Build OpenCV on the NVIDIA Jetson TX1

With the deprecation of OpenCV4Tegra in L4T 28.1, developers may want to build OpenCV from source for their applications. There is a script on the JetsonHacks Github account to help in the process. Looky here:

Background

For some applications it makes sense to build OpenCV from source. OpenCV is a rich environment with many options. For example, the OpenCV libraries in the Ubuntu repositories currently do not include GPU acceleration for aarch64 machines. For the Jetson, with its built in GPU, it makes sense to build GPU support into the OpenCV library.

An earlier NVIDIA supplied version of OpenCV4Tegra provided a variety of optimizations for the OpenCV library. Over the course of the last couple of years these optimizations have migrated upstream. That means that the optimizations are now available in the public OpenCV library.

Installation

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 https://github.com/jetsonhacks/buildOpenCVTX1.git
$ cd buildOpenCVTX1
$ ./buildOpenCV.sh

Once finished building, you are ready to install.

Navigate to the build directory to install the newly built libraries:

$ cd ~/opencv/build

Note: As discussed in the video, due to the nature of the multi-processor make process, some files may not be compiled. It’s a good idea to run make again after switching to the build directory:

$ make

This takes an extra few minutes, but will round up any stragglers and save headaches down the road.

Now install:

$ 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 your OpenCV library paths correctly after installation.

Notes

  • This is meant to be a template for building your own custom version of OpenCV, pick and choose your own modules and options
  • The Jetson TX1 in the video is running L4T 28.1, OpenCV 3.3 is the version being built.
  • In the script, GStreamer support has been enabled. However there are issues using the Jetson TX1 onboard camera with it. The issue is discussed here: NVIDIA Jetson TX1 Forum – L4T 28.1 Onboard Camera Error. As of this writing (9/5/2017), I have been unable to get this working.
  • 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 TX1 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:

10 Comments

  1. Thank you very much for the tutorial, I have not installed 3.3, when I installed opencv3.3 need to uninstall 2.4(OpenCV for Tegra)? Also, the camera at the end of this tutorial questions still exist?

  2. Thank you very much.
    When compiling openCV 3.3 my TX1 you run out of memory. I then inserted an SD cart and select it as install directory.
    Now when compiling code from the Host with Nsight, even if the compiler and the linker are able to found libraries in the SD they are not able to execute the code telling that the .so does not exist or is no reachable. Any clues?

  3. Thank you very much for the tutorial. I tried install opencv 3.3 with jetpack 2.3.1 but don’t could.Now installed the jetpack 3.1 and openCV 3.3 without problems! thanks!

  4. HI
    Thank you very much for the nice tutorial…

    sorry for asking a trivial question..

    you write:
    Remember to setup your OpenCV library paths correctly after installation.

    how would i do that ?

    • The OpenCV library paths are environment variables in your particular development tree to tell compilers and such where to look for the OpenCV libraries. Since these variables depend on your particular development environment and library paths, it is beyond the scope of what can described here. Generally, if you
      $ echo $PATH
      you will see the existing paths to system libraries.

Leave a Reply

Your email address will not be published.


*