其他分享
首页 > 其他分享> > QLabel显示opencv Mat图片

QLabel显示opencv Mat图片

作者:互联网

QLabel显示opencv  Mat图片

 

void showImgOnLabel(QLabel* labelParam, cv::Mat imgParam, int showType)
{
    cv::Mat rgb;
    QImage img;

    if (showType==1)
    {
        cv::resize(imgParam, imgParam, cv::Size(640, 480));
    }
    else if (showType==2)
    {
        cv::resize(imgParam, imgParam, cv::Size(160, 120));
    }

    if (imgParam.channels() == 3)
    {
        cv::cvtColor(imgParam, rgb, CV_BGR2RGB);
        img = QImage((const uchar*)(rgb.data), rgb.cols, rgb.rows, rgb.cols*rgb.channels(), QImage::Format_RGB888);
    }
    else
    {
        img = QImage((const uchar*)(imgParam.data), imgParam.cols, imgParam.rows, imgParam.cols*imgParam.channels(), QImage::Format_Indexed8);
    }
    labelParam->clear();
    labelParam->setPixmap(QPixmap::fromImage(img));
    //this->main_ui.labelWin1->resize(this->main_ui.labelWin1->pixmap()->size());
    //labelParam->resize(QSize(640, 480));
    labelParam->show();
}

 

 

#################################

标签:Mat,cols,labelParam,opencv,rgb,imgParam,cv,QImage,QLabel
来源: https://www.cnblogs.com/herd/p/15464144.html