配置环境变量
path F:\opencv-4.0.0\opencv\build\x64\vc14\bin
打开Qtcreater创建mainwindow窗口项目
点击项目配置文件,添加库->外部库
.pro文件
INCLUDEPATH += $$PWD/../../opencv-4.0.0/opencv/build/include
DEPENDPATH += $$PWD/../../opencv-4.0.0/opencv/build/include
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#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("F:/Image_database/lena.jpeg");
cv::imshow("图像显示",src);
cv::waitKey(0);
cv::destroyAllWindows();
}
MainWindow::~MainWindow()
{
delete ui;
}
release下