当前位置:文档之家› opencv install manual

opencv install manual

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.2 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 VS2010 distribution then you

must use CMake to build OpenCV binaries from the sources.
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.2 is known to work with latest versions of Visual Studio (such as VS2008, VS2010, including Express Editions) and MinGW on Windows, Xcode 3.2 or later on MacOSX, GCC 4.3 or later on Linux and other Unix-like systems). In the case of older compilers you may prefer OpenCV 1.1 instead.

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.6.x or 2.7.x (Python 3.x support status is unknown) and Numpy, including the development files: Python.h, ndarrayobject.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 users - you can take libtbb2 and libtbb-dev packages from Ubuntu 10.04 (Lucid Lynx), they are known to install and work flawlessly on 9.10.

(Optional) Qt 4.6 or later. You can use Qt as HighGUI backend on any platforms (Windows, Linux, Mac) by passing WITH_QT=ON to CMake when configuring OpenCV.

(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 default GUI backend for highgui on OSes other than Windows and MacOSX.
(Optional) libjpeg, libtiff, libjasper, libpng and zlib, openexr. Install any of those with the associated

development packages (libjpeg-dev etc. on Debian/Ubuntu) if you want to use those stock libraries to read and write images in the respective formats, instead of using the versions supplied with OpenCV (openexr is not supplied)
(Optional) ffmpeg, libgstreamer, libxine, unicap, libdc1394 2.x.

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 sh

ow you, which of the packages have been detected and will be used in highgui. (Unable full video support with FFMPEG). For example, on Ubuntu 9.10 all the necessary ffmpeg files can be installed using the following command:

sudo apt-get install libavformat-dev libswscale-dev


Extra Prerequisites (MacOSX)
Xcode 3.2 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.


Extra Prerequisites (Android)
See the Android build page for details.



2) Get the latest stable OpenCV version
Go to https://www.doczj.com/doc/437517925.html,/projects/opencvlibrary

Windows: download the executable installation package for Windows and run it. Note that the package is 32-bit only, and does not include TBB support (thus you can not take advantage of multiple cores unless you are doing threading youself at the application level). It is generally recommended to download the source .zip package and rebuild OpenCV from scratch using the same compiler that you use to build your applications.
Linux/MacOSX/other operating systems: download the source tarball (OpenCV-x.y.z.tar.bz2)

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://https://www.doczj.com/doc/437517925.html,/svn/opencv/trunk

or the latest tested OpenCV snapshot from here: https://https://www.doczj.com/doc/437517925.html,/svn/opencv/tags/latest_tested_snapshot

In Linux/MacOSX it can be done using the command line, e.g.:
cd ~/
svn co https://https://www.doczj.com/doc/437517925.html,/svn/opencv/trunk

3) Build the OpenCV library from source using CMake & GCC
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.


Configure using CMake
In general you should:
Create a temporary directory, which we denote as , 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". If you have them installed, turn on TBB and IPP support in order to get a better performance. Also, if you want to build Python wrappers, samples or the reference manual in PDF, you should explicitly turn them on. (It might be wise to try first with all options turned off, and make sure that works first.)

If you are us

ing command line, enter the and type

cmake [] 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.
. ~ Note for newbie linux users:
Do the cmake step from inside the folder where you want to build OpenCV. It is a good practice to keep your source and build files (the files that are going to be generated after the cmake step) separately. Remember to specify the source folder while invoking cmake as the last argument. Otherwise cmake will scan for CMakeLists.txt file in the usual standard location /usr/local/src and will throw an error. Unzipping all OpenCV directories from the source files to the src folder is not an elegant way of doing things in linux.
. If you have a gui version of cmake installed, just do this from inside the build folder, $ ccmake

Another example for Windows users (assuming the .exe extracted files to C:\OpenCV2.2\)
cd C:\OpenCV2.2 # the directory containing INSTALL, CMakeLists.txt etc.
mkdir release
cd release
cmake -D:CMAKE_BUILD_TYPE=RELEASE C:\OpenCV2.2Note 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: YESUsing 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: NOIt 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.2(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: If there are multiple IPP versions installed on the machine (not necess

arily 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.



Compile using GCC
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) or "make install" (Windows). (Note that the correct "make" is probably C:\MinGW\bin\mingw32-make.exe.)

If your IDE did not run "make install", either do so from the command line, or otherwise let your system know where to find the generated libraries. To do this without "make install":
In Linux you should add /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 ldconfigIn MacOSX you should add /lib[/debug|/release] to DYLD_LIBRARY_PATH.

In Windows you should add the build dir to the system path to the system path (My Computer--[Right button click]-->Properties->Advanced->Environment Variables->Path). Potential build dirs, depending on your config:

/bin

/bin/debug

/bin/release

Look for libopencv-core220.dll or libopencv_core220.a.

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 /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.pyIf 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:
Visual Studio,

Eclipse,

C++Builder,

DevCpp,

CodeBlocks,

Linux,

Mac OS/X,

MinGW,

Android

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 specif

y the necessary paths and options manually, e.g.:
g++ -o my_example my_example.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacyNote that if you build OpenCV statically, you also need to link all the OpenCV dependencies
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 -lopencv_core -lopencv_imgproc ...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`

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.


相关主题
文本预览
相关文档 最新文档