Ubuntu16.04 + OpenCV源码 + Qt5.10 安装、配置

Ubuntu18 OpenCV-3.2.0有问题参考:https://blog.csdn.net/hiram_zhang/article/details/103467737

 

  1. 在VMWare中配置安装Ubuntu16.04。没有什么特别的地方,正常安装即可。
  2. 安装最新版qt,此时5.10。按照普通QT教程安装(需要勾选gcc),无须sudo,此时不用管OpenCV。
    地址:http://download.qt.io/archive/qt/,或官网:https://www.qt.io/download(可能需要注册)
  3. 源码安装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.git
    git clone https://github.com/opencv/opencv_contrib.git
    cd opencv_directory
    mkdir build
    cd build
    cmake –D CMAKE_BUILD_TYPE=Release –D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
    make -j4
    sudo make install
    sudo vim /etc/ld.so.conf.d/opencv.conf # 在文件中添加一行 /usr/local/lib
    sudo ldconfig -v pkg-config --modversion opencv # 查看版本号
  4. 在新建的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 <QApplication>
#include <QDebug>

#include <opencv2/opencv.hpp>

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();
}

 

 

posted @ 2018-01-28 14:51  xbit  阅读(424)  评论(0编辑  收藏  举报