pro 文件引用 openvc:
CONFIG += link_pkgconfig
PKGCONFIG+= opencv
//图形边缘检测
void MainWindow::on_bianyuan_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,tr("Open Image"),".",tr("Image File(*.png *.jpg *.jpeg *.bmp)"));
if (fileName.isEmpty())
{
return;
}
ui->stackedWidget->setCurrentIndex(1);
Mat srcImage = imread(fileName.toLatin1().data());//读取图片数据
// cvtColor(srcImage, srcImage, COLOR_BGR2RGB);//bgr图像格式转换rgb
Mat dstImage, edge, grayImage;
dstImage.create(srcImage.size(), srcImage.type());
cvtColor(srcImage, grayImage, COLOR_BGR2GRAY);
blur(grayImage, edge, Size(3, 3));
Canny(edge, edge, 3, 9, 3);
imshow("fsdvf",edge);
cvtColor(edge, edge, COLOR_GRAY2RGB);
QImage tmp = QImage((const unsigned char*)(edge.data),edge.cols,edge.rows,QImage::Format_RGB888);
QGraphicsScene *scene = new QGraphicsScene;//图像显示
scene->addPixmap(QPixmap::fromImage(tmp));
ui->graphicsView->setScene(scene);
ui->graphicsView->show();
}