1、首先Qt5配置Opencv(我已经配置成功)有时间发出来
2、Opencv的基本Mat操作
(1)加Opencv的头文件

  • #include<opencv2/opencv.hpp>
    #include <opencv2/highgui/highgui_c.h> 
    using namespace cv;
    

    (2)Opencv图像基本处理

     Mat srcimage = imread("F:/1.png");   //读取原始图片
     //Mat转QImage 颜色
     cvtColor(srcimage,srcimage,CV_BGR2RGB);
    

3、Mat转QImage( //Mat转QImage 像素 oldlabel放置原图)

   QImage disimage = QImage(srcimage.data,srcimage.cols,srcimage.rows,srcimage.cols*srcimage.channels(),QImage::Format_RGB888);
    disimage = disimage.scaled(ui->oldlabel->width(),ui->oldlabel->height());

4、用Qt的lable展示图片

   ui->oldlabel->setPixmap(QPixmap::fromImage(disimage));

5、源代码

   //读取原始图片
    Mat srcimage = imread("F:/1.png");
    //Mat转QImage 颜色
    cvtColor(srcimage,srcimage,CV_BGR2RGB);
    //Mat转QImage 像素   oldlabel放置原图
    QImage disimage = QImage(srcimage.data,srcimage.cols,srcimage.rows,srcimage.cols*srcimage.channels(),QImage::Format_RGB888);
    disimage = disimage.scaled(ui->oldlabel->width(),ui->oldlabel->height());
    ui->oldlabel->setPixmap(QPixmap::fromImage(disimage));
05-01 12:49