How to Convert OpenCV cv::Mat to QImage
Problem:
How can I convert an OpenCV cv::Mat type to QImage in C ? Converting IPlimage to QImage using existing code is not sufficient.
Solution:
Michal Kottman's response is generally accurate, but it may fail for certain images. To address this issue, you can use the following solution:
QImage imgIn = QImage((uchar*) img.data, img.cols, img.rows, img.step, QImage::Format_RGB888);
Explanation:
The key difference in this approach is the addition of img.step, which specifies the byte width of each row in the cv::Mat. Without this parameter, Qt may not always render images correctly.
By including img.step, you can ensure compatibility with a broader range of images and prevent rendering issues.
The above is the detailed content of How to Convert a cv::Mat to a QImage in C ?. For more information, please follow other related articles on the PHP Chinese website!