opencv安装手册之opencv3.4.2

1.

1.依賴

sudo apt-get install build-essential 
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 libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev 
sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包 
sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能 
sudo apt-get install ffmpeg

出现问题:无法定位软件包libjasper-dev

解决:https://blog.csdn.net/weixin_41053564/article/details/81254410
2.在解压好的文件夹中打开终端,创建文件夹并打开

mkdir release
cd release

3.配置编译opencv (无NVIDIA CUDA版本)

cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/home/fanzong/anaconda2/envs/tensorflow \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \ -D PYTHON_EXCUTABLE=/home/fanzong/anaconda2/envs/tensorflow/bin/python \ -D WITH_TBB=ON \ -D WITH_V4L=ON \ -D WITH_QT=ON \ # 1 -D WITH_GTK=ON \ -D WITH_OPENGL=ON \ -D BUILD_EXAMPLES=ON .. # cmake命令的使用方式:cmake [<some optional parameters>] <path to the OpenCV source directory>。如果命令报错的话可以试着把-D后面的空格去掉在执行一次。

配置编译opencv (NVIDIA CUDA版本)

cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules \ -D PYTHON_EXCUTABLE=/usr/bin/python \ -D WITH_CUDA=ON \  -D WITH_CUBLAS=ON \ -D DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" \ -D CUDA_ARCH_BIN="5.3" \ ](https://developer.nvidia.com/cuda-gpus) -D CUDA_ARCH_PTX="" \ -D CUDA_FAST_MATH=ON \  -D WITH_TBB=ON \ -D WITH_V4L=ON \ -D WITH_QT=ON \     # 如果qt未安装可以删去此行;若因为未正确安装qt导致的Qt5Gui报错,
  • 简化配置编译
sudo cmake -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 ON ..

编译完成之后安装

sudo make -j16
sudo make install

3 小程序测试

找到 opencv-3.4.3/samples/cpp/example_cmake 目录下,官方已经给出了一个cmake的example,我们可以拿来测试下。按顺序执行:
cmake .
make
./opencv_example

即可看到打开了摄像头,在左上角有一个hello opencv ,即表示配置成功。

2.others

卸载opencv
1)cd opencv/build
2)sudo make uninstall
3)删除build文件夹
4)sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*

编译opencv、opencv_contrib

  1. sudo apt-get install --assume-yes build-essential cmake git
  2. sudo apt-get install --assume-yes pkg-config unzip ffmpeg qtbase5-dev python-dev python3-dev python-numpy python3-numpy
  3. sudo apt-get install --assume-yes libopencv-dev libgtk-3-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev
  4. sudo apt-get install --assume-yes libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
  5. sudo apt-get install --assume-yes libv4l-dev libtbb-dev LIBFAAC-DEV libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev
  6. sudo apt-get install --assume-yes libvorbis-dev libxvidcore-dev v4l-utils vtk6
  7. sudo apt-get install --assume-yes liblapacke-dev libopenblas-dev libgdal-dev checkinstall
    1)解压后按之前位置放好
    2)mkdir build
    3)cd build
    4)#cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/liujinglin/BD/opencv_contrib-3.4.5/modules/ -D #FORCE_VTK=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_CUBLAS=ON -D CUDA_NVCC_FLAGS="-D_FORCE_INLINES" -D WITH_GDAL=ON -D WITH_XINE=ON -D WITH_CUDA=ON -D BUILD_EXAMPLES=ON …

(注意修改opencv_contrib路径)

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/liujinglin/BD/opencv_contrib-3.4.5/modules/ -D FORCE_VTK=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_CUBLAS=ON -D WITH_GDAL=ON -D WITH_XINE=ON -D BUILD_EXAMPLES=ON …

5)如果在cmake过程中出现卡在Download的问题,参考https://blog.csdn.net/CSDN330/article/details/86747867
6) make -j16
7) sudo make install
8) sudo /bin/bash -c ‘echo “/usr/local/lib” > /etc/ld.so.conf.d/opencv.conf’
9) sudo ldconfig
10) sudo apt-get update

你可能感兴趣的:(opencv安装手册之opencv3.4.2)