How To Install OpenCV on Debian 11

Install OpenCV on Debian 11

In this tutorial, we will show you how to install OpenCV on Debian 11. For those of you who didn’t know, OpenCV (Open Source Computer Vision Library) is an open-source computer vision library and has bindings for C++, Python, and Java. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in commercial products.

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 through the step-by-step installation of the OpenCV on a Debian 11 (Bullseye).

Prerequisites

  • A server running one of the following operating systems: Debian 10 or Debian 11.
  • It’s recommended that you use a fresh OS install to prevent any potential issues
  • A non-root sudo useror access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install OpenCV on Debian 11 Bullseye

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

Step 2. Installing OpenCV on Debian 11.

  • Install OpenCV from the Debian Repository.

By default, OpenCV is available on Debian 11 base repository. So, now we install the latest stable version of OpenCV using the following command below:

sudo apt install python3-opencv

Verify OpenCV installation:

python3 -c "import cv2; print(cv2.__version__)"
  • Install OpenCV from the Source.

First, install all 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, make a new directory and change the present working directory:

mkdir opencv_git
cd opencv_git

Then, clone OpenCV using the following command:

git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

After cloning, create a directory and switch to that newly made folder:

cd opencv
mkdir cvbuild
cd cvbuild

Next, configure the OpenCV infrastructure by running the following command below:

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/module \ -D BUILD_EXAMPLES=ON ..

Now start the compilation process:

make -j1
sudo make install

Finally, verify the OpenCV successfully installation:

pkg-config --modversion opencv4

Congratulations! You have successfully installed OpenCV. Thanks for using this tutorial for installing the latest version of the OpenCV on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official OpenCV website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!