目的
这是用用QT+opencv实现的一个完整的展示图片的例子,包括了项目的配置文件,完整的代码,以用做初次学习opencv用。
代码
工程文件:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = openCv1
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
INCLUDEPATH += E:\openSource\opencv\opencv\build\include
INCLUDEPATH += E:\openSource\opencv\opencv\build\include\opencv
INCLUDEPATH += E:\openSource\opencv\opencv\build\include\opencv2
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
#win32: LIBS += -L$$PWD/../../../openSource/opencv/opencv/build/x64/vc14/lib/ -lopencv_world310
LIBS += -LE:\openSource\opencv\opencv\build\x64\vc14\lib\ -lopencv_world455
#LIBS += -LE:\openSource\opencv\opencv\build\x64\vc14\lib\ -lopencv_world455d
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
代码文件:
//#include "mainwindow.h"
#pragma execution_character_set("utf-8")
#include <QApplication>
#include <QDebug>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//MainWindow w;
//w.show();
QString str = QString::fromUtf8("E:\\temp\\lushanjing3.jpg");
qDebug()<<str;
Mat img = imread(str.toStdString());//图片路径
//处理前
imshow("img",img);//显示图片
Mat resimg;
//高斯模糊
cv::GaussianBlur(img,resimg,Size(5,5),0);
imshow("resimg",resimg);//显示图片
waitKey(2000);//等待按键
return a.exec();