camera_tutorial icon indicating copy to clipboard operation
camera_tutorial copied to clipboard

Convert uint32_t array to openCV Mat c++

Open AnhPC03 opened this issue 5 years ago • 3 comments

Hello. How can i convert your uint32_t *image to openCV Mat in c++? I had converted but not successed Here is my code in c++

cv::Mat intMat_RGBA = cv::Mat(cv::Size(oriImgWidth, oriImgHeight), CV_8UC4, image);
std::vector<cv::Mat> RGBA_channels;
cv::split(intMat_RGBA, RGBA_channels);

// remove the alpha channel:
RGBA_channels.pop_back();
std::reverse(RGBA_channels.begin(), RGBA_channels.end());

// and merge back to image:
cv::Mat intMat_BGR;
cv::merge(RGBA_channels, intMat_BGR);

AnhPC03 avatar Jan 08 '21 10:01 AnhPC03

Hi. I'm sorry, but I actually have no idea. I have never worked with openCV in c++ before.

ugu11 avatar Jan 09 '21 15:01 ugu11

Did you solve it?

AngelUrq avatar Sep 01 '21 16:09 AngelUrq

OpenCV requires your image array to be in BGRA (instead of the RGBA format used here). Change the following line in the convertImage function: image[getRotatedImageByteIndex(y, x, height)] = (hexFF << 24) | (b << 16) | (g << 8) | r; to image[getRotatedImageByteIndex(y, x, height)] = (hexFF << 24) | (r << 16) | (g << 8) | b;

tomtitherington avatar Sep 19 '21 12:09 tomtitherington