Developing on NVIDIA® Jetson™ for AI on the Edge

Packaging OpenCV with CUDA for Jetson

It takes several hours to build OpenCV with CUDA support on a NVIDIA Jetson. In the normal build process, the finished library is installed on the build machine. But what if you want to install it on another machine also? The make build system for OpenCV has a package option! Looky here:

Tips and Tricks

Building the package for OpenCV is pretty simple. Go to the build directory and then make the package. In the video, we’re using a Jetson Nano, but this works with any Jetson. Assuming that you were following the previous articles and have just finished your build, the commands will look like this:

$ cd /tmp/build_opencv/opencv/build

$ make package

The make build system will run, and produce a shell script for installation, along with a couple of compressed .tar files both of which contain only the OpenCV libraries and associated files. The file names will start with ‘OpenCV-‘. Copy those files somewhere that you can share with other machines. Typically I use a USB SSD for the task.

Saving the Build

Because the build system uses make, it’s important to keep the timestamps intact when copying the build artifacts. If you do not, then make will rebuild the entire system because it thinks the source files have been updated.

When you copy files using the file manager GUI, the default is to keep the same timestamps on the copied files. However, if you use the command line ‘cp‘ command, the timestamps are updated to reflect when the files were copied. In order to prevent this, use the preserve flag. For example, to copy the folder build_opencv :

$ cp -r –preserve=timestamps build_opencv /path/to/destination

It’s source to destination. The -r means copy everything including subdirectories. Use the preserve flag whenever copying build artifacts.


Installing the new package is straightforward. Copy the OpenCV script file to your home directory, then run the script. For example:

$ ./ –prefix=/usr/local

This will install the OpenCV library into /usr/local because of the ‘prefix‘ flag. Default installation is into the current directory. Some people will install into .local in the home directory if they want only the current user to have access.

Missing Dependencies

Unfortunately some of the runtime libraries are missing after the install. When packaging, the development libraries are used. However, when installed on a new system these libraries have not been installed. The runtime libraries are not as extensive as the ones needed for development.

The video goes over how to find the dependencies using the ‘ldd’ and ‘apt-file’ utilities. The following ldd command finds the files that the dynamic linker cannot find, and apt-file attempts to locate which package holds them in the apt repository.

$ ldd | grep found

$ apt-file search libtesseract

You will need to install apt-file and update it’s index before use:

$ sudo apt install apt-file

$ sudo apt-file update

The libtesseract and libcblas libraries are not present in the default system. In order to install them:

$ sudo apt install libtesseract4

$ sudo apt install libatlas3-base

Once these libraries are installed, you are ready to enjoy OpenCV goodness! If you’re using Python to import cv2, then make sure to set the PYTHONPATH to match your install spot.


4 Responses

  1. Build opencv takes long time and I got error at 98%, I’m very sad.

    Could you share package so I can install without compile. Thanks

  2. Once you’ll have built opencv with CUDA support, you may want to use it 😉
    A way to leverage Jetson HW with many open source SW is from gstreamer
    You may see:
    Currently, only EGL pitch format is supported for RGBA, I420 and NV12. Block linear or other memory buffer types than NVBUF_MEM_SURFACE_ARRAY are unsupported.
    Though, it may be enough or a good starting point for trying most cases with Jetsons.
    Hope it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *


Some links here are affiliate links. If you purchase through these links I will receive a small commission at no additional cost to you. As an Amazon Associate, I earn from qualifying purchases.

Books, Ideas & Other Curiosities