May 2020
Intermediate to advanced
530 pages
17h 8m
English
By default, when we load an image with the OpenCV library, it loads the image in the BGR format and with char as the underlying data type. So, we need to convert it to the RGB format, like this:
cv::cvtColor(img, img, cv::COLOR_BGR2RGB);
Then, we can convert the underlying data type to the float type, like this:
img.convertTo(img, CV_32FC3, 1/255.0);
Next, to deinterleave channels, we need to split them with the cv::split() function, like this:
cv::Mat bgr[3];cv::split(img, bgr);
Then, we can place channels back to the cv::Mat object in the order we need with the cv::vconcat() function, which concatenates matrices vertically, as follows:
cv::Mat ordered_channels;cv::vconcat(bgr[2], bgr[1], ordered_channels);cv::vconcat(ordered_channels, ...
Read now
Unlock full access