How to Use NVIDIA OpenCV Python Bindings on Jetson Boards

From RidgeRun Developer Wiki




Introduction

NVIDIA provides a custom OpenCV installation for the Jetson family of boards. This installation is deployed by Jetpack and comes in the form of DPKG packages (this means you use apt-get to interact with them). It is very easy to accidentally override this installation with other packages.

This wiki shows how to recover the original Jetpack installation of OpenCV Python bindings.

Different Repositories

If you check the OpenCV package provided by APT you'll see that it is provided by NVIDIA:

$ apt show libopencv
Package: libopencv
Version: 4.1.1-2-gd5a58aa75
Priority: optional
Section: libs
Maintainer: admin@opencv.org
Installed-Size: 56,0 MB
Provides: opencv-data, libopencv-calib3d4.0, libopencv-core4.0, libopencv-features2d4.0, libopencv-flann4.0, libopencv-highgui4.0,
...
Homepage: http://opencv.org
Download-Size: 9 921 kB
APT-Manual-Installed: yes
APT-Sources: https://repo.download.nvidia.com/jetson/common r32/main arm64 Packages
Description: Open Computer Vision Library

There are, however, at least 3 different ways to install the Python bindings:

APT libopencv-python (you want this one)

This one is the one provided by NVIDIA, and likely the one you want to use:

$ apt show libopencv-python
Package: libopencv-python
...
APT-Sources: https://repo.download.nvidia.com/jetson/common r32/main arm64 Packages
Description: Python bindings for Open Source Computer Vision Library

APT python-opencv

This one can be installed by using apt, but are NOT provided by NVIDIA:

$ apt show python-opencv
Package: python-opencv
...
APT-Sources: http://ports.ubuntu.com/ubuntu-ports bionic-updates/universe arm64 Packages
Description: Python bindings for the computer vision library
...

PIP opencv-python

This one is the unofficial Python bindings available through PyPi. Again, these are NOT provided by NVIDIA.

Recovering the Original Installation

Knowing the different repositories providing OpenCV Python bindings, the recovery becomes as the following:

# Remove PIP3 installation, if any
pip3 uninstall opencv-python

# Remove APT Ubuntu Bindings, if any
sudo apt purge python-opencv

# Reinstall APT NVIDIA bindings
sudo apt install --reinstall libopencv libopencv-python

Validating

Now you can test the installation by running the following:

#!/usr/bin/env python3

import cv2
availableBackends = [cv2.videoio_registry.getBackendName(b) for b in cv2.videoio_registry.getBackends()]
print(availableBackends)

Which produces:

$ python3 ./app.py
['FFMPEG', 'GSTREAMER', 'INTEL_MFX', 'V4L2', 'CV_IMAGES', 'CV_MJPEG']

Further Support

If you need further support, you may contact us

Contact Us



For direct inquiries, please refer to the contact information available on our Contact page. Alternatively, you may complete and submit the form provided at the same link. We will respond to your request at our earliest opportunity.


Links to RidgeRun Resources and RidgeRun Artificial Intelligence Solutions can be found in the footer below.