Build OpenCV 3.4 on NVIDIA Jetson AGX Xavier Developer Kit

In order to get access to cameras using OpenCV on the NVIDIA Jetson AGX Xavier, you need to build the library from source. Looky here:


Using JetPack 4.1, you may install OpenCV as an option. However, that particular version of OpenCV does not support CUDA or camera input.

What to do? Build it yourself of course!

Fortunately we have some convenience scripts to help with that task in the JetsonHacks repository buildOpenCVXavier on Github.


You should note that OpenCV is a rich environment, and can be custom tailored to your needs. As such, some of the more common options are in the build command, but are not comprehensive. Modify the options to suit your needs.

Library location

With this script release, the script now installs OpenCV in /usr/local. Earlier versions of this script installed in /usr. You may have to set your include and libraries and/or PYTHONPATH to point to the new version. See the Examples folder. Alternatively, you may want to change the script to install into the /usr directory.

All of this may lead to a conflict. You may consider removing OpenCV installed by JetPack before performing this script installation:

$ sudo apt-get purge libopencv*


Make sure to read through the install script. In the script, here are some of the options that were included:

  • CUDA
  • Fast Math (cuBLAS)
  • OpenGL
  • GStreamer 1.0
  • Video 4 Linux (V4L)
  • Python 2.7 and Python 3.5 support
  • TBB (Threading Build Blocks)

Build and Install

To download the source, build and install OpenCV:

$ git clone
$ cd buildOpenCVXavier
$ git checkout v1.0
$ ./

Note: You can also use, which will build .deb installers for your OpenCV configuration. This is useful when you want to build OpenCV once, and then have it available for other installations.

Another Note: Check out the README file for instructions on how to set where the scripts download and build the OpenCV source. You can also query the scripts using the –help command line flag.

You can remove the sources and build files after you are done:

$ ./

This will remove the OpenCV source, as well as the opencv_extras directories.


There are a couple of demos in the Examples folder.

There are two example programs here. Both programs require OpenCV to be installed with GStreamer support enabled. Both of these examples were last tested with L4T 31.0.2, OpenCV 3.4.3

The first is a simple C++ program to view the onboard camera feed from the Jetson Dev Kit.

To compile gstreamer_view.cpp:

$ g++ -o gstreamer_view -Wall -std=c++11 gstreamer_view.cpp $(pkg-config –libs opencv)

to run the program:

$ ./gstreamer_view

The second is a Python program that reads the onboard camera feed from the Jetson Dev Kit and does Canny Edge Detection.

To run the Canny detection demo (Python 2.7):

$ python

With Python 3.3:

$ python3

With the Canny detection demo, use the less than (<) and greater than (>) to adjust the edge detection parameters. You can pass the command line flags —video_device=<videoDeviceNumber> to use a USB camera instead of the built in camera.


  • This is meant to be a template for building your own custom version of OpenCV, pick and choose your own modules and options
  • Most people do NOT have both the JetPack installed and the source built OpenCV on their system. Some people have noted success using both however, check the forums.
  • Different modules and setting may require different dependencies, make sure to look for error messages when building.
  • In the video, there are two cameras. One is a camera from a Jetson TX1 Development Kit plugged in to the AGX Xavier camera port (located on the underside of the carrier board). The second camera is a Logitech C920 webcam connected via USB.


    • There are two cameras. One is a camera from a Jetson TX1 Development Kit, plugged in to the AGX Xavier camera port (located on the underside of the carrier board). The second camera is a Logitech C920 webcam connected via USB. Thanks for reading!

  1. I found that with this installation openCV would not work in Python 3. To fix this I had to run: `sudo apt install python3-opencv` after above installation was complete.

    Furthermore, cv2 would still not work in a virtual environment. To fix this I had to create a symbolic link to the main python env cv2 file:
    `ln -s /usr/lib/python3/dist-packages/ .venv/lib/python3.6/site-packages/`

    • Disregard my previous comment re: installing opencv for python3. Running `sudo apt install python3-opencv` will not install gstreamer.

      The correct way to install for python 3 requires adding the following option for cmake in line 161:
      `-D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 \`

      Then create a link to cv2 if using a virtual env:
      `ln /usr/local/lib/python3.6/site-packages/ .venv/lib/python3.6/site-packages/`

Leave a Reply

Your email address will not be published.