I spent some time getting Python and OpenCV setup on Windows 7 tonight. I was looking for a solution that would get me started prototyping image processing algorithms quickly and this solution works quite nicely. Here’s an easy way to set things up:
1. It’s easiest to download the scientific computation python bundle that is offered athttp://www.enthought.com/. Look for the link for “EPD Free” (Enthought Python Distribution.) EPD Free comes with Python 2.7, SciPy, NumPy, Matplotlib and a handful of other useful numerical tools, all in a convenient Windows installer.
2. Download OpenCV for Windows from http://opencv.willowgarage.com/. Unpack into a directory somewhere and make special note of the ‘opencv/build/python/2.7′ directory. Additionally, check out the ‘samples/python2′ directory for examples to run.
3. You could use the built in python IDE, IDLE, but the Eclipse plugin PyDev is much more useful. You can find installation instructions over at http://pydev.org/. In short, download the Eclipse IDE and install PyDev from the internal software update menu. When you are setting up a Python workspace just make sure to include the ‘opencv/build/python/2.7′ directory so that you can make use of OpenCV within Eclipse.
Test things out with the following code. It accesses a webcam and renders video until you press a key. It can be run from within Eclipse, just create a new Python module and run.
1
2
3
4
5
6
7
8
9
10
|
import cv2 cap = cv2.VideoCapture( 1 ) cv2.namedWindow( "input" ) key = - 1 while ( key < 0 ): success, img = cap.read() cv2.imshow( "imshow" , img) key = cv2.waitKey( 1 ) cv2.destroyAllWindows() |
OpenCV 2.4 for Python documentation is available at http://opencv.willowgarage.com/, however you’ll probably find it equally as useful to look at the sample scripts in the ‘samples/python2′ directory.