I'm working with opencv
and I have to integrate it to a Qt
Gui, but I have some issue for showing the image in Qt
...
Here is the code that I'm using
#include <QApplication>
#include <QtGui>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
QImage const Mat2QImage(const cv::Mat& src){
return QImage((unsigned char*)src.data, src.cols, src.rows, src.step, QImage::Format_RGB888);
}
int main(int argc, char **argv){
QApplication app(argc, argv);
cv::Mat src = cv::imread("lena.jpg");
QLabel aLabel;
QImage img = Mat2QImage(src);
aLabel.resize(src.rows, src.cols);
aLabel.setPixmap(QPixmap::fromImage(img));
aLabel.show();
return app.exec();
}
And Here is the result :
Note that if I change the format to QImage::FormatRGB32
I will get an empty window, I've also tried all the formats and that wasn't what I'm expacting ...
Any idea about how to solve the issue ?
Thanks !