如果在Ubuntu下,Python环境是Anaconda的时候编译OpenCV,直接cmake会有问题,cmake会找到系统自带的Python2的python lib而不是Anaconda里面的,两个python版本号不一样就不会编译python接口。
解决方法是在cmake命令里指定python2环境的参数。
先在opencv的源码目录里新建一个build文件夹,然后进入这个文件夹,执行下面的命令:
cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D PYTHON_INCLUDE_DIR=/PATH_TO_ANACONDA/anaconda2/include/python2.7 \ -D PYTHON_INCLUDE_DIR2=/PATH_TO_ANACONDA/anaconda2/include/python2.7 \ -D PYTHON_LIBRARY=/PATH_TO_ANACONDA/anaconda2/lib/libpython2.7.so \ -D PYTHON2_LIBRARY=/PATH_TO_ANACONDA/anaconda2/lib/libpython2.7.so \ -D PYTHON_PACKAGES_PATH=/PATH_TO_ANACONDA/anaconda2/lib/python2.7/site-packages/ \ -D BUILD_EXAMPLES=ON \ -D BUILD_NEW_PYTHON_SUPPORT=ON \ -D BUILD_opencv_python3=OFF \ -D BUILD_opencv_python2=ON \ -D BUILD_TIFF=ON ..
之后执行
make sudo make install来自http://stackoverflow.com/questions/29381705/install-opencv-3-0-0-beta-on-ubuntu-14-04-with-anaconda-python-2-7