{"id":469,"date":"2014-01-23T12:20:37","date_gmt":"2014-01-23T17:20:37","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=469"},"modified":"2014-01-23T12:20:37","modified_gmt":"2014-01-23T17:20:37","slug":"setting-up-python-and-opencv-for-windows-7","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2014\/01\/23\/setting-up-python-and-opencv-for-windows-7\/","title":{"rendered":"Setting up Python and OpenCV for Windows 7"},"content":{"rendered":"<div>\n<div>\n<div>\n<div>\n<div>by\u00a0<a title=\"Posts by BizzaroDavid\" href=\"http:\/\/antianti.org\/?author=1\" rel=\"author\">BIZZARODAVID<\/a>\u00a0on\u00a0AUGUST 29, 2012\u00a0\u00b7\u00a0<a href=\"http:\/\/antianti.org\/?p=440#comments\">LEAVE A COMMENT<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div>\n<div>\n<p>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\u2019s an easy way to set things up:<\/p>\n<p>1. It\u2019s easiest to download the scientific computation python bundle that is offered at<a href=\"http:\/\/www.enthought.com\/\">http:\/\/www.enthought.com\/<\/a>. Look for the link for \u201cEPD Free\u201d (Enthought Python Distribution.) EPD Free comes with Python 2.7, SciPy, NumPy, Matplotlib and a handful of other useful numerical tools, all in a\u00a0convenient Windows installer.<\/p>\n<p>2. Download OpenCV for Windows from\u00a0<a href=\"http:\/\/opencv.willowgarage.com\/wiki\/\">http:\/\/opencv.willowgarage.com\/<\/a>. Unpack into a directory somewhere and make special note of the \u2018opencv\/build\/python\/2.7\u2032 directory. \u00a0Additionally, check out the \u2018samples\/python2\u2032 directory for examples to run.<\/p>\n<p>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\u00a0<a href=\"http:\/\/pydev.org\/\">http:\/\/pydev.org\/<\/a>. 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 \u2018opencv\/build\/python\/2.7\u2032 directory so that you can make use of OpenCV within Eclipse.<\/p>\n<p>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.<\/p>\n<div>\n<div id=\"highlighter_813675\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>1<\/div>\n<div>2<\/div>\n<div>3<\/div>\n<div>4<\/div>\n<div>5<\/div>\n<div>6<\/div>\n<div>7<\/div>\n<div>8<\/div>\n<div>9<\/div>\n<div>10<\/div>\n<\/td>\n<td>\n<div>\n<div><code>import<\/code> <code>cv2<\/code><\/div>\n<div><\/div>\n<div><code>cap <\/code><code>=<\/code> <code>cv2.VideoCapture(<\/code><code>1<\/code><code>)<\/code><\/div>\n<div><code>cv2.namedWindow(<\/code><code>\"input\"<\/code><code>)<\/code><\/div>\n<div><code>key <\/code><code>=<\/code> <code>-<\/code><code>1<\/code><\/div>\n<div><code>while<\/code><code>( key &lt; <\/code><code>0<\/code> <code>):<\/code><\/div>\n<div><code>\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code>success, img <\/code><code>=<\/code> <code>cap.read()<\/code><\/div>\n<div><code>\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code>cv2.imshow(<\/code><code>\"imshow\"<\/code><code>, img)<\/code><\/div>\n<div><code>\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code>key <\/code><code>=<\/code> <code>cv2.waitKey(<\/code><code>1<\/code><code>)<\/code><\/div>\n<div><code>cv2.destroyAllWindows()<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>OpenCV 2.4 \u00a0for Python documentation is available at\u00a0<a href=\"http:\/\/opencv.willowgarage.com\/wiki\/\">http:\/\/opencv.willowgarage.com\/<\/a>, however you\u2019ll probably find it equally as useful to look at the sample scripts in the \u2018samples\/python2\u2032 directory.<\/p>\n<div><\/div>\n<\/div>\n<div><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>by\u00a0BIZZARODAVID\u00a0on\u00a0AUGUST 29, 2012\u00a0\u00b7\u00a0LEAVE A COMMENT I spent some time getting Python and OpenCV setup on Windows 7 tonight. I was looking for a solution that&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-469","post","type-post","status-publish","format-standard","hentry","category-computer-vision"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=469"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/469\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=469"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}