Convert Mat to QPixmap

user2354422 picture user2354422 · May 7, 2013 · Viewed 10.9k times · Source

How can we convert directly cv::Mat to QPixmap without going through filename loading?

I have made some research about it but no hints!

As a first step, what I have tried is that I save the image, and then load it. But it's not what I want to have.

Answer

mehfoos yacoob picture mehfoos yacoob · Aug 16, 2013

Jehan is right.

For people referring to this thread in the future: First convert image from BGR(used by OpenCV) to RGB.

Then:

QPixmap::fromImage(QImage((unsigned char*) mat.data, mat.cols, mat.rows, QImage::Format_RGB888));