Tuesday, May 24, 2016

Installing OpenCV and Anaconda on Win

Doing research on Windows can be quite painful, yet it's never you too late to switch to Linux (OS Ubuntu). Here are (big) PROs for doing that:
- installation on Ubuntu is more straightforward (e.g. see OpenCV), especially when it comes to adding various plug-ins and libraries in environment
- on Windows some of the open source research libraries are not very well maintained, and some of them are not even compatible (e.g., at the moment of writing this post, Google Tensorflow)

(Feel free to post CONs for Ubuntu in comments bellow).

However, if you persists with Windows (this is probably why you are here), here are some tips how to install OpenCV and Anaconda. There are many sites around, mainly suggesting to download OpenCV binaries and compile it with CMake and VS, however, if you will be only working with Python, you can omit those steps. I took the following information from the StackOverflow and extended it with Step 1. This had worked for me (Windows 7, 64-bit, Anaconda 3, v4.0.6, Python 3.5.1.)

1. Run cmd (simply type cmd in search once you press the Start button) and position yourself to Anaconda3 folder. Mine is installed in C:\Anaconda3

2. Then, type following:

conda install -c https://conda.binstar.org/menpo opencv

or, if you want new opencv 3:

conda install -c https://conda.binstar.org/menpo opencv3

3. Once you are done, enter the Python console (type Python in cmd), and then type following:

import cv2
print(cv2.__version__)

The command should show if the OpenCV is installed and what version you have.
This is what I get:



Voila! Now you can have fun with amazing OpenCV in Python.


NOTE: If you are using Python IDE PyCharm you might meet additional difficulties. Here are the tips how to fix  the error "No module named cv2" (PyCharm version Community Edition 2016.1.3.).

1. If PyCharm was open during the OpenCV installation reset it. 
2. If the error is still there, you should then set correct Python environment in PyCharm.
Go to File->Default Settings->Project Interpreter and add version of Python you are using.


This should be it. If  "import cv2" line is still underlined with red color, please use some OpenCV example in PyCharm and check whether it works. This could be an internal glitch in PyCharm environment.

1 comment: