Skip to content

Instantly share code, notes, and snippets.

@Nannigalaxy
Created September 20, 2021 08:23
Show Gist options
  • Save Nannigalaxy/2991f723af477c406ea630f2ea992c4f to your computer and use it in GitHub Desktop.
Save Nannigalaxy/2991f723af477c406ea630f2ea992c4f to your computer and use it in GitHub Desktop.
OpenCV for C++ and Python with contrib modules
# Date: 20 Sept 2021
# Script for installing opencv for c++ and python with contrib modules
# Tested on Pop!_OS 20.04
echo "Installing Pre-requisites"
sudo apt install build-essential cmake git pkg-config libgtk-3-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev \
gfortran openexr libatlas-base-dev python3-dev python3-numpy \
libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev \
libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
mkdir ~/opencv_build && cd ~/opencv_build
echo "Downloading Opencv"
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
cd ~/opencv_build/opencv
mkdir -p build && cd build
echo "Generating configuration"
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
echo "Installing OpenCV"
make -j$(nproc)
sudo make install
echo "Testing Installation"
pkg-config --modversion opencv4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment