首页 > 解决方案 > 将 Mat 图像转换为 QImage 后图像质量失真

问题描述

void Qtexample::on_pushButton_clicked()
{ 
    QString img_path = QFileDialog::getOpenFileName(this, "Select your image", QDir::homePath());

    img = imread(img_path.toStdString().c_str());
    Size size(200, 200);
    cv::resize(img, img,size);
    cvtColor(img, img, COLOR_RGB2BGR); //convering the image to RGB for QImage to handle well 

    QImage Qimg((uchar*)img.data, img.cols, img.rows, img.step, QImage::Format_RGB888);  // converting Mat image to QImage
    ui.label->setPixmap(QPixmap::fromImage(Qimg,Qt::AutoColor).scaled(ui.label->width(), ui.label->height()));  // displaying the image inside the QLabel with the help of QPixmap
    // imshow("image", img);  // show image
}

该代码通过将 Mat 图像转换为 QImage 来工作,但生成的图像有点失真,我需要帮助。

标签: c++qtopencv

解决方案


推荐阅读