OpenCV3 is the latest major edition of the most comprehensive computer vision library, OpenCV. OpenCV has continued to expand its Python bindings and has finally started to support Python 3. Below I’ll show a fairly painless way of setting up this environment.
Anaconda makes creating virtual environments for Python and installing non-python packages like numpy and OpenCV incredibly easy, so we’re going to use that. Go to the following link and make sure to select I want Python 3.4.
If you’re on Windows this will download an executable that will install Anaconda. If you’re on Linux it will download a shell script that will install Anaconda. I assume OSX is similar to Linux.
Once we have Anaconda installed we’re going to want to create a new virtual environment in which to run all of our computer vision tasks. Virtual environments let us install packages without cluttering up our python ecosystem. In Windows make sure to open up the Anaconda command prompt. In Linux just a normal terminal. We’re going to install the following packages: numpy, scipy, scikit-learn, matplotlib. I don’t know if we’ll need all of them but they’re all great packages so what the heck. Only numpy is needed for sure. Run the following commands. (If you’re on Windows source activate becomes activate.)
conda create -n opencv numpy scipy scikit-learn matplotlib python=3 source activate opencv conda install -c https://conda.binstar.org/menpo opencv3
Let’s explain what these commands mean. conda create makes a new virtual environment -n gives that environment a name. The names after that are the packages that get installed upon creating the environment and the keyword argument python=3 makes sure that we use python 3 (3.4 in my case). You might be wondering why we did not install OpenCV along with the other packages. That’s because OpenCV as of this writing is not included in Anaconda’s regular list of packages. We need to use binstar to get that.
Before that, we’ll activate our new virtual environment. This is similar to sourcing your bash profile in linux. In Windows source activate becomes activate. You should now see the name of your environment (opencv) prepended to the command prompt. Now we’re going to install OpenCV3. To do this we had to find where opencv3 is located. Go to binstar.org and search for opencv3. I found it under user menpo for linux_x64 and windows_x64. OSX has a separate package. We want to take that URL and modify it so that it works with the conda install. https://conda.binstar.org/user package_name The command as formatted above should install opencv3.
To check whether this works or not start up a python prompt. Run import cv2 (!!!IMPORTANT it’s still cv2 not cv3). To check the version print(cv2.__version__) If everything worked out you should have 3.0.0 🙂