YouTube Icon

Code Playground.

How to Install OpenCV on Ubuntu 20.04

CFG

How to Install OpenCV on Ubuntu 20.04

OpenCV (Open Source Computer Vision Library) is an open-source PC vision library with ties for C++, Python, and Java and supports all major working frameworks. It can exploit multi-center preparing and highlights GPU speeding up for ongoing activity. 

OpenCV is utilized for a wide scope of utilizations, including clinical picture investigation, sewing road see pictures, observation video, identifying and perceiving faces, following moving articles, extricating 3D models, and substantially more. 

This article depicts how to introduce OpenCV on Ubuntu 20.04. To introduce the most recent stable variant of OpenCV from source, look down to the Installing OpenCV from the Source part of this instructional exercise. Pick the establishment strategy that works best for you. 

Installing OpenCV from the Ubuntu Repository

OpenCV is accessible for establishment from the default Ubuntu 20.04 storehouses. To introduce it run: 

sudo apt update
sudo apt install libopencv-dev python3-opencv

The order above will introduce all bundles important to run OpenCV. 

Confirm the establishment by bringing in the cv2 module and printing the OpenCV variant: 

python3 -c "import cv2; print(cv2.__version__)"

At the hour of composing, the adaptation in the stores is 4.2: 

4.2.0

Introducing OpenCV from the Source 

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

Play out the accompanying strides to introduce the most recent OpenCV form from the source: 

Introduce the construct instruments and conditions: 

mkdir ~/opencv_build && cd ~/opencv_build
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

libgstreamer-modules base1.0-dev libgstreamer1.0-dev 

Clone the OpenCV's and OpenCV contrib stores:

At the hour of composing, the default form in the github archives is adaptation 4.3.0. On the off chance that you need to introduce a more seasoned rendition of OpenCV, disc to both opencv and opencv_contrib catalogs and run git checkout <opencv-version> 

Once the download is finished, make a transitory form catalog, and explore to it: 

cd ~/opencv_build/opencv
mkdir -p build && cd build

Set up the OpenCV work 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 ..

The yield will look something like underneath: 

-- Configuring done
-- Generating done
-- Build files have been written to: /home/vagrant/opencv_build/opencv/build

Start the accumulation cycle: 

make -j8

Change the - j banner as per your processor. On the off chance that you don't have the foggiest idea about the quantity of centers your processor, you can discover it by composing nproc. 

The aggregation may take a few minutes or more, contingent upon your framework arrangement. 

Introduce OpenCV with: 

sudo make install

To check the establishment, type the accompanying orders and you should see the OpenCV variant. 

C++ ties: 

pkg-config --modversion opencv4
4.3.0

Python ties: 

python3 -c "import cv2; print(cv2.__version__)"
4.3.0-dev

Conclusion

We have given both of you various approaches to introduce OpenCV on your Ubuntu 20.04 machine. The strategy you pick relies upon your prerequisites and inclinations. Despite the fact that introducing the bundled variant from the Ubuntu vault is simpler, building OpenCV from source gives you greater adaptability, and it ought to be your first choice when introducing OpenCV. 

In the event that you have any inquiries or input, don't hesitate to remark beneath.




CFG