简体   繁体   English

在Windows 7上为Python 2.7安装OpenCV

[英]Installing OpenCV on Windows 7 for Python 2.7

am trying desperately to get OpenCV to work on Windows 7. I download and installed it, and it didn't work, I got 我正在拼命尝试使OpenCV在Windows 7上运行。我下载并安装了它,但它不起作用,我得到了

ImportError: No module named opencv 

when I tried to run one of the samples. 当我尝试运行其中一个示例时。 I google my problem and got only random solutions that don't work. 我用谷歌搜索我的问题,只得到了行不通的解决方案。 Can anybody guide me in installing it, or know where i can get a clear installation guide design for a programming noob. 任何人都可以指导我安装它,或者知道在哪里可以为编程新手获得清晰的安装指南设计。

As of OpenCV 2.2.0, the package name for the Python bindings is "cv".The old bindings named "opencv" are not maintained any longer. 从OpenCV 2.2.0开始,Python绑定的软件包名称为“ cv”。名为“ opencv”的旧绑定不再保留。 You might have to adjust your code. 您可能需要调整代码。 See http://opencv.willowgarage.com/wiki/PythonInterface . 参见http://opencv.willowgarage.com/wiki/PythonInterface

The official OpenCV installer does not install the Python bindings into your Python directory. 官方的OpenCV安装程序不会将Python绑定安装到您的Python目录中。 There should be a Python2.7 directory inside your OpenCV 2.2.0 installation directory. OpenCV 2.2.0安装目录中应该有一个Python2.7目录。 Copy the whole Lib folder from OpenCV\\Python2.7\\ to C:\\Python27\\ and make sure your OpenCV\\bin directory is in the Windows DLL search path. 将整个Lib文件夹从OpenCV \\ Python2.7 \\复制到C:\\ Python27 \\,并确保您的OpenCV \\ bin目录位于Windows DLL搜索路径中。

Alternatively use the opencv-python installers at http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv . 或者使用位于http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv的opencv-python安装程序。

I have posted a very simple method to install OpenCV 2.4 for Python in Windows here : Install OpenCV in Windows for Python 我在这里发布了一种非常简单的方法来在Windows中为Python安装OpenCV 2.4: 在Windows中为Python安装OpenCV

It is just as simple as copy and paste. 它就像复制和粘贴一样简单。 Hope it will be useful for future viewers. 希望对将来的观众有用。

  1. Download Python, Numpy, OpenCV from their official sites. 从其官方站点下载Python,Numpy,OpenCV。

  2. Extract OpenCV (will be extracted to a folder opencv) 解压缩OpenCV(将解压缩到opencv文件夹中)

  3. Copy ..\\opencv\\build\\python\\x86\\2.7\\cv2.pyd 复制.. \\ opencv \\ build \\ python \\ x86 \\ 2.7 \\ cv2.pyd

  4. Paste it in C:\\Python27\\Lib\\site-packages 将其粘贴到C:\\ Python27 \\ Lib \\ site-packages中

  5. Open Python IDLE or terminal, and type 打开Python IDLE或终端,然后键入

     >>> import cv2 

If no errors shown, it is OK. 如果未显示任何错误,则确定。

UPDATE (Thanks to dana for this info): 更新(感谢dana提供此信息):

If you are using the VideoCapture feature, you must copy opencv_ffmpeg.dll into your path as well. 如果使用的是VideoCapture功能,则还必须将opencv_ffmpeg.dll复制到路径中。 See: https://stackoverflow.com/a/11703998/1134940 参见: https : //stackoverflow.com/a/11703998/1134940

I have posted an entry to setup OpenCV for Python in Windows: http://luugiathuy.com/2011/02/setup-opencv-for-python/ 我发布了一个条目,用于在Windows中为Python设置OpenCV: http : //luugiathuy.com/2011/02/setup-opencv-for-python/

Hope it helps. 希望能帮助到你。

Actually you can use x64 and Python 2.7. 实际上,您可以使用x64和Python 2.7。 This is just not delivered in the standard OpenCV installer. 这只是标准的OpenCV安装程序中未提供。 If you build the libraries from the source ( http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html ) or you use the opencv-python from cgohlke's comment, it works just fine. 如果您从源代码构建库( http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html ),或者从cgohlke的注释中使用opencv-python,它就可以正常工作。

download the opencv 2.2 version from https://sourceforge.net/projects/opencvlibrary/files/opencv-win/ https://sourceforge.net/projects/opencvlibrary/files/opencv-win/下载opencv 2.2版本

install package. 安装软件包。

then Copy cv2.pyd to C:/Python27/lib/site-packeges. 然后将cv2.pyd复制到C:/ Python27 / lib / site-packeges。

and it should work: 它应该工作:

import cv2

open command prompt and run the following commands (assuming python 2.7): 打开命令提示符并运行以下命令(假设python 2.7):

cd c:\Python27\scripts\
pip install opencv-python

the above works for me for python 2.7 on windows 10 64 bit 以上适用于Windows 10 64位上的python 2.7

One thing that needs to be mentioned. 需要提及的一件事。 You have to use the x86 version of Python 2.7. 您必须使用x86版本的Python 2.7。 OpenCV doesn't support Python x64. OpenCV不支持Python x64。 I banged my head on this for a bit until I figured that out. 我把头撞了一下,直到我弄清楚了。

That said, follow the steps in Abid Rahman K's answer. 也就是说,请按照Abid Rahman K的回答中的步骤进行操作。 And as Antimony said, you'll need to do a 'from cv2 import cv' 正如锑所说,您需要执行“从cv2导入cv”

在Windows 7上为Python 2.7安装OpenCV

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM