Can I pip install opencv2 for python?

2019-01-22 16:56发布

I know that I can pip install opencv-python which installs opencv3, but is there a separate command or name for opencv2.4.9? If not, how can I specify which version to install?

8条回答
家丑人穷心不美
2楼-- · 2019-01-22 17:16

Easy and simple

  • Prerequisites
    • pip install matplotlib
    • pip install numpy
  • Final step
    • pip install opencv-python

Specific version * Final step * opencv-python==2.4.9

  • OR

  • cv2 vs. "opencv3"**

To get a potential misunderstanding out of the way: The python OpenCV module is named and imported via import cv2 in all versions > 2.0, including > 3.0. If you want to work with cv2, installing OpenCV versions > 3 is fine - unless you're looking for specific compatibility with older versions or are a fan of the 2.4.x versions. The switch from 2.4.x to 3.x was in 2015 and in terms of features, speed and transparency, it makes much sense to use the newer versions. You can read here and here about major differences. 2.4.x versions are still supported though, current release is 2.4.13.5.

Installing a specific version, e.g. OpenCV 2.4.9

That said: If you want to install a specific version that neither pip install opencv-python==2.4.X, sudo apt-get install opencv nor conda install opencv=2.4.x provide (as explained by other answers here), you can always install from sources. In the sourceforge repository you can find all major versions for each operating system. Although for unxeperienced users this might be scary, it is well explained in some tutorials. E.g. here for 2.4.9 on Ubuntu 14.04. Or here is the official Linux install doc for the latest release 2.4.13.5.

In essence, the install process boils down to:

  1. install dependencies, refer to docs (e.g. here) for required packages

  2. get sources from OpenCVs sourceforge

    e.g. wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip

  3. unzip sources and prepare build by creating build directory and running cmake

    mkdir build
    cd build
    cmake (... your build options ...)
    
  4. build in the created build directory with:

    make
    sudo make install
    
查看更多
手持菜刀,她持情操
3楼-- · 2019-01-22 17:26

You can also do it using Anaconda:

conda install -c https://conda.binstar.org/menpo opencv=2.4.9
查看更多
不美不萌又怎样
4楼-- · 2019-01-22 17:34

Via pip you can specify the package version to install using the following:

pip install opencv-python==2.4.9

However, that package does not seem to be available on pypi.

A little trick for checking available versions:

pip install opencv-python==

Which returns:

Could not find a version that satisfies the requirement opencv-python== (from versions: 3.1.0.0, 3.1.0.1, 3.1.0.2, 3.1 .0.3, 3.1.0.5, 3.2.0.6, 3.2.0.7) No matching distribution found for opencv-python==

查看更多
我想做一个坏孩纸
5楼-- · 2019-01-22 17:34

you can try this

pip install opencv==2.4.9
查看更多
一纸荒年 Trace。
6楼-- · 2019-01-22 17:36

There's another easy way, you can type in terminal

sudo apt-get install python-opencv

Install OpenCV-Python in Ubuntu

After installing it, you can use opencv version 2.4 in both c++ and python.

But I recommend you should use opencv 3.2.0 and opencv-contrib, it gives more features

Hope this can help!

查看更多
爷的心禁止访问
7楼-- · 2019-01-22 17:37

If you are using windows os, you can download your desired opencv unofficial windows binary from here, and type something like pip install opencv_python-2.4.13.2-cp27-cp27m-win_amd64.whl in the directory of binary file.

查看更多
登录 后发表回答