In this tutorial, we will show you how to install OpenCV on Debian 10. For those of you who didn’t know, OpenCV (Open Source Computer Vision Library) is an open-source, highly optimized computer library mainly used in applications for image processing. It has a variety of inbuilt image processing functions helping you to get started easily. It runs on Linux, Windows, Mac OS, iOS, and Android.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of OpenCV on a Debian 10 (Buster) server.
Prerequisites
- A server running one of the following operating systems: Debian 10 (Buster).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install OpenCV on Debian 10 Buster
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt upgrade sudo apt install python3-opencv
Step 2. Installing OpenCV on Debian 10.
First, Install the required and optional dependencies:
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
Next, clone the OpenCV’s and OpenCV contrib repositories:
mkdir ~/opencv_build && cd ~/opencv_build git clone https://github.com/opencv/opencv.git git clone https://github.com/opencv/opencv_contrib.git
Once the download is completed, create a temporary build directory:
cd ~/opencv_build/opencv mkdir build cd build
Then, set up the OpenCV build with CMake:
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 ..
Start the compilation process:
make -j2
Finally step, Install OpenCV using the following command:
sudo make install
Check whether OpenCV has been installed successfully, enter the following command:
pkg-config --modversion opencv4
Congratulations! You have successfully installed OpenCV. Thanks for using this tutorial for installing OpenCV on your Debian 10 Buster system. For additional help or useful information, we recommend you to check the official OpenCV website.