QT中通过读文件的方式无法创建Mat对象!!

 代码如下:

之前死活就是没有Mat,后来发现是因为路径里面有中文!!!!

切记切记!!!改了两天居然因为这种错误,我服了!!!

//打开图片
void Test01::on_open_clicked() {

	QString filename;
	filename = QFileDialog::getOpenFileName(this,
		tr("选择图像"),
		"",
		tr("Images (*.png *.bmp *.jpg *.tif *.GIF )"));
	if (filename.isEmpty())
	{
		return;
	}
	else
	{
		QImage* img2 = new QImage;

		if (!(img2->load(filename))) //加载图像
		{
			QMessageBox::information(this,
				tr("打开图像失败"),
				tr("打开图像失败!"));
			delete img2;
			return;
		}
		//QImage i = *img2;
		//image = QImage2cvMat(i);
		string str = filename.toStdString();  // 将filename转变为string类型;
		image = imread(str);//读取图片
		QString qstr = QString::fromStdString(str);
		if (image.empty()) {
			ui.label_4->setText("open error");
			ui.label_3->setText(qstr);
		}
		*img2 = img2->scaled(img2->width() / 3, img2->height() / 3, Qt::KeepAspectRatio);
		QGraphicsScene *scene = new QGraphicsScene;
		scene->addPixmap(QPixmap::fromImage(*img2));
		ui.graphicsView->setScene(scene);
		ui.graphicsView->resize(img2->width() + 10, img2->height() + 10);
		ui.graphicsView->show();
		//Mat image2=image.clone();
		//QImage img = MatToQImage(image2);//转化为QImage

//		QGraphicsScene *scene = new QGraphicsScene;
//		scene->addPixmap(QPixmap::fromImage(img));
		//label = new QLabel();
		//label->setPixmap(QPixmap::fromImage(img));
		//label->resize(QSize(img.width(), img.height()));
		//ui.scrollArea->setWidget(label);
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值