标签:div oss -o 取图 src opencv proc nim str
1. 通过lable方式打开图片。
代码如下:
1 void MainWindow::on_pushButton_clicked()
2 {
3 Mat srcImage,gray_image,srcImage1;
4 QString Fileadd = QFileDialog::getOpenFileName(this,"get file");
5 if(Fileadd.isEmpty())
6 {
7 QMessageBox::information(this,"警告","没有选择文件");
8 return ;
9 }
10 srcImage = imread(Fileadd.toLatin1().data()); //读取图片
11 cvtColor(srcImage,srcImage1,COLOR_BGR2RGB); // 图像格式转换
12 QImage disImage = QImage((const unsigned char*)(srcImage1.data),srcImage1.cols,srcImage1.rows,QImage::Format_RGB888);
13 ui->label->setPixmap(QPixmap::fromImage(disImage.scaled(ui->label->size(), Qt::KeepAspectRatio)));
14 }
效果图如下:
2.Graphics View 方式打开图片
代码如下:
1 void MainWindow::on_pushButton_2_clicked()
2 {
3 QString fileName = QFileDialog::getOpenFileName(this,tr("Open Image"),".",tr("Image File(*.png *.jpg *.jpeg *.bmp)"));
4 if (fileName.isEmpty())
5 {
6 return;
7 }
8 Mat srcImage = imread(fileName.toLatin1().data());//读取图片数据
9 cvtColor(srcImage, srcImage, COLOR_BGR2RGB);//图像格式转换
10 QImage disImage = QImage((const unsigned char*)(srcImage.data),srcImage.cols,srcImage.rows,QImage::Format_RGB888);
11
12 QGraphicsScene *scene = new QGraphicsScene;//图像显示
13 scene->addPixmap(QPixmap::fromImage(disImage));
14 ui->graphicsView->setScene(scene);
15 ui->graphicsView->show();
16 }
效果图如下:
Qt OpenCV 在界面显示图片 通过Lable方式 和GraphicsView 方式
标签:div oss -o 取图 src opencv proc nim str
原文地址:https://www.cnblogs.com/ybqjymy/p/12356801.html