导入后的效果:
1.下载文件: https://opencv.org/releases/
2.解压文件
3.创建qt测试项目
1.新建项目:
2.测试新建项目
4.导入opencv库
-
库文件路径
-
修改文件
5.测试结果
1.测试代码
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPaintEvent>
#include <QPainter>
#include "opencv2/opencv.hpp"
#include "QVBoxLayout"
#include "QLabel"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QVBoxLayout*layout=new QVBoxLayout();
QLabel *label=new QLabel();
std::string str=cv::format("hello world,qt and opencv%d.%d",cv::getVersionMajor(),cv::getVersionMajor());
label->setText(QString(str.c_str()));
layout->addWidget(label);
ui->centralwidget->setLayout(layout);
cv::Mat src=cv::imread("E:/C++/opencv/opencv/sources/samples/data/lena.jpg");
cv::imshow("图像显示",src);
cv::waitKey(0);
cv::destroyAllWindows();
}
MainWindow::~MainWindow()
{
delete ui;
}
2.结果: