安装以下包:
# yum install gcc cmake git python-devel gtk2-devel numpy tbb-devel libjpeg-turbo-devel libtiff-devel libpng-devel libjasper-devel cmake-gui
下载opencv源码包,解压到主目录,将自动创建子目录opencv-2.4.11。
进入该目录中,编译OpenCV:
$ cd ~/opencv-2.4.11
$ cmake CMakeLists.txt
$ make -j7 # 同时运行7个任务
在进行到快30%的时候,出现以下错误:
In file included from /home/xxf/opencv-2.4.11/modules/highgui/src/cap_ffmpeg.cpp:45:
/home/xxf/opencv-2.4.11/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘void CvVideoWriter_FFMPEG::close()’:
/home/xxf/opencv-2.4.11/modules/highgui/src/cap_ffmpeg_impl.hpp:1468: error: ‘avformat_free_context’ was not declared in this scope
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o] Error 1
解决办法:使用yum 卸载 ffmpeg、ffmpeg-devel,然后下载ffmpeg源码,编译安装:
$ cd ffmpeg
$ ./configure --enable-shared
此时可能提示yasm/nasm太旧,安装之:
$ sudo yum install nasm yasm
再继续:
$ make
$ sudo make install
进入opencv目录
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_EXAMPLES=ON -DBUILD_NEW_PYTHON_SUPPORT=ON -DINSTALL_PYTHON_EXAMPLES=ON -DPYTHON_EXECUTABLE=/usr/local/python-2.7/bin/python -DPYTHON_INCLUDE_DIR=/usr/local/python-2.7/include -DPYTHON_LIBRARY=/usr/local/python-2.7/lib/libpython2.7.so -DPYTHON_NUMPY_INCLUDE_DIR=/usr/local/python-2.7/lib/python2.7/site-packages/numpy/core/include/ -DPYTHON_PACKAGES_PATH=/usr/local/python-2.7/lib/python2.7/site-packages/ -DCUDA_GENERATION=Auto ..