0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AIの前処理をOpenCVで行うときによく使う処理

Last updated at Posted at 2022-09-28

・BGRからRGBへチャンネルの順序変更
・画素値正規化
・点順次(NHWC)から面順次(NCHW)へ形式変更

cv::Mat img_rgb(img.size(), img.type());
int from_to[] = { 0,2, 1,1, 2,0 };  // BGR->RGB
cv::mixChannels(&img, 1, &img_rgb, 1, from_to, 3);

cv::Mat img_rgb_float;
img_rgb.convertTo(img_rgb_float, CV_32F);
img_rgb_float *= 1. / 255;

// 点順次から面順次
cv::Mat tmp[3];
cv::split(img_rgb_float, tmp);
cv::Mat dst;
cv::vconcat(tmp, 3, dst);
0
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?