如何为 Python 3.4 安装 OpenCV?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28355069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:08:43  来源:igfitidea点击:

How do I install OpenCV for Python 3.4?

pythonopencv

提问by user3317287

I use Python 3.4 through Anaconda distribution. They don't seem to have Python 3.4 bindings for OpenCV. I tried to use Cmake from the source, but to no avail. Could anybody please help me to install OpenCV for Python 3.4.x?

我通过 Anaconda 发行版使用 Python 3.4。他们似乎没有 OpenCV 的 Python 3.4 绑定。我尝试从源代码中使用 Cmake,但无济于事。有人可以帮我为 Python 3.4.x 安装 OpenCV 吗?

回答by IronManMark20

There are many tutorials and questions (on SO) about this.

有很多关于此的教程和问题(关于 SO)。

Thisseems to answer your question. Edit: Reproduced below:

似乎回答了你的问题。编辑:转载如下:

1)  Download OpenCV from http://opencv.org/downloads.html and extract

2)From the extracted folder, copy the file from the extracted directory:   
opencv/build/python/2.7/(either x86 or x64, depending on your Anaconda 
version)/cv2.pyd to your Anaconda site-packages directory, e.g., 
C:\Anaconda\Lib\site-packages

3)To get ffmpeg within opencv to work, you'll have to add the directory 
that ffmpeg is located in to the path (e.g., opencv/sources/3rdparty
/ffmpeg). Then you'll have to find the dll in that folder (e.g., 
opencv_ffmpeg_64.dll) and copy or rename it to a filename that includes 
the opencv version you are installing, (e.g., opencv_ffmpeg249_64) for 
2.4.9.

{End Reproduction}

{结束复制}

EDIT2: OpenCV doesn't support Python 3.x except for OpenCV version 3.0 (still experimental, in beta). Download the 3.0 version from the download site and try that.(Thanks to this question).

EDIT2:OpenCV 不支持 Python 3.x,除了 OpenCV 3.0 版(仍处于试验阶段,处于测试阶段)。从下载站点下载 3.0 版本并尝试。(感谢这个问题)。

A SO question with a possible tip, if the previous doesn't work.

如果以前的方法不起作用,则带有可能提示的 SO 问题。

And finally, I will point you to a read the docs tutorialon how to install it.

最后,我将指导您阅读有关如何安装它的文档教程

Good luck!

祝你好运!

回答by JSalys

conda install -c menpo opencv3

Does the trick. However you have to have anaconda installed.

有诀窍。但是,您必须安装 anaconda。

回答by susan097

This is Quite Simple way:

这是很简单的方法:

I recommend to use through anaconda.

我建议通过 anaconda 使用。

Create the environment in anaconda(recommended one): conda create -n deeplearning

在anaconda中创建环境(推荐一个): conda create -n deeplearning

Then, activate by: activate deeplearning

然后,通过以下方式激活: activate deeplearning

Now, Install opencv for python3.x of Anaconda3 as:

现在,为 Anaconda3 的 python3.x 安装 opencv 为:

  • conda install -c https://conda.binstar.org/menpo opencv3

    This will simply install opencv3 and other related libraries as: spicy, numpy, scikit-learn and matplotlib in that environment.

  • conda install -c https://conda.binstar.org/menpo opencv3

    这将简单地在该环境中安装 opencv3 和其他相关库,如:spicy、numpy、scikit-learn 和 matplotlib。

Check whether Opencv installed or not as:

检查 Opencv 是否安装为:

>>> import cv2
>>> cv2.__version__
'3.1.0'