Build OpenCV on the NVIDIA Jetson TX2

Note: This article has been updated for L4T 28.2. Please see Build OpenCV 3.4 with CUDA on NVIDIA Jetson TX2

As a developer, sometimes you need to build OpenCV from source to get the configuration desired. There is a script on the JetsonHacks Github account to help in the process. Looky here:


JetPack can install a CPU and GPU accelerated version of the OpenCV libraries, called OpenCV4Tegra, on the Jetson. OpenCV4Tegra is version 2.4.13 as of this writing. This is great for many applications, especially when you are writing your own apps. However, some libraries require different modules and such that require upstream OpenCV versions.


The community has gathered the recipe(s) for building OpenCV for version later than OpenCV 3.0. There is a repository on the JetsonHacks Github account which contains a build script to help in the process.

To download the source and build OpenCV:

$ git clone
$ cd buildOpenCVTX2
$ ./

Once finished building, you are ready to install.

As explained in the video, navigate to the build directory to install the newly built libraries:

$ cd ~/opencv/build
$ sudo make install

Once you have generated the build files, you can use the ccmake tool to examine the different options and modules available.

Remember to setup you OpenCV library paths correctly.


  • 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 OpenCV4Tegra and the source built OpenCV on their system. Some people have noted success using both however, check the forums.
  • Sometimes the make tool does not build everything. Experience dictates to go back to the build directory and run make again, just to be sure
  • Different modules and setting may require different dependencies, make sure to look for error messages when building.
  • After building, you should run the tests. The build script includes the testing options. All tests may not pass.
  • The build script adds support for Python 2.7
  • The compiler assumes that the Jetson TX2 aarch64 (ARMv8) architecture is NEON enabled, therefore you do not have to enable the NEON flag for the build

The information for this script was gathered from several places:


  1. Can you please compare performance of OpenCV 2.4.13 and 3.2 on some typical image operations? Will UMat from 3.2 do automatically the same thing as fast as cuda:: 2.4 methods and do it asynchronous?

  2. Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package libavcodec-dev
    E: Unable to locate package libavformat-dev
    E: Unable to locate package libavutil-dev
    E: Unable to locate package libpostproc-dev
    E: Unable to locate package libswscale-dev
    E: Unable to locate package libeigen3-dev
    E: Unable to locate package libtbb-dev
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package python-py
    E: Unable to locate package python-pytest

    what is it?
    the latest version of the jetpack has been fully installed.

  3. Does the own compiled version of cv2 (mostly for on-board camera) confilcts with the cv2 module in ROS package?
    Or can I just don’t source the ros’s cv when I’m using the custom version of cv?


    • I believe that the ROS package just blindly installs its own version of OpenCV, ignoring what’s already on the Jetson. I know that people have worked on solutions to this, but I don’t have one at the moment. Thanks for reading!

  4. Could you write up a tutorial too on removing either OpenCV or CV4Tegra as you did mention that most would not be using both and using either one instead.

  5. I first installed it with -DBUILD_opencv-python3=OFF. After that, I set -DBUILD_opencv-python3=ON and reinstalled without removing the previous installation. But I can’t import cv2 in python3. Do I need to reinstall after removing the existing one? If so, how do I remove the old one?

Leave a Reply

Your email address will not be published.