When working on computer vision projects or image processing applications, it's common to use the OpenCV library. However, when it comes to creating graphical user interfaces (GUI) in Qt, you may need to convert images obtained through OpenCV into a format compatible with Qt. This tutorial explains how to convert OpenCV image to Qt 6 image.
The following code snippet demonstrates a straightforward process of converting an image obtained through the OpenCV library into a format compatible with Qt. Inside the main
function, an image is read using OpenCV. Subsequently, a Qt image is created using the constructor, taking parameters such as the image data, width, height, step (line width in bytes), and the image format. Finally, the resulting Qt image is saved.
#include <QImage>
#include <opencv2/opencv.hpp>
int main()
{
cv::Mat img = cv::imread("test.jpg");
QImage qimg(img.data, img.cols, img.rows, img.step, QImage::Format_BGR888);
qimg.save("test2.jpg");
return 0;
}
This code example demonstrates how developers can smoothly combine OpenCV images with Qt applications, showcasing the seamless interoperability of these powerful libraries.
Leave a Comment
Cancel reply