OpenCV Installation Guide
Overview:
1) First you need to install CMake and maybe some prerequisite tools (particularly for Linux and Mac).
2) If you want the latest 2.1 release of OpenCV, get it here for Windows, Linux or Mac.
(Or if you want the latest code being developed, get it from our SVN server)
3) After downloading OpenCV, if you did not download the VS2008 distribution then you
- must use CMake to build OpenCV binaries from code.
4) Finally you must configure your C/C++ compiler so it knows where to find OpenCV for your projects.
- (Installation guides for popular compilers are given below).
1) Prerequisites
Common Prerequisites
- C/C++ compiler (OpenCV 2.1 is known to work with VC8 or later such as VS2005, VS2008, VS2010
including Express Editions, and MinGW on Windows, Xcode 3.1 or later on MacOSX, GCC 4.x on Linux and other Unix-like systems). For older compilers such as VC6, use OpenCV 1.1 or older.
CMake 2.6 or later. CMake is now the only method of building OpenCV SVN snapshots.
(Optional) Subversion client (e.g. command-line svn tool, SmartSVN, Tortoise SVN)
(Optional) Python 2.5.x or 2.6.x (Python 3.x support status is unknown),
- including the development files: Python.h, etc. in order to build Python wrappers
(Optional) Intel TBB to enable parallel code in OpenCV. We do not use OpenMP any longer. Important note: Only TBB 2.2 or later will work. For Ubuntu 9.10 or 10.04 users - you can take libtbb2 and libtbb-dev packages from Ubuntu 10.04 (Lucid Lynx), they are known to install and work flawlessly on both 9.10 and 10.04. Others can build TBB 2.2 or later from the sources.
(Optional) IPP 5.1 or later. OpenCV does not require IPP, but can be configured to
- use IPP to make some functions run faster.
(Optional) LiveTeX distribution (or MiKTeX on Windows) to build the up-to-date OpenCV reference manual PDF
Extra Prerequisites (Linux/BSD/other Unix-like OSes)
- pkg-config. It is used at the configuration stage and also simplifies the further use of OpenCV itself.
(Optional) gtk+ 2.x and the related packages (glib, gthread etc.).
- This is the GUI toolkit of choice for highgui on OSes other than Windows and MacOSX.
(Optional) libjpeg, libtiff, libjasper, libpng and zlib. Install any of those with the associated
- development packages (libjpeg-dev etc. on Debian/Ubuntu) to be able to read/write the corresponding image formats.
(Optional) ffmpeg, libgstreamer, libxine, unicap, libdc1394 2.x (or libdc1394 1.x + libraw1394).
You should have some/all of these packages installed (together with associated development packages) to add video capturing, video decoding and video encoding capabilities to highgui. The output of the cmake will show you, which of the packages have been detected and will be used in highgui. (Unable full video support with FFMPEG). For example, on Ubuntu 8.10 all the necessary ffmpeg files can be installed using the following command:
sudo apt-get install libavformat-dev libswscale-dev
- For Debian / Ubuntu
Extra Prerequisities (MacOSX)
Xcode 3.1 or later. It does not only include the required C++ compiler, but also Cocoa, QTKit and other frameworks that make highgui on MacOSX functional. Besides, CMake can generate Xcode projects by the command "ccmake -G Xcode", so you can build OpenCV conveniently from within the IDE. Additional information can be found on the Mac_OS_X_OpenCV_Port page.
2) Get the latest stable OpenCV version
- Windows: download the executable installation package for Windows and run it
- Linux/MacOSX/other operating systems: download the source tarball and unpack it
Or get the cutting-edge OpenCV from SourceForge SVN repository
- If you want the newest code that is still in development, launch SVN client and checkout either:
the current OpenCV snapshot from here: https://code.ros.org/svn/opencv/trunk
or the latest tested OpenCV snapshot from here: http://code.ros.org/svn/opencv/tags/latest_tested_snapshot
- In Linux/MacOSX it can be done using the command line, e.g.:
cd ~/<my_working_directory> svn co https://code.ros.org/svn/opencv/trunk
3) Build the OpenCV library from source using CMake
Note: Specific guides to compiling the OpenCV source are also available for Mac, Ubuntu (prebuilt packages), Debian & Ubuntu (manual install), Linux and MinGW. Visual Studio 2008 users can skip this section since their installation comes with prebuilt DLL and LIB files.
- In general you should:
Create a temporary directory, which we denote as <cmake_binary_dir>, where you want to put the generated Makefiles, Visual Studio, Xcode or Eclipse etc. project files as well the object files and output binaries. You can do it using CMake GUI.
- 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.
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 (see here).
Using TBB (Optional). If you have TBB installed (see the Prerequisites), turn on WITH_TBB option, adjust the TBB include and library paths if needed. You should see the following message in the CMake output:
USE TBB: YES
Using IPP (Optional). 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.
- If you generated project files for Visual Studio, Xcode, Eclipse etc., run the respective IDE, open the OpenCV top-level project/solution/workspace etc. and build it.
- 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).
- If you did not run "make install", you should let your system know where to find the generated libraries.
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).
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
In MacOSX you should add <cmake_binary_dir>/lib[/debug|/release] to DYLD_LIBRARY_PATH.
- Note that the step is not needed to run OpenCV samples, because:
- on Windows both OpenCV DLLs and the samples are placed into the same directory
- on Linux/MacOSX CMake embeds the correct library paths into the executables
Testing OpenCV
- You may turn on "BUILD_EXAMPLES" in CMake GUI or run cmake with "-D BUILD_EXAMPLES=ON" option, then it will include short demo samples to the build. Note that some of them need image files from the original source directory, you may just copy them to the bin directory.
You can also run correctness tests <cmake_binary_dir>/bin[/debug|/release]/cxcoretest and cvtest.
Testing Python wrappers
- As long as you build Python wrappers and installed them, you can just enter opencv/samples/python and run the samples, e.g.
python delaunay.py
- If you want to try Python samples without installing OpenCV, put cv.so/cv.pyd to opencv/samples/python directory, or rather add the directory containing cv.so/cv.pyd to PYTHON_LIBRARY_PATH, e.g.
export PYTHON_LIBRARY_PATH=~/projects/opencv/release/lib:$PYTHON_LIBRARY_PATH
4) Configure your own projects to use OpenCV
- Installation guides are available for:
You can use CMake for your own projects, by looking at the Getting_started and FindOpenCV.cmake pages.
- Or you can add opencv 'include', 'lib' and 'bin' subdirectories to your IDE settings.
- Or for hand-written Makefiles you can specify the necessary paths and options manually, e.g.:
g++ -o my_example my_example.cpp -I<opencv_source_dir>/include[/opencv] \ -L<cmake_binary_dir>/lib -lcxcore -lcv -lcvaux -lhighgui -lml
- Or you can use pkg-config and the provided "opencv.pc".
- Make sure that opencv.pc is found by pkg-config:
pkg-config opencv --libs # should print something like -lcxcore -lcv ...
- You can now use it in your Makefiles or build scripts, e.g.:
g++ -o my_example my_example.cpp `pkg-config opencv --cflags --libs`
- Make sure that opencv.pc is found by pkg-config:
5) Use OpenCV for state-of-the-art projects!
If you are new to OpenCV, you should first read the Beginners FAQ.
There are also some info on topics (such as Blob Detection and Face Recognition) in the FAQ Guide.
There are some tutorials (such as POSIT 3D Pose Estimation) in Tutorials.
- There are many sample programs that come with OpenCV in the "samples\c\" folder.
The best way to learn how to use OpenCV is to read the O'Reilly book "Learning OpenCV: Computer Vision with the OpenCV Library", that explains many important concepts such as Image Processing, Histogram Matching, Object Tracking, 3D Pose Estimation, Stereo Camera Calibration, Machine Learning, etc.
An up-to-date version of this manual can be found here: http://opencv.willowgarage.com/wiki/InstallGuide