Ubuntu16.04下安装OpenCV3.2.0

时间:2023-02-15 12:07:17

1.安装官方给的opencv依赖包

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

2.下载opencv3.2.0

这里需要下载opencv和opencv_contrib(后者会在cmake配置的时候用到),这是因为opencv3以后SIFT和SURF之类的属性被移到了contrib中,。

$ wget https://github.com/opencv/opencv/archive/3.2.0.zip # 从github上直接下载或者clone也可
$ wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip

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

cd opencv-3.2.0
mkdir build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
 
 

4.安装Python-opencv:

sudo apt-get install python-opencv

sudo apt-get install python-numpy 

5. 测试是否安装成功

python

>>import cv2

>>>cv2.__version_

3.2.0