将Mat图像收敛到QImage后图像质量失真

时间:2019-05-17 08:19:40

标签: c++ qt opencv

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起作用,但是生成的Image有点失真,我需要帮助。

0 个答案:

没有答案