1Installation in Linux {#tutorial_linux_install} 2===================== 3 4These steps have been tested for Ubuntu 10.04 but should work with other distros as well. 5 6Required Packages 7----------------- 8 9- GCC 4.4.x or later 10- CMake 2.8.7 or higher 11- Git 12- GTK+2.x or higher, including headers (libgtk2.0-dev) 13- pkg-config 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 20The packages can be installed using a terminal and the following commands or by using Synaptic 21Manager: 22@code{.bash} 23[compiler] sudo apt-get install build-essential 24[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 25[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev 26@endcode 27Getting OpenCV Source Code 28-------------------------- 29 30You can use the latest stable OpenCV version or you can grab the latest snapshot from our [Git 31repository](https://github.com/Itseez/opencv.git). 32 33### Getting the Latest Stable OpenCV Version 34 35- Go to our [downloads page](http://opencv.org/downloads.html). 36- Download the source archive and unpack it. 37 38### Getting the Cutting-edge OpenCV from the Git Repository 39 40Launch Git client and clone [OpenCV repository](http://github.com/itseez/opencv). If you need 41modules from [OpenCV contrib repository](http://github.com/itseez/opencv_contrib) then clone it too. 42 43For example 44@code{.bash} 45cd ~/<my_working_directory> 46git clone https://github.com/Itseez/opencv.git 47git clone https://github.com/Itseez/opencv_contrib.git 48@endcode 49Building OpenCV from Source Using CMake 50--------------------------------------- 51 52-# Create a temporary directory, which we denote as \<cmake_build_dir\>, where you want to put 53 the generated Makefiles, project files as well the object files and output binaries and enter 54 there. 55 56 For example 57 @code{.bash} 58 cd ~/opencv 59 mkdir build 60 cd build 61 @endcode 62-# Configuring. Run cmake [\<some optional parameters\>] \<path to the OpenCV source directory\> 63 64 For example 65 @code{.bash} 66 cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. 67 @endcode 68 or cmake-gui 69 70 - set full path to OpenCV source code, e.g. /home/user/opencv 71 - set full path to \<cmake_build_dir\>, e.g. /home/user/opencv/build 72 - set optional parameters 73 - run: “Configure” 74 - run: “Generate” 75 76-# Description of some parameters 77 - build type: `CMAKE_BUILD_TYPE=Release\Debug` 78 - to build with modules from opencv_contrib set OPENCV_EXTRA_MODULES_PATH to \<path to 79 opencv_contrib/modules/\> 80 - set BUILD_DOCS for building documents 81 - set BUILD_EXAMPLES to build all examples 82 83-# [optional] Building python. Set the following python parameters: 84 - PYTHON2(3)_EXECUTABLE = \<path to python\> 85 - PYTHON_INCLUDE_DIR = /usr/include/python\<version\> 86 - PYTHON_INCLUDE_DIR2 = /usr/include/x86_64-linux-gnu/python\<version\> 87 - PYTHON_LIBRARY = /usr/lib/x86_64-linux-gnu/libpython\<version\>.so 88 - PYTHON2(3)_NUMPY_INCLUDE_DIRS = 89 /usr/lib/python\<version\>/dist-packages/numpy/core/include/ 90 91-# [optional] Building java. 92 - Unset parameter: BUILD_SHARED_LIBS 93 - It is useful also to unset BUILD_EXAMPLES, BUILD_TESTS, BUILD_PERF_TESTS - as they all 94 will be statically linked with OpenCV and can take a lot of memory. 95 96-# Build. From build directory execute make, recomend to do it in several threads 97 98 For example 99 @code{.bash} 100 make -j7 # runs 7 jobs in parallel 101 @endcode 102-# [optional] Building documents. Enter \<cmake_build_dir/doc/\> and run make with target 103 "html_docs" 104 105 For example 106 @code{.bash} 107 cd ~/opencv/build/doc/ 108 make -j7 html_docs 109 @endcode 110-# To install libraries, from build directory execute 111 @code{.bash} 112 sudo make install 113 @endcode 114-# [optional] Running tests 115 116 - Get the required test data from [OpenCV extra 117 repository](https://github.com/Itseez/opencv_extra). 118 119 For example 120 @code{.bash} 121 git clone https://github.com/Itseez/opencv_extra.git 122 @endcode 123 - set OPENCV_TEST_DATA_PATH environment variable to \<path to opencv_extra/testdata\>. 124 - execute tests from build directory. 125 126 For example 127 @code{.bash} 128 <cmake_build_dir>/bin/opencv_test_core 129 @endcode 130 131@note 132 If the size of the created library is a critical issue (like in case of an Android build) you 133 can use the install/strip command to get the smallest size as possible. The *stripped* version 134 appears to be twice as small. However, we do not recommend using this unless those extra 135 megabytes do really matter. 136