Installation in Linux
Table of Contents
Prev Tutorial:
Prev Tutorial:
| Original author | Ana Huamán |
| Compatibility | OpenCV >= 3.0 |
# Install minimal prerequisites (Ubuntu 18.04 as reference)
sudo apt update && sudo apt install -y cmake g++ wget unzip
# Download and unpack sources
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
unzip opencv.zip
# Create build directory
mkdir -p build && cd build
# Configure
cmake ../opencv-4.x
# Build
cmake --build .# Install minimal prerequisites (Ubuntu 18.04 as reference)
sudo apt update && sudo apt install -y cmake g++ wget unzip
# Download and unpack sources
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.x.zip
unzip opencv.zip
unzip opencv_contrib.zip
# Create build directory and switch into it
mkdir -p build && cd build
# Configure
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.x/modules ../opencv-4.x
# Build
cmake --build .This section provides more details of the build process and describes alternative methods and tools. Please refer to the OpenCV installation overview tutorial for general installation details and to the OpenCV configuration options reference for configuration options documentation.
sudo apt install -y g++sudo apt install -y clangsudo apt install -y cmakesudo apt install -y makesudo apt install -y ninja-buildsudo apt install -y wget unzipsudo apt install -y gitThere are two methods of getting OpenCV sources:
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
unzip opencv.zip
mv opencv-4.x opencvgit clone https://github.com/opencv/opencv.git
git -C opencv checkout 4.xmkdir -p build && cd buildcmake ../opencvcmake -GNinja ../opencvmake -j4ninjaAfter successful build you will find libraries in the build/lib directory and executables (test, samples, apps) in the build/bin directory:
ls bin
ls libCMake package files will be located in the build root:
ls OpenCVConfig*.cmake
ls OpenCVModules.cmakeBy 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):
sudo make installor
sudo ninja installInstallation 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 OpenCV configuration options reference for details.