从github中down下OPenCV + OpenCV_Contrib库,可以从https://github.com/opencv上下载(注意版本对应)
cd ~/<my_working_directory>
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
将opencv_contrib目录移到opencv目录下
添加opencv所需要的依赖库:
Required Packages
GCC 4.4.x or later
CMake 2.8.7 or higher
Git
GTK+2.x or higher, including headers (libgtk2.0-dev)
pkg-config
Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev(一些开发用视频解码)
[optional] libtbb2 libtbb-dev
[optional] libdc1394 2.x
[optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
[optional] CUDA Toolkit 6.5 or higher
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 libjaster-dev
出现:errorE: unable to locate libjasper-dev时,执行
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
进入opencv文件夹,打开terminal
mkdir build
cd build
cmake编译(后面的两个点不能丢)
cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..
make -j8
python
import cv2
如果出现"No module named cv2",请执行
sudo apt-get install python-opencv