1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #18195 from mshabunin:linux-tutorial

Installation tutorials rework

* Doc: general installation, config reference, linux installation

* Doc: addressed review comments

* Minor fixes
This commit is contained in:
Maksim Shabunin
2020-10-08 00:35:06 +03:00
committed by GitHub
parent 537494f4dd
commit 46ccde82cf
31 changed files with 1158 additions and 358 deletions
@@ -3,146 +3,123 @@ Installation in Linux {#tutorial_linux_install}
@next_tutorial{tutorial_linux_gcc_cmake}
| | |
| -: | :- |
| Original author | Ana Huamán |
| Compatibility | OpenCV >= 3.0 |
The following steps have been tested for Ubuntu 10.04 but should work with other distros as well.
@tableofcontents
Required Packages
-----------------
# Quick start {#tutorial_linux_install_quick_start}
- GCC 4.4.x or later
- CMake 2.8.7 or higher
- Git
- GTK+2.x or higher, including headers (libgtk2.0-dev)
- pkg-config
- Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
- ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
- [optional] libtbb2 libtbb-dev
- [optional] libdc1394 2.x
- [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
- [optional] CUDA Toolkit 6.5 or higher
The packages can be installed using a terminal and the following commands or by using Synaptic
Manager:
@code{.bash}
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
@endcode
Getting OpenCV Source Code
--------------------------
## Build core modules {#tutorial_linux_install_quick_build_core}
You can use the latest stable OpenCV version or you can grab the latest snapshot from our [Git
repository](https://github.com/opencv/opencv.git).
@snippet linux_quick_install.sh body
### Getting the Latest Stable OpenCV Version
- Go to our [downloads page](http://opencv.org/releases.html).
- Download the source archive and unpack it.
## Build with opencv_contrib {#tutorial_linux_install_quick_build_contrib}
### Getting the Cutting-edge OpenCV from the Git Repository
@snippet linux_quick_install_contrib.sh body
Launch Git client and clone [OpenCV repository](http://github.com/opencv/opencv). If you need
modules from [OpenCV contrib repository](http://github.com/opencv/opencv_contrib) then clone it as well.
For example
@code{.bash}
cd ~/<my_working_directory>
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
@endcode
Building OpenCV from Source Using CMake
---------------------------------------
# Detailed process {#tutorial_linux_install_detailed}
-# Create a temporary directory, which we denote as \<cmake_build_dir\>, where you want to put
the generated Makefiles, project files as well the object files and output binaries and enter
there.
This section provides more details of the build process and describes alternative methods and tools. Please refer to the @ref tutorial_general_install tutorial for general installation details and to the @ref tutorial_config_reference for configuration options documentation.
For example
@code{.bash}
cd ~/opencv
mkdir build
cd build
@endcode
-# Configuring. Run cmake [\<some optional parameters\>] \<path to the OpenCV source directory\>
For example
@code{.bash}
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
@endcode
or cmake-gui
## Install compiler and build tools {#tutorial_linux_install_detailed_basic_compiler}
- set full path to OpenCV source code, e.g. /home/user/opencv
- set full path to \<cmake_build_dir\>, e.g. /home/user/opencv/build
- set optional parameters
- run: “Configure”
- run: “Generate”
- To compile OpenCV you will need a C++ compiler. Usually it is G++/GCC or Clang/LLVM:
- Install GCC...
@snippet linux_install_a.sh gcc
- ... or Clang:
@snippet linux_install_b.sh clang
@note
Use `cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..` , without spaces after -D if the above example doesn't work.
- OpenCV uses CMake build configuration tool:
@snippet linux_install_a.sh cmake
-# Description of some parameters
- build type: `CMAKE_BUILD_TYPE=Release\Debug`
- to build with modules from opencv_contrib set OPENCV_EXTRA_MODULES_PATH to \<path to
opencv_contrib/modules/\>
- set BUILD_DOCS for building documents
- set BUILD_EXAMPLES to build all examples
- CMake can generate scripts for different build systems, e.g. _make_, _ninja_:
-# [optional] Building python. Set the following python parameters:
- PYTHON2(3)_EXECUTABLE = \<path to python\>
- PYTHON_INCLUDE_DIR = /usr/include/python\<version\>
- PYTHON_INCLUDE_DIR2 = /usr/include/x86_64-linux-gnu/python\<version\>
- PYTHON_LIBRARY = /usr/lib/x86_64-linux-gnu/libpython\<version\>.so
- PYTHON2(3)_NUMPY_INCLUDE_DIRS =
/usr/lib/python\<version\>/dist-packages/numpy/core/include/
- Install Make...
@snippet linux_install_a.sh make
- ... or Ninja:
@snippet linux_install_b.sh ninja
-# [optional] Building java.
- Unset parameter: BUILD_SHARED_LIBS
- It is useful also to unset BUILD_EXAMPLES, BUILD_TESTS, BUILD_PERF_TESTS - as they all
will be statically linked with OpenCV and can take a lot of memory.
- Install tool for getting and unpacking sources:
-# [optional] Generate pkg-config info
- Add this flag when running CMake: `-DOPENCV_GENERATE_PKGCONFIG=ON`
- Will generate the .pc file for pkg-config and install it.
- Useful if not using CMake in projects that use OpenCV
- Installed as `opencv4`, usage: `pkg-config --cflags --libs opencv4`
- _wget_ and _unzip_...
@snippet linux_install_a.sh wget
- ... or _git_:
@snippet linux_install_b.sh git
-# Build. From build directory execute *make*, it is recommended to do this in several threads
For example
@code{.bash}
make -j7 # runs 7 jobs in parallel
@endcode
-# [optional] Building documents. Enter \<cmake_build_dir/doc/\> and run make with target
"doxygen"
## Download sources {#tutorial_linux_install_detailed_basic_download}
For example
@code{.bash}
cd ~/opencv/build/doc/
make -j7 doxygen
@endcode
-# To install libraries, execute the following command from build directory
@code{.bash}
sudo make install
@endcode
-# [optional] Running tests
There are two methods of getting OpenCV sources:
- Get the required test data from [OpenCV extra
repository](https://github.com/opencv/opencv_extra).
- Download snapshot of repository using web browser or any download tool (~80-90Mb) and unpack it...
@snippet linux_install_a.sh download
- ... or clone repository to local machine using _git_ to get full change history (>470Mb):
@snippet linux_install_b.sh download
For example
@code{.bash}
git clone https://github.com/opencv/opencv_extra.git
@endcode
- set OPENCV_TEST_DATA_PATH environment variable to \<path to opencv_extra/testdata\>.
- execute tests from build directory.
For example
@code{.bash}
<cmake_build_dir>/bin/opencv_test_core
@endcode
@note
If the size of the created library is a critical issue (like in case of an Android build) you
can use the install/strip command to get the smallest size possible. The *stripped* version
appears to be twice as small. However, we do not recommend using this unless those extra
megabytes do really matter.
Snapshots of other branches, releases or commits can be found on the [GitHub](https://github.com/opencv/opencv) and the [official download page](https://opencv.org/releases.html).
## Configure and build {#tutorial_linux_install_detailed_basic_build}
- Create build directory:
@snippet linux_install_a.sh prepare
- Configure - generate build scripts for the preferred build system:
- For _make_...
@snippet linux_install_a.sh configure
- ... or for _ninja_:
@snippet linux_install_b.sh configure
- Build - run actual compilation process:
- Using _make_...
@snippet linux_install_a.sh build
- ... or _ninja_:
@snippet linux_install_b.sh build
@note
_Configure_ process can download some files from the internet to satisfy library dependencies, connection failures can cause some of modules or functionalities to be turned off or behave differently. Refer to the @ref tutorial_general_install and @ref tutorial_config_reference tutorials for details and full configuration options reference.
@note
If you experience problems with the build process, try to clean or recreate the build directory. Changes in the configuration like disabling a dependency, modifying build scripts or switching sources to another branch are not handled very well and can result in broken workspace.
@note
_Make_ can run multiple compilation processes in parallel, `-j<NUM>` option means "run <NUM> jobs simultaneously". _Ninja_ will automatically detect number of available processor cores and does not need `-j` option.
## Check build results {#tutorial_linux_install_detailed_basic_verify}
After successful build you will find libraries in the `build/lib` directory and executables (test, samples, apps) in the `build/bin` directory:
@snippet linux_install_a.sh check
CMake package files will be located in the build root:
@snippet linux_install_a.sh check cmake
## Install
@warning
Installation process only copies files to predefined locations and do minor patching. Library installed using this method is not integrated into the system package registry and can not be uninstalled automatically. We do not recommend system-wide installation to regular users due to possible conflicts with system packages.
By default OpenCV will be installed to the `/usr/local` directory, all files will be copied to following locations:
* `/usr/local/bin` - executable files
* `/usr/local/lib` - libraries (.so)
* `/usr/local/cmake/opencv4` - cmake package
* `/usr/local/include/opencv4` - headers
* `/usr/local/share/opencv4` - other files (e.g. trained cascades in XML format)
Since `/usr/local` is owned by the root user, the installation should be performed with elevated privileges (`sudo`):
@snippet linux_install_a.sh install
or
@snippet linux_install_b.sh install
Installation root directory can be changed with `CMAKE_INSTALL_PREFIX` configuration parameter, e.g. `-DCMAKE_INSTALL_PREFIX=$HOME/.local` to install to current user's local directory. Installation layout can be changed with `OPENCV_*_INSTALL_PATH` parameters. See @ref tutorial_config_reference for details.