Wednesday, April 14, 2010

Something about openCV

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision.  I wanna use some data structures and methods in it to make the program simpler to write.

OpenCV is released under a BSD license, it is free for both academic and commercial use. The library has >500 optimized algorithms (see figure below). It is used around the world, has >2M downloads and >40K people in the user group.

In case I forget, I move the installation & configuration guild here:


  1. Create a temporary directory, which we denote as <cmake_binary_dir>, where you want to put the generated Makefiles, VisualStudio, Xcode or Eclipse etc. project files as well the object files and output binaries. You can do it using CMake GUI.

    1. If you use CMake GUI, execute "Configure" to do the initial configuration, then adjust any options, then press "Configure" again and then press "Generate". For the best performance, and if your compiler and the platform supports it, it is recommended to turn on SSE2 optimization (on Mac and Windows it is turned on by default) and OpenMP support. Also, if you want to build Python wrappers, samples or the reference manual in PDF, you should explicitly turn it on.

    2. If you are using command line, enter the <cmake_binary_dir> and type

      • cmake [<some optional parameters...>] <path to the OpenCV source directory>
        For example, if you downloaded the project to ~/projects/opencv, you can do the following:
        cd ~/projects/opencv # the directory containing INSTALL, CMakeLists.txt etc.
            mkdir release
            cd release
            cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
        
      • that will generate makefiles for the Release configuration and will put them in ~/projects/opencv/release directory.
      • Another example for Windows users (assuming the .exe extracted files to C:\OpenCV2.1\)
        cd C:\OpenCV2.1 # the directory containing INSTALL, CMakeLists.txt etc.
            mkdir release
            cd release
            cmake -D:CMAKE_BUILD_TYPE=RELEASE C:\OpenCV2.1

      • Note that the use of the colon after the -D is required on Windows Vista (include if cmake is giving errors on other Windows distro's as well). If you are using MS Visual Studio cmake exits with an error message "error PRJ0003: Error spawning 'cmd.exe', make sure that you have the correct VC++ Executable Directories set.

  2. Using TBB. If you have TBB installed (see the Prerequisites), turn on USE_TBB option, adjust the TBB include and library paths if needed. You should see the following message in the CMake output:

    • USE TBB:  YES

  3. Using IPP. If you have IPP installed on your machine and want to build OpenCV with IPP support, check if IPP is turned on in CMake configuration options and if it was detected. First, look at the CMake output. If it prints

    • USE IPP:   NO

    • It means that IPP was not turned on or it was not detected. In this case turn it on (USE_IPP=ON) and pass the correct path to IPP shared libraries (IPP_PATH=<...>), like in the example below. While OpenCV currently uses static IPP libraries, it derives their path from the supplied path to the shared/dynamic IPP libraries.
      cmake -D:CMAKE_BUILD_TYPE=RELEASE -D:USE_IPP=ON -D:IPP_PATH="C:\Program Files\Intel\IPP\6.1.031\ia32\bin" C:\OpenCV2.1
    • (It's also easy to do the same using CMake GUI)
    • If you did everything right, you will see the following in the CMake output:
      USE IPP:   <ipp_path>
    • If there are multiple IPP versions installed on the machine (not necessarily all of them are in the system path) and you want to use the particular one, different from what CMake has found, just specify the correct IPP_PATH.


    1. If you generated project files for VisualStudio, Xcode, Eclipse etc., run the respective IDE, open the OpenCV top-level project/solution/workspace etc. and build it.
    2. If you generated makefiles, then enter the created temporary directory and run make/nmake utility. Then you can optionally run "sudo make install" (Linux, MacOSX).
  4. If you did not run "make install", you should let your system know where to find the generated libraries.

    1. In Windows you should add <cmake_binary_dir>/bin/debug and <cmake_binary_dir>/bin/release

      • to the system path (My Computer--[Right button click]-->Properties->Advanced->Environment Variables->Path).

    2. In Linux you should add <cmake_binary_dir>/lib[/debug|/release] to /etc/ld.so.conf or to LD_LIBRARY_PATH, e.g.:

      • export LD_LIBRARY_PATH=~/projects/opencv/release/lib:$LD_LIBRARY_PATH
            sudo ldconfig

    3. In MacOSX you should add <cmake_binary_dir>/lib[/debug|/release] to DYLD_LIBRARY_PATH.
  5. Note that the step is not needed to run OpenCV samples, because:
    1. on Windows both OpenCV DLLs and the samples are placed into the same directory
    2. on Linux/MacOSX CMake embeds the correct library paths into the executables




No comments:

Post a Comment