Installing OpenCV on Windows with Python 2.7
OpenCV is released under a BSD license and hence it’s free for both academic and commercial use. It has C++, C, Python 2.7 (above) and Java interfaces and supports Windows, Linux, Mac OS, iOS, and Android. OpenCV was designed for computational efficiency and with a strong focus on real-time applications. Written in optimized C/C++, the library can take advantage of multi-core processing. Enabled with OpenCL, it can take advantage of the hardware acceleration of the underlying heterogeneous compute platform. Adopted all around the world, OpenCV has more than 47 thousand people of the user community and estimated the number of downloads exceeding 9 million. Usage ranges from interactive art to mines inspection, stitching maps on the web or through advanced robotics.
Installing OpenCV from prebuilt binaries
- Below Python packages are to be downloaded and installed to their default locations.
- Install all packages into their default locations. Python will be installed to
- After installation, open Python IDLE. Enter import numpy and make sure Numpy is working fine.
- Download latest OpenCV release from sourceforge site and double-click to extract it.
- Goto opencv/build/python/2.7 folder.
- Copy cv2.pyd to C:/Python27/lib/site-packages.
- Open Python IDLE and type following codes in Python terminal.
>>> import cv2
>>> print cv2.__version__
If the results are printed out without any errors, congratulations !!! You have installed OpenCV-Python successfully.
Possible Errors while Installation of OpenCV
There are following two most common type of errors while installation:
ERROR 1: ImportError: DLL load failed: %1 is not a valid Win32 application
This error will show something like this:
>>> import cv2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: DLL load failed: %1 is not a valid Win32 application.
SOLUTION: Try copying the 32-bit version of cv2.pyd in step 6 of installation process mentioned above. The reason is that your installed Python 2.7 version is 32-bit but you might be trying to use 64-bit OpenCV cv2.pyd file. So there is a compatibility issue.
ERROR 2:OpenCV 2.4.8: module compiled against API version 9
This error looks something like the following:
import cv2 RuntimeError: module compiled against API version 9 but this version of numpy is 7 Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> import cv2 ImportError: numpy.core.multiarray failed to import
SOLUTION: The version of numpy in the tutorial is at OpenCV website is version 7, but now the team is using version 9 (but numpy team name it 1.8 publicly). So, simply update your numpy installation. If you have used my “numpy 1.8” link above, then there should not be any problem.
For convenience, download the latest version, check here
Please feel free to leave a comment or question below.