How To Install OpenCV on Linux Mint 21
In this tutorial, we will show you how to install OpenCV on Linux Mint 21. For those of you who didn’t know, OpenCV (Open Source Computer Vision Library) is a powerful open-source library used for computer vision, machine learning, and image processing. It plays a significant role in real-time operations, which are crucial in today’s systems. By using OpenCV, one can process images and videos to identify objects, faces, or even human handwriting. When integrated with various libraries, such as Numpy, Python can process the OpenCV array structure for analysis.
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 Linux Mint 21.2 (Victoria).
Prerequisites
- A server running one of the following operating systems: Linux Mint 21.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- While we’ll guide you through the process, a basic understanding of the command line will be beneficial. If you’re new to the CLI, you might want to acquaint yourself with some fundamental commands.
- An active internet connection.
- Administrative privileges are essential for installing and configuring software on your system. Ensure that you have superuser or sudo access.
Install OpenCV on Linux Mint 21
Step 1. Before installing any new software, it’s always a good idea to update your system. This ensures that you have the latest security patches and software updates. Use the following command to update your system:
sudo apt update sudo apt upgrade
Step 2.Installing Python and PIP.
Before installing OpenCV, ensure that Python and PIP are preinstalled on your system. You can check if Python is already installed by opening the terminal and running the following command:
python --version
If Python is not present, you will need to install it. Similarly, to check if PIP is installed, run the following command:
pip3 --version
Step 3. Installing Required Dependencies.
OpenCV relies on other libraries to function properly. Install the required dependencies:
sudo apt install libgtk-3-dev libboost-all-dev libatlas-base-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev gfortran openexr libopenexr-dev python3-dev python3-numpy libtbb2 libtbb-dev libdc1394-22-dev
Step 4. Installing OpenCV on Linux Mint 21.
Clone the OpenCV and OpenCV contrib repository to get the latest source files:
mkdir ~/opencv_build && cd ~/opencv_build git clone https://github.com/opencv/opencv.git git clone https://github.com/opencv/opencv_contrib.git
Build OpenCV with CMake and use make to compile the source code:
cd ~/opencv_build/opencv mkdir build && cd build 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 .. make -j$(nproc) sudo make install
This will install OpenCV to /usr/local/
by default.
Check that OpenCV is installed correctly by importing cv2 in Python:
python3 -c "import cv2; print(cv2.__version__)"
This should print out the OpenCV version installed.
You can also run some of the examples in /usr/local/share/opencv4/samples/python
to verify OpenCV is working properly.
Congratulations! You have successfully installed OpenCV. Thanks for using this tutorial to install the latest version of OpenCV on the Linux Mint system. For additional help or useful information, we recommend you check the official OpenCV website.