`//--------------------------------------------------------------------
QString Qfilename = QFileDialog::getOpenFileName(this, tr(“选择图像”), “”, tr(“Images (*.png *.bmp *.jpg)”));
if (Qfilename.isEmpty() && isFirst_open)
{
QMessageBox::information(this, tr(“打开图像失败”), tr(“没有选择图片”));
return;
}
else if (Qfilename.isEmpty() && !isFirst_open)
{
}
else
{
filename = Qfilename.toStdString();
srcImg = imread(filename);
cvtColor(srcImg, grayImg, COLOR_BGR2GRAY);
isFirst_open = 0;
}
Mat temp;
QImage Qtemp;
cvtColor(srcImg, temp, COLOR_BGR2RGB);//BGR convert to RGB
Qtemp = QImage((const unsigned char*)(temp.data), temp.cols, temp.rows, temp.step, QImage::Format_RGB888);
ui.label->setPixmap(QPixmap::fromImage(Qtemp));
ui.label->resize(Qtemp.size());
ui.label->show();`![打开图片](https://img-blog.csdnimg.cn/20190818212337600.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1FMQkZB,size_16,color_FFFFFF,t_70)