opecv qt 显示图片

1.声明

public slots:

void showImage();

2.使用

connect(ui.openfile, SIGNAL(clicked()), SLOT(showImage())); //点击事件

3.实现

void QtGuiApp01::showImage()

{

QString filename = QFileDialog::getOpenFileName(this,

tr("open image"),

".",

tr("Image file(*.png *.jpg *.bmp)"));

cv::Mat image = imread(filename.toLocal8Bit().data());

QImage img = QImage((const unsigned char*)(image.data), image.cols, image.rows, QImage::Format_RGB888);

//设定图像大小自适应label窗口的大小

img = img.scaled(ui.labelImg->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

ui.labelImg->setPixmap(QPixmap::fromImage(img));

}


opecv qt 显示图片_第1张图片

你可能感兴趣的:(opecv qt 显示图片)