OpenCV

Locate OpenCV:

1
2
3
pkg-config --modversion opencv //version
pkg-config --cflags opencv //include file path
pkg-config --libs opencv //library path

Uninstall OpenCV:

  1. go to the compile package and make uninstall
  2. if cannot find the compile package, sudo find / -name "*opencv*" -exec rm -i {} \;

Install OpenCV:

For Windows: C++(Visual Studio)

  1. Download latest OpenCV from http://sourceforge.net/projects/opencvlibrary/?source=typ_redirect.
  2. Make a dir named build. Use cmake to generate OpenCV.sln in build.
  3. Click OpenCV.sln and CMakeTargets->INSTALL->build. You can build it in both debug and release modes.
  4. In the environmental variables, add D:\Program Files\OpenCV_3.0.0\build\install\x64\vc11 as OPENCV_DIR, add Path with %OPENCV_DIR%\bin.
  5. Create a OpenCV project. C/C++->General->Additional Include Directories: $(OPENCV_DIR)\..\..\include
  6. Linker->General->Additional Library Directories: $(OPENCV_DIR)\lib
  7. Linker->Input->Additional Dependencies: copy all the lib files. *d.lib means debug mode.

Note that there may be some problems for visual studio to recognize the updated environmental variable. Try to restart the visual studio or recreate the project.

For Linux: install for C++

  1. pre-install packages
    [compiler] sudo apt-get install build-essential
    [required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
    [optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
  2. download the required version on https://sourceforge.net/projects/opencvlibrary/
  3. make and install
    1
    2
    3
    4
    5
    mkdir build
    cd build
    cmake .. //cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
    make
    sudo make install

Tips: if you want to install multiple versions of OpenCV, set CMAKE_INSTALL_PREFIX differently for different versions of OpenCV.

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
    -D PYTHON_EXECUTABLE=/usr/bin/python \
    -D BUILD_EXAMPLES=ON ..

If want to turn off some modules, use -D BUILD_opencv_xfeatures2d=OFF

Switch between different versions of OpenCV:

switch from version 3.2 to version 2.4 shell

switch from version 2.4 to version 3.2 shell

For Linux: Python(Anaconda)

source activate tgt_env
conda install -c https://conda.binstar.org/menpo opencv
spyder

Then try import cv2