Skip to content
Viking Drone
  • Home
  • Vali
  • About
  • Contact
  • News
  • Toggle website search
Menu Close
  • Home
  • Vali
  • About
  • Contact
  • News
  • Toggle website search

Installing OpenCV 4.5.2

Helpdesk      Getting Started      Installing OpenCV 4.5.2
Password Protected

Nope
Yep, that's right!
Development Board
Getting Started
Remote Dektop using X2GO
Installing OpenCV 4.5.2
Using Ubuntu 20.04
Upgrading NVIDIA Jetson Xavier NX to Ubuntu 20.04

Installing OpenCV 4.5.2

The NVIDIA Jetson Xavier NX computer ships with a version of OpenCV that does not use the GPU. This means that the computer does not use some of its features like cuDNN for Neural Network algorithms. To enable CUDA and full GPU support, OpenCV can be build from source.

Pre-installation

Remove the old version of OpenCV.

$ sudo apt-get purge *libopencv*

Update all packages.

$ sudo apt-get update
$ sudo apt-get upgrade

Make sure CUDA can be found.

$ sudo sh -c "echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/nvidia-tegra.conf"
$ sudo ldconfig

Install all thrid party libraries that OpenCV depends on.

$ sudo apt-get install build-essential cmake git unzip pkg-config
$ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install libgtk2.0-dev libcanberra-gtk*
$ sudo apt-get install python3-dev python3-numpy python3-pip
$ sudo apt-get install libxvidcore-dev libx264-dev libgtk-3-dev
$ sudo apt-get install libtbb2 libtbb-dev libdc1394-22-dev
$ sudo apt-get install libv4l-dev v4l-utils
$ sudo apt-get install libavresample-dev libvorbis-dev libxine2-dev
$ sudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev
$ sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev
$ sudo apt-get install libopenblas-dev libatlas-base-dev libblas-dev
$ sudo apt-get install liblapack-dev libeigen3-dev gfortran
$ sudo apt-get install libhdf5-dev protobuf-compiler
$ sudo apt-get install libprotobuf-dev libgoogle-glog-dev libgflags-dev

Download OpenCV

Download OpenCV 4.5.2 from Github.

$ cd ~
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.2.zip
$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.2.zip

Unzip the folders, rename them and clean up the zipped folders.

$ unzip opencv.zip
$ unzip opencv_contrib.zip
$ mv opencv-4.5.2 opencv
$ mv opencv_contrib-4.5.2 opencv_contrib
$ rm opencv.zip
$ rm opencv_contrib.zip

Build OpenCV

Create the building directory.

$ cd ~/opencv
$ mkdir build
$ cd build

Configure CMake to build OpenCV the way you want it. These flags can be changed to adapt the installation to your needs.

$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
-D WITH_OPENCL=OFF \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN=5.3 \
-D CUDA_ARCH_PTX="" \
-D WITH_CUDNN=ON \
-D WITH_CUBLAS=ON \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_NEON=ON \
-D WITH_QT=OFF \
-D WITH_OPENMP=ON \
-D WITH_OPENGL=ON \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D BUILD_opencv_python3=TRUE \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D CMAKE_C_COMPILER=/usr/bin/gcc-7 \
-D BUILD_EXAMPLES=OFF ..

If the configuration went well, you should see a report and a message that the configuration is done. You are now ready to build OpenCV.

$ make -j$(nproc)

This step will take one to two hours and might sometimes look frozen. Do not stop the process before the build is 100% completed and you see the prompt back. Now you can install the libraries that you just built and remove the build folders.

$ sudo make install
$ sudo ldconfig
$ make clean
$ sudo rm -rf ~/opencv
$ sudo rm -rf ~/opencv_contrib

You should now have OpenCV 4.5.2 installed on you companion computer. To test that your installation, you can use Python.

$ python3
>>>import cv2
>>>cv2.__version__
>>>exit()
Facebook Twitter Linkedin Youtube

© Viking Drone 2020

Viking Drone 2021
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Cookie settingsACCEPT
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT