目录

linux-安装python-opencv

目录

linux 安装python-opencv

三种方法:

  1. pip 安装 :
pip install opencv-python ,最新版为opencv3

安装后

>>> import cv2
>>> print cv2.__version__

参考:

  1. 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问题 ,可以参考如下链接升级

可能导致奔溃,所以请小心安装。

  1. 源码装

装完后,

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.

  1. Move the module to any folder in Python Path
    Python path can be found out by entering

    import

    sys;print

    sys.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,

    su mv /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/site-packages

But you will have to do this every time you install OpenCV.

  1. 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.

    export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages

Thus OpenCV installation is finished. Open a terminal and try

import

cv2 .

参考:

  1. python的测试

linux下查看opencv版本

  1. 覆盖原有opencv

如果服务器已经安装了opencv,但是通过 anaconda的conda安装,也安装了python的opencv接口,会发现其中也包含了opencv的lib,include文件,如下:

https://img-blog.csdn.net/20171028004459583?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGlhbWVudGluZ3Rhbw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center

这时可以使用这个版本的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

可以使用原方法测试。