- 在VMWare中配置安装Ubuntu16.04。没有什么特别的地方,正常安装即可。
- 安装最新版qt,此时5.10。按照普通QT教程安装(需要勾选gcc),无须sudo,此时不用管OpenCV。地址:http://download.qt.io/archive/qt/,或官网:https://www.qt.io/download(可能需要注册)
- 源码安装OpenCV,依次执行以下命令即可。按照普通OpenCV教程安装,此时不用管如何配置QT。
sudo apt-get install cmake build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev --fix-missing git clone https://github.com/opencv/opencv.gitgit clone https://github.com/opencv/opencv_contrib.gitcd opencv_directorymkdir buildcd buildcmake –D CMAKE_BUILD_TYPE=Release –D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..make -j4sudo make installsudo vim /etc/ld.so.conf.d/opencv.conf # 在文件中添加一行 /usr/local/lib sudo ldconfig -vpkg-config --modversion opencv # 查看版本号
- 在新建的Qt工程文件(如test.pro)后面,添加INCLUDEPATH和LIBS 配置。
INCLUDEPATH += /usr/local/include \ /usr/local/include/opencv \ /usr/local/include/opencv2 \LIBS += -L /usr/local/lib/libopencv_*
最后,测试案例(显示图片1):
#include "mainwindow.h"#include#include #include using namespace cv;int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; w.show(); Mat image; image = imread("../im1.jpg"); cvNamedWindow("show image", CV_WINDOW_AUTOSIZE); imshow("show image", image ); //waitKey(0); //cvDestroyWindow("show image"); return a.exec();}