Ubuntu16.04.3安装OpenCV并配置QT环境进行开发

首先下载OpenCV的压缩包,我这里使用的是opencv-2.4.13.3.zip,将其使用unzip 命令解压:

unzip opencv-2.4.13.3.zip

在当期目录下生成opencv*目录,使用如下命令完成相关操作:

cd opencv-2.4.13.3
mkdir release
cd release

下载opencv编译开发所使用的工具及其依赖包:

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

sudo apt-get install qt4-dev-tools qt4-designer qt4-doc qt4-qtconfig qt4-demos qt4-qmake libqt4-sql-mysql

使用cmake指明编译输出的路径并指明需要编译链接的模块:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

在这里可能会报错,报错的原因基本上都是一些需要安装的包没有安装,根据报错信息对需要安装的包进行安装即可。
执行make命令:

make -j4
sudo make install

-j后面跟的数字代表采用几核编译,不清楚的可以直接make命令。

后面就是一些opencv的相关配置:

sudo gedit /etc/ld.so.conf.d/opencv.conf
#末尾加入/usr/local/opencv/lib,保存退出
sudo vim /usr/local/opencv/lib/ld.so.conf
#末尾加入/usr/local/opencv/lib,保存退出
sudo ldconfig    #使配置生效

sudo gedit /etc/bash.bashrc 

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opencv/lib/pkgconfig

export PKG_CONFIG_PATH

sudo source /etc/bash.bashrc  #使配置生效

到这里,关于opencv安装配置基本上就说完了,如果是使用qtcreator开发,我们可以使用qmake工具,在项目的配置文件中添加INCLUDEPATH和LIBS即可,以opencv-2.4.13.3为例:
添加的内容如下:

INCLUDEPATH += /usr/local/opencv/include \
    /usr/local/opencv/include/opencv \
    /usr/local/opencv/include/opencv2


LIBS += /usr/local/opencv/lib/libopencv_calib3d.so \
    /usr/local/opencv/lib/libopencv_contrib.so \
    /usr/local/opencv/lib/libopencv_core.so \
    /usr/local/opencv/lib/libopencv_features2d.so \
    /usr/local/opencv/lib/libopencv_flann.so \
    /usr/local/opencv/lib/libopencv_gpu.so \
    /usr/local/opencv/lib/libopencv_highgui.so \
    /usr/local/opencv/lib/libopencv_imgproc.so \
    /usr/local/opencv/lib/libopencv_legacy.so \
    /usr/local/opencv/lib/libopencv_ml.so \
    /usr/local/opencv/lib/libopencv_nonfree.so \
    /usr/local/opencv/lib/libopencv_objdetect.so \
    /usr/local/opencv/lib/libopencv_ocl.so \
    /usr/local/opencv/lib/libopencv_photo.so \
    /usr/local/opencv/lib/libopencv_stitching.so \
    /usr/local/opencv/lib/libopencv_superres.so \
    /usr/local/opencv/lib/libopencv_video.so \
    /usr/local/opencv/lib/libopencv_videostab.so

我把所有的so库都添加进去了,熟悉opencv的可以根据自己的使用情况,引入自己所需要的库即可。

你可能感兴趣的:(ubuntu,图像处理)