OpenCV
4.5.0
Open Source Computer Vision
|
There are two ways of installing OpenCV on your machine: download prebuilt version for your platform or compile from sources.
In many cases you can find prebuilt version of OpenCV that will meet your needs.
Packages for Android, iOS and Windows built with default parameters and recent compilers are published for each release, they do not contain opencv_contrib modules.
Other organizations and people maintain their own binary distributions of OpenCV. For example:
It can happen that existing binary packages are not applicable for your use case, then you'll have to build custom version of OpenCV by yourself. This section gives a high-level overview of the build process, check tutorial for specific platform for actual build instructions.
OpenCV uses CMake build management system for configuration and build, so this section mostly describes generalized process of building software with CMake.
Install C++ compiler and build tools. On *NIX platforms it is usually GCC/G++ or Clang compiler and Make or Ninja build tool. On Windows it can be Visual Studio IDE or MinGW-w64 compiler. Native toolchains for Android are provided in the Android NDK. XCode IDE is used to build software for OSX and iOS platforms.
Install CMake from the official site or some other source.
Get other third-party dependencies: libraries with extra functionality like decoding videos or showing GUI elements; libraries providing optimized implementations of selected algorithms; tools used for documentation generation and other extras. Check OpenCV configuration options reference for available options and corresponding dependencies.
Typical software project consists of one or several code repositories. OpenCV have two repositories with code: opencv - main repository with stable and actively supported algorithms and opencv_contrib which contains experimental and non-free (patented) algorithms; and one repository with test data: opencv_extra.
You can download a snapshot of repository in form of an archive or clone repository with full history.
To download snapshot archives:
To clone repositories run the following commands in console (git must be installed):
At this step CMake will verify that all necessary tools and dependencies are available and compatible with the library and will generate intermediate files for the chosen build system. It could be Makefiles, IDE projects and solutions, etc. Usually this step is performed in newly created build directory:
cmake-gui
application allows to see and modify available options using graphical user interface. See https://cmake.org/runningcmake/ for details.During build process source files are compiled into object files which are linked together or otherwise combined into libraries and applications. This step can be run using universal command:
... or underlying build system can be called directly:
During installation procedure build results and other files from build directory will be copied to the install location. Default installation location is /usr/local
on UNIX and C:/Program Files
on Windows. This location can be changed at the configuration step by setting CMAKE_INSTALL_PREFIX
option. To perform installation run the following command:
sudo cmake ...
).