2020-11-11

1.安装 opencv 所需依赖包

如果后面还要遗漏的,出错再补上

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264v4l-utils unzip

2.下载 opencv3.2.0

这里需要下载 opencv 和 opencv_contrib (后者会在 cmake 配置的时候用到), 这是因为 opencv3以后 SIFT 和 SURF 之类的属性被移到了 contrib 中,执行下面两条指令下载 OpenCV3.2.0

$ wget https://github.com/opencv/opencv/archive/3.2.0.zip
$ wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip

(3.2.0.zip就是opencv-3.2.0.zip)
(3.2.0.zip.1就是opencv_contrib.zip)

3.解压下载的两个文件

$ unzip opencv-3.2.0.zip -d ~/opencv
$ unzip opencv_contrib-3.2.0.zip -d ~/opencv

4.创建并进入 build 目录,执行 cmake 生成 makefile 文件

$ cd ~/opencv/opencv-3.2.0
$ mkdir build
$ cd build/
$ sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH= ..

注意cmake的参数不要出错

问题一:

下载包的时候链接超时

 
  1. CMake Error at 3rdparty/ippicv/downloader.cmake:77 (message):

  2. ICV: Failed to download ICV package: ippicv_linux_20151201.tgz.

  3. Status=28;"Timeout was reached"

  4.  

手动下载 ippicv_linux_20151201.tgz(https://raw.githubusercontent.com/Itseez/opencv_3rdparty/81a676001ca8075ada498583e4166079e5744668/ippicv/ippicv_linux_20151201.tgz)到opencv-3.2.0/3rdparty/ippicv/downloads/目录下再cmake

$ sudo cp ~/software/opencv/ippicv_linux_20151201.tgz ~/opencv/opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/

问题二:

 
  1. -- No package 'gtk+-3.0' found

  2.  

$ sudo apt-get install libgtk-3-dev

问题三:

 
  1. -- No package 'gstreamer-base-1.0' found

  2.  
  3. -- No package 'gstreamer-video-1.0' found

  4.  
  5. -- No package 'gstreamer-app-1.0' found

  6.  
  7. -- No package 'gstreamer-riff-1.0' found

  8.  
  9. -- No package 'gstreamer-pbutils-1.0' found

  10.  
  11.  

sudo apt-get -y install libgstreamer-plugins-base1.0-dev
sudo apt-get -y install libgstreamer1.0-dev

问题四:

 
  1. -- No package 'libavresample' found

  2.  
  3. -- No package 'libgphoto2' found

  4.  
  5.  

$ sudo apt-get -y install libavresample-dev
$ sudo apt-get -y install libgphoto2-dev

问题五:

 
  1. -- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off

  2. -- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off

  3. -- Could NOT find Atlas (missing: Atlas_CBLAS_INCLUDE_DIR Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY Atlas_LAPACK_LIBRARY)

  4. -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)

  5. -- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)

  6. -- Could NOT find Matlab (missing: MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIRS MATLAB_ROOT_DIR MATLAB_LIBRARIES MATLAB_LIBRARY_DIRS MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN)

  7. -- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file

  8.  

$ sudo apt-get install libopenblas-dev

问题六:

 
  1. -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)

  2.  

$ sudo apt-get install doxygen

问题七:

-- Could NOT find JNI (missing:  JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH) 

a.下载jdk-8u151-linux-x64.tar.gz到download目录
http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk8-downloads-2133151-zhs.html

b.安装jdk

$ cd download/
$ sudo mkdir /usr/local/java
$ sudo tar zxvf jdk-8u151-linux-x64.tar.gz -C /usr/local/java
$ sudo ln -s /usr/local/java/jdk1.8.0_151/ /usr/local/java/latest

c. 添加环境变量:

$ sudo vim /etc/profile

加入如下内容:

 
  1. >export JAVA_HOME=/usr/local/java/latest

  2. export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

  3. export PATH=$PATH:$JAVA_HOME/bin

执行

$ source /etc/profile

进行更新。

没有报错的情况下,cmake成功后会出现

 
  1. -- Configuring done

  2. -- Generating done

  3. -- Build files have been written to: /home/fc/opencv/opencv-

  4. 3.2.0/build

5. make

cmake成功,之后可以在 build 文件下执行编译指令,待编译成功后即可执行安装指令。

$ sudo make -j4

出错:
/opencv/opencv-3.2.0/build/opencv_lapack.h:2:45: fatal error: LAPACKE_H_PATH-NOTFOUND/lapacke.h: 没有那个文件或目录
解决方法:

$ sudo apt-get install liblapacke-dev checkinstall

make时间有点长,差不多两个小时了。

6.install

$ sudo make install

7.安装 python 接口依赖

$sudo apt-get install python-opencv
sudo apt-get install python-numpy

8.测试 Python 的 OpenCV3.2.0 模块

 
  1. $ python

  2. Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19)

  3. [GCC 7.2.0] on linux2

  4. Type "help", "copyright", "credits" or "license" for more information.

  5. >>> import cv2

  6. Traceback (most recent call last):

  7. File "", line 1, in

  8. ImportError: No module named cv2

  9. >>>

  10.  

问题:No module named cv2
原因在于 python2.7 找不到 cv2.so 文件

$ sudo cp ~/opencv/opencv-3.2.0/build/lib/cv2.so ~/anaconda2/lib/python2.7/site-packages/

再测试:

 
  1. $ python

  2. Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19)

  3. [GCC 7.2.0] on linux2

  4. Type "help", "copyright", "credits" or "license" for more information.

  5. >>> import cv2

  6. >>> cv2.__version__

  7. '3.2.0'

  8. >>>

  9.  

能显示opencv的版本说明安装成功

你可能感兴趣的:(2020-11-11)