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/`

  2. I encountered problems on Jetpack 4.2.1
    The with that version my camera is really slow..
    I have also build opencv 4.1.1 without problem while compiling or installation,
    but sadly the camera was also really slow..

    Any one have experience with that?
    Thanks in advance

  3. I had a problem with a circular link to
    The build failed at about 30% because it could not find
    Worse than that when I rebooted, the GUI could not put up window boarders or move windows.
    I am not sure if I overwrote the actual or if the script did. I recovered by getting the file from
    I had to replace it while the build was in progress.

  4. I grow tired of trying 50 times now. Can someone please share how to use this with Python 3.7 ?
    python points to 3.7
    python3 points to 3.6
    added `-D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3.7 \`

    Still doesn’t work. Been at this for 3 days now….

    Any help would be much appriciated

    • Not sure what issue you are encountering from your description. My understanding is that python should point to where your version 2.X is, and python3 should point to where your Python 3.X is located. So something like python points to Python 2.7 and python 3 would point to Python 3.7.

  5. Okay I used sudo update-alternatives –config python and sudo update-alternatives –config python3

    python -V = 2.7
    python3 -V = 3.7

    I removed the old opencv folder it had build on the SSD and ran the build again.After that it started working, much thanks!

  6. fatal error: opencv2/xfeatures2d/cuda.hpp: No such file or directory
    #include “opencv2/xfeatures2d/cuda.hpp”
    Hi, I’m getting this message. how do I add sift-surf libraries?

  7. thanx for your great posts..
    I’m working with the JetPack 4.3 on jetson Nano with OpenCV cv2 verison 4.1.1. Unfortunately gstream is not working with my raspy 2 cam on Jetson Nano. Any ideas?

    • It is difficult to diagnose your issue with the information provided. Do you have a Gstreamer pipeline that you are using? Did you compile OpenCV with Gstreamer on?

  8. How can we install OpenCV inside a docker container so that we don’t have to do it everytime we want to use a different Xavier?

  9. Trying this installation at a Xavier NX.

    Get this error when trying to run the compiled code

    ./gstreamer_view: error while loading shared libraries: cannot open shared object file: No such file or directory

  10. Thank you for your posts and videos.

    I am trying to run this on an Xavier board running Jetpack 4.3. Without changing anything in the installation script, I was getting errors about some packages being deprecated (not too suprised). OpenCV 4.1.1 was the one installed with Jetpack 4.3. I tried changing OPENCV_VERSION to 4.1.1 and am getting errors.

    Do you have any advice on how to change the script?

Leave a Reply

Your email address will not be published.