三种方法:
1. pip 安装 :
pip install opencv-python ,最新版为opencv3
安装后
>>> import cv2
>>> print cv2.__version__
参考:http://www.cnblogs.com/lclblack/p/6377710.html
2. anaconda的conda安装 ,可以指定opencv版本,如opencv2
conda install -c https://conda.binstar.org/menpo opencv=2.4.9
但是容易出问题,比如 /lib64/libc.so.6: version `GLIBC_2.14' not found问题 ,可以参考如下链接升级
https://my.oschina.net/zhangxu0512/blog/262275
http://www.linuxidc.com/Linux/2017-01/139833.htm
http://www.cnblogs.com/MrLJC/p/4245925.html
可能导致奔溃,所以请小心安装。
3. 源码装
https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.html#install-opencv-python-in-fedora
装完后,
Installation is over. All files are installed in /usr/local/ folder. But to use it, your Python should be able to find OpenCV module. You have two options for that.
-
Move the module to any folder in Python Path : Python path can be found out by entering import sys;printsys.path in Python terminal. It will print out many locations. Move /usr/local/lib/python2.7/site-packages/cv2.so to any of this folder. For example,
But you will have to do this every time you install OpenCV.
-
Add ``/usr/local/lib/python2.7/site-packages`` to the PYTHON_PATH: It is to be done only once. Just open ~/.bashrc and add following line to it, then log out and come back.
Thus OpenCV installation is finished. Open a terminal and try import cv2.
参考:http://www.cnblogs.com/freeweb/p/5794447.html
4. python的测试
http://blog.csdn.net/this_is_chris/article/details/51498673
http://blog.csdn.net/u012150360/article/details/70156195
https://jingyan.baidu.com/article/14bd256e466474bb6d2612db.html
linux下查看opencv版本
http://blog.csdn.net/lzh2912/article/details/52494891
5. 覆盖原有opencv
如果服务器已经安装了opencv,但是通过anaconda的conda安装,也安装了python的opencv接口,会发现其中也包含了opencv的lib,include文件,如下:
这时可以使用这个版本的opencv覆盖原装的,方法是修改bashrc,如下:
## 动态库搜索路径
export LD_LIBRARY_PATH=/home/caiyong.wang/anaconda2/lib:$LD_LIBRARY_PATH
##(静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径export LIBRARY_PATH=/home/caiyong.wang/anaconda2/lib:$LIBRARY_PATH ##c程序头文件搜索路径export C_INCLUDE_PATH=/home/caiyong.wang/anaconda2/include:$C_INCLUDE_PATH
##c++程序头文件搜索路径export CPLUS_INCLUDE_PATH=/home/caiyong.wang/anaconda2/include:$CPLUS_INCLUDE_PATH
##pkg-config 路径export PKG_CONFIG_PATH=/home/caiyong.wang/anaconda2/lib/pkgconfig/:$PKG_CONFIG_PATH
可以使用原方法测试。