Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing OpenCV on Windows 7 for Python 2.7

Tags:

python

opencv

am trying desperately to get OpenCV to work on Windows 7. I download and installed it, and it didn't work, I got

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.

like image 934
cubearth Avatar asked Jan 17 '11 01:01

cubearth


People also ask

How can I import cv2 in Python 3 7?

Start the Python shell by typing python3 and then hit enter. You will be inside the Python shell where you can execute your Python code. Import the cv2 package which is the name of the OpenCV module. Type “import cv2” and hit enter.


6 Answers

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. You might have to adjust your code. See http://opencv.willowgarage.com/wiki/PythonInterface.

The official OpenCV installer does not install the Python bindings into your Python directory. There should be a Python2.7 directory inside your OpenCV 2.2.0 installation directory. 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.

Alternatively use the opencv-python installers at http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv.

like image 142
cgohlke Avatar answered Oct 19 '22 11:10

cgohlke


I have posted a very simple method to install OpenCV 2.4 for Python in Windows here : Install OpenCV in Windows for Python

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.

  2. Extract OpenCV (will be extracted to a folder opencv)

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

  4. Paste it in C:\Python27\Lib\site-packages

  5. Open Python IDLE or terminal, and type

    >>> import cv2
    

If no errors shown, it is OK.

UPDATE (Thanks to dana for this info):

If you are using the VideoCapture feature, you must copy opencv_ffmpeg.dll into your path as well. See: https://stackoverflow.com/a/11703998/1134940

like image 41
Abid Rahman K Avatar answered Oct 19 '22 11:10

Abid Rahman K


I have posted an entry to setup OpenCV for Python in Windows: http://luugiathuy.com/2011/02/setup-opencv-for-python/

Hope it helps.

like image 26
Thuy Avatar answered Oct 19 '22 10:10

Thuy


Actually you can use x64 and Python 2.7. This is just not delivered in the standard OpenCV installer. 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.

like image 43
yanlend Avatar answered Oct 19 '22 10:10

yanlend


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

install package.

then Copy cv2.pyd to C:/Python27/lib/site-packeges.

and it should work:

import cv2
like image 43
NINO Cikoo Avatar answered Oct 19 '22 11:10

NINO Cikoo


open command prompt and run the following commands (assuming 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

like image 31
Ohad Cohen Avatar answered Oct 19 '22 10:10

Ohad Cohen