camera_tutorial
camera_tutorial copied to clipboard
Convert uint32_t array to openCV Mat c++
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);
Hi. I'm sorry, but I actually have no idea. I have never worked with openCV in c++ before.
Did you solve it?
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;