依赖包
- GCC ≥4.4.x
- CMake ≥2.8.7
- Cit
- GTK ≥2.x,including headers (libgtk2.0-dev)
- pkg-config
- Python ≥2.6,Numpy ≥1.5,with developer packages(python-dev,python-numpy)
- ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
- [可选] libtbb2 libtbb-dev
- [可选] libdc1394 2.x
- [可选] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
- [可选] CUDA Toolkit ≥6.5
通过以下命令来安装上述依赖包:1
2
3sudo 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
下载OpenCV源码
1.下载页下载最新稳定版
2.从Git Repository获取:1
2git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
编译源码
1.创建临时文件夹,用于存放Makefiles等1
2
3cd ~/opencv
mkdir build
cd build
2.配置并编译1
cmake [<some optional parameters>] <path to the OpenCV source directory>
例如:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18cmake -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 \ # 使用CUDA
-D WITH_CUBLAS=ON \
-D DCUDA_NVCC_FLAGS="-D_FORCE_INLINES" \
-D CUDA_ARCH_BIN="9.2" \ # 使用的CUDA所对应的版本
-D CUDA_ARCH_PTX="" \
-D CUDA_FAST_MATH=ON \ # 计算速度更快但是相对不精确
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=ON \ # 如果qt未安装可以删去此行;若因为未正确安装qt导致的Qt5Gui报错,可将build内文件全部删除后重新cmake,具体可以参考[这里](http://stackoverflow.com/questions/17420739/opencv-2-4-5-and-qt5-error-s)
-D WITH_GTK=ON \
-D WITH_OPENGL=ON \
-D BUILD_EXAMPLES=ON ~/opencv