P.C.
P.C.

Reputation: 649

How can I convert a QImage of format RGB32 to OpenCV::mat?

I have a QImage of format RGB32 When I do this:

cv::Mat depthMat(depthImg.height(),depthImg.width(),CV_8UC3,(uchar*)depthImg.bits(),depthImg.bytesPerLine());

I get the image of the left. I am actually supposed to get the image on the right. enter image description here

Upvotes: 1

Views: 3556

Answers (1)

P.C.
P.C.

Reputation: 649

Okay! I figured it out! RGB32 has 8 bits of R, 8 bits of G, 8 bits of B and 8 bits of Alpha. It's essentially RGBA. So, we can use this:

cv::Mat depthMat(depthImg.height(),depthImg.width(),CV_8UC4,(uchar*)depthImg.bits(),depthImg.bytesPerLine());

enter image description here

Upvotes: 5

Related Questions