Skip to content
scottclowe edited this page Feb 8, 2015 · 17 revisions

Installation:

Instructions pillaged from here.

http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation

http://docs.opencv.org/trunk/doc/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.html#install-opencv-python-in-fedora

https://stackoverflow.com/questions/20953273/install-opencv-for-python-3-3

Since we are installing to a venv, this was the most useful: https://medium.com/@manuganji/installation-of-opencv-numpy-scipy-inside-a-virtualenv-bf4d82220313

https://stackoverflow.com/questions/11184847/running-opencv-from-a-python-virtualenv

Install Instructions

You will need >1GB free space to install OpenCV. When the process is finished, it will take up about 300MB.

First, you need to install cmake if you don't have it already. Do this without being in the virtual environment.

On Debian:

sudo apt-get install cmake

On CentOS:

yum install cmake

Setup:

wget https://github.com/Itseez/opencv/archive/3.0.0-beta.tar.gz
tar -vzxf 3.0.0-beta.tar.gz
rm 3.0.0-beta.tar.gz
cd opencv-3.0.0-beta
mkdir build
cd build

Now set a variable for the path your venv is at, and source it. Make sure it is an absolute path, not a relative path.

$VIRTUAL_ENV = '/path/to/your/neukrill-venv'
source $VIRTUAL_ENV/bin/activate

For a Python 3.4 venv, do the following:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV/ -D PYTHON_EXECUTABLE=$VIRTUAL_ENV/bin/python3.4 -D PYTHON_PACKAGES_PATH=$VIRTUAL_ENV/lib/python3.4/site-packages -D BUILD_NEW_PYTHON_SUPPORT=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..

Alternatively, to install on a Python 2.7 venv:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV/local/ -D PYTHON_EXECUTABLE=$VIRTUAL_ENV/bin/python -D PYTHON_PACKAGES_PATH=$VIRTUAL_ENV/lib/python2.7/site-packages -D BUILD_NEW_PYTHON_SUPPORT=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON ..

After doing cmake for either Python 2.7 or 3.4, scroll up and check that the directories are correct and point at the venv in the Python 2/3 section, and that Python (for build) correctly points to the venv as well.

Finish:

make -j <numCores>
make install

Note: The make step may take about half an hour when using only a single core.

Now let's try it out and check it is working:

python
import cv2

This should import without error.

If this is successful, you can now remove the copy of OpenCV you downloaded.

cd ../../
rm -r opencv-3.0.0-beta

Documentation

Here is the documentation for using OpenCV with Python.

http://docs.opencv.org/trunk/doc/py_tutorials/py_tutorials.html

https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_tutorials.html

About Bag of Visual Words

Here are some general details about the bag of words method.

http://www.cs.princeton.edu/courses/archive/fall09/cos429/papers/csurka-eccv-04.pdf

https://gilscvblog.wordpress.com/2013/08/23/bag-of-words-models-for-visual-categorization/

Bag of Words OpenCV Python Tutorials

https://github.com/Itseez/opencv/blob/master/samples/python2/find_obj.py

http://nbviewer.ipython.org/gist/kislayabhi/abb68be1b0be7148e7b7

Clone this wiki locally