1 Installation in Linux {#tutorial_linux_install}
4 The following steps have been tested for Ubuntu 10.04 but should work with other distros as well.
10 - CMake 2.8.7 or higher
12 - GTK+2.x or higher, including headers (libgtk2.0-dev)
14 - Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
15 - ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
16 - [optional] libtbb2 libtbb-dev
17 - [optional] libdc1394 2.x
18 - [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
19 - [optional] CUDA Toolkit 6.5 or higher
21 The packages can be installed using a terminal and the following commands or by using Synaptic
24 [compiler] sudo apt-get install build-essential
25 [required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
26 [optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
28 Getting OpenCV Source Code
29 --------------------------
31 You can use the latest stable OpenCV version or you can grab the latest snapshot from our [Git
32 repository](https://github.com/opencv/opencv.git).
34 ### Getting the Latest Stable OpenCV Version
36 - Go to our [downloads page](http://opencv.org/releases.html).
37 - Download the source archive and unpack it.
39 ### Getting the Cutting-edge OpenCV from the Git Repository
41 Launch Git client and clone [OpenCV repository](http://github.com/opencv/opencv). If you need
42 modules from [OpenCV contrib repository](http://github.com/opencv/opencv_contrib) then clone it as well.
46 cd ~/<my_working_directory>
47 git clone https://github.com/opencv/opencv.git
48 git clone https://github.com/opencv/opencv_contrib.git
50 Building OpenCV from Source Using CMake
51 ---------------------------------------
53 -# Create a temporary directory, which we denote as \<cmake_build_dir\>, where you want to put
54 the generated Makefiles, project files as well the object files and output binaries and enter
63 -# Configuring. Run cmake [\<some optional parameters\>] \<path to the OpenCV source directory\>
67 cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
71 - set full path to OpenCV source code, e.g. /home/user/opencv
72 - set full path to \<cmake_build_dir\>, e.g. /home/user/opencv/build
73 - set optional parameters
78 Use `cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..` , without spaces after -D if the above example doesn't work.
80 -# Description of some parameters
81 - build type: `CMAKE_BUILD_TYPE=Release\Debug`
82 - to build with modules from opencv_contrib set OPENCV_EXTRA_MODULES_PATH to \<path to
83 opencv_contrib/modules/\>
84 - set BUILD_DOCS for building documents
85 - set BUILD_EXAMPLES to build all examples
87 -# [optional] Building python. Set the following python parameters:
88 - PYTHON2(3)_EXECUTABLE = \<path to python\>
89 - PYTHON_INCLUDE_DIR = /usr/include/python\<version\>
90 - PYTHON_INCLUDE_DIR2 = /usr/include/x86_64-linux-gnu/python\<version\>
91 - PYTHON_LIBRARY = /usr/lib/x86_64-linux-gnu/libpython\<version\>.so
92 - PYTHON2(3)_NUMPY_INCLUDE_DIRS =
93 /usr/lib/python\<version\>/dist-packages/numpy/core/include/
95 -# [optional] Building java.
96 - Unset parameter: BUILD_SHARED_LIBS
97 - It is useful also to unset BUILD_EXAMPLES, BUILD_TESTS, BUILD_PERF_TESTS - as they all
98 will be statically linked with OpenCV and can take a lot of memory.
100 -# Build. From build directory execute *make*, it is recommended to do this in several threads
104 make -j7 # runs 7 jobs in parallel
106 -# [optional] Building documents. Enter \<cmake_build_dir/doc/\> and run make with target
111 cd ~/opencv/build/doc/
114 -# To install libraries, execute the following command from build directory
118 -# [optional] Running tests
120 - Get the required test data from [OpenCV extra
121 repository](https://github.com/opencv/opencv_extra).
125 git clone https://github.com/opencv/opencv_extra.git
127 - set OPENCV_TEST_DATA_PATH environment variable to \<path to opencv_extra/testdata\>.
128 - execute tests from build directory.
132 <cmake_build_dir>/bin/opencv_test_core
136 If the size of the created library is a critical issue (like in case of an Android build) you
137 can use the install/strip command to get the smallest size possible. The *stripped* version
138 appears to be twice as small. However, we do not recommend using this unless those extra
139 megabytes do really matter.