How to convert an OpenCV cv::Mat to QImage

Michal Kottman’s answer is valid and give expected result for some images but it’ll fail on some cases. Here is a solution i found to that problem.

QImage imgIn= QImage((uchar*) img.data, img.cols, img.rows, img.step, QImage::Format_RGB888);

Difference is adding img.step part. qt won’t complain without it but some images won’t show properly without it. Hope this will help.

Leave a Comment