ugu11 / camera_tutorial

Apache License 2.0
36 stars 11 forks source link

Convert uint32_t array to openCV Mat c++ #7

Open AnhPC03 opened 3 years ago

AnhPC03 commented 3 years ago

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);
ugu11 commented 3 years ago

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

AngelUrq commented 2 years ago

Did you solve it?

tomtitherington commented 2 years ago

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;