#include "opencv2/opencv.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include inline QImage cvMat2QImage(const cv::Mat &inMat) { if(inMat.step / inMat.cols == 4) return QImage(inMat.data, inMat.cols, inMat.rows, static_cast(inMat.step), QImage::Format_ARGB32); else return QImage(inMat.data, inMat.cols, inMat.rows, static_cast(inMat.step), QImage::Format_RGB888); } void onDrawPreview(cv::Mat frame) { QLabel* mDisplayLabel = new QLabel(); mDisplayLabel->resize(400, 700); if(!frame.data) return; cv::imwrite("cvMat.jpg", frame); QImage img =cvMat2QImage (frame); img.save("qimage.jpg", "JPG"); QPixmap pixmap=QPixmap::fromImage(img); pixmap.save("pixmap.jpg", "JPG"); QPixmap fitpixmap = pixmap; if(pixmap.width() > 375) fitpixmap = pixmap.scaled(375, 375 *pixmap.height()/pixmap.width(), Qt::KeepAspectRatio, Qt::SmoothTransformation); fitpixmap.save("fitpixmap.jpg", "JPG"); mDisplayLabel->setPixmap(fitpixmap); }