9f691c25899a40163c51a1d46beb2996985189ab
[platform/upstream/opencv.git] / doc / tutorials / introduction / linux_install / linux_install.markdown
1 Installation in Linux {#tutorial_linux_install}
2 =====================
3
4 The following steps have been tested for Ubuntu 10.04 but should work with other distros as well.
5
6 Required 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 -   [optional] CUDA Toolkit 6.5 or higher
20
21 The packages can be installed using a terminal and the following commands or by using Synaptic
22 Manager:
23 @code{.bash}
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
27 @endcode
28 Getting OpenCV Source Code
29 --------------------------
30
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).
33
34 ### Getting the Latest Stable OpenCV Version
35
36 -   Go to our [downloads page](http://opencv.org/releases.html).
37 -   Download the source archive and unpack it.
38
39 ### Getting the Cutting-edge OpenCV from the Git Repository
40
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.
43
44 For example
45 @code{.bash}
46 cd ~/<my_working_directory>
47 git clone https://github.com/opencv/opencv.git
48 git clone https://github.com/opencv/opencv_contrib.git
49 @endcode
50 Building OpenCV from Source Using CMake
51 ---------------------------------------
52
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
55     there.
56
57     For example
58     @code{.bash}
59     cd ~/opencv
60     mkdir build
61     cd build
62     @endcode
63 -#  Configuring. Run cmake [\<some optional parameters\>] \<path to the OpenCV source directory\>
64
65     For example
66     @code{.bash}
67     cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
68     @endcode
69     or cmake-gui
70
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
74     -   run: “Configure”
75     -   run: “Generate”
76
77     @note
78     Use `cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..` , without spaces after -D if the above example doesn't work.
79
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
86
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/
94
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.
99
100 -#  Build. From build directory execute *make*, it is recommended to do this in several threads
101
102     For example
103     @code{.bash}
104     make -j7 # runs 7 jobs in parallel
105     @endcode
106 -#  [optional] Building documents. Enter \<cmake_build_dir/doc/\> and run make with target
107     "doxygen"
108
109     For example
110     @code{.bash}
111     cd ~/opencv/build/doc/
112     make -j7 doxygen
113     @endcode
114 -#  To install libraries, execute the following command from build directory
115     @code{.bash}
116     sudo make install
117     @endcode
118 -#  [optional] Running tests
119
120     -   Get the required test data from [OpenCV extra
121         repository](https://github.com/opencv/opencv_extra).
122
123     For example
124     @code{.bash}
125     git clone https://github.com/opencv/opencv_extra.git
126     @endcode
127     -   set OPENCV_TEST_DATA_PATH environment variable to \<path to opencv_extra/testdata\>.
128     -   execute tests from build directory.
129
130     For example
131     @code{.bash}
132     <cmake_build_dir>/bin/opencv_test_core
133     @endcode
134
135 @note
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.