Installing OpenCV3.3 on the Jetson TX2

From RidgeRun Developer Wiki




Introduction

The main goal of this wiki is to provide a guide for the installation of OpenCV3.3 on the Jetson TX2 board. This guide gives the commands to follow to install opencv and its required packages

Uninstall OpenCV4Tegra

Uninstall OpenCV for Tegra packages, purge local repositories, and update the apt cache using the following commands:

sudo apt-get purge libopencv4tegra-dev libopencv4tegra
sudo apt-get purge libopencv4tegra-repo
sudo apt-get update

Required Packages

Base requirements

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

GStreamer support (recommended)

This is required for using the onboard camera

sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

Python Support

sudo apt-get install python2.7-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

OpenGL Support

sudo apt-get install libgtkglext1 libgtkglext1-dev
sudo apt-get install qtbase5-dev

video4linux2 support (better handling of usb cameras modes)

sudo apt-get install libv4l-dev v4l-utils qv4l2 v4l2ucp

Installing OpenCV 3.3

Downloading Sources

Version previous to 3.3 don't provide correct support for CUDA in the board

wget --no-check-certificate -O OpenCV-3.3.0.zip https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/3.3.0/opencv-3.3.0.zip/download
unzip OpenCV-3.3.0.zip
cd opencv-3.3.0

Compiling

mkdir build
cd build
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="6.2" -D CUDA_ARCH_PTX="" -D WITH_LIBV4L=ON -D CMAKE_BUILD_TYPE=RELEASE -D WITH_LIBV4L=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D WITH_GSTREAMER=ON -D WITH_CUBLAS=1 -D WITH_TBB=ON -D WITH_OPENGL=ON -D CMAKE_INSTALL_PREFIX=/usr/local ..

Installing

make -j6
sudo make install

Applying Patch

If you find the following mistake while running the make command:

/usr/local/cuda-8.0/include/cuda_gl_interop.h:64:2: error: #error Please include the appropriate gl headers before including cuda_gl_interop.h
#error Please include the appropriate gl headers before including cuda_gl_interop.h

The following patch must be applied to the /usr/local/cuda-8.0/include/cuda_gl_interop.h file:

diff --git a/cuda_gl_interop.h b/cuda_gl_interop.h
index 0f4aa17..e8c538c 100644
--- a/cuda_gl_interop.h
+++ b/cuda_gl_interop.h
@@ -59,13 +59,13 @@
 
 #else /* __APPLE__ */
 
-#if defined(__arm__) || defined(__aarch64__)
-#ifndef GL_VERSION
-#error Please include the appropriate gl headers before including cuda_gl_interop.h
-#endif
-#else
+//#if defined(__arm__) || defined(__aarch64__)
+//#ifndef GL_VERSION
+//#error Please include the appropriate gl headers before including cuda_gl_interop.h
+//#endif
+//#else
 #include <GL/gl.h>
-#endif
+//#endif
 
 #endif /* __APPLE__ */

In order to apply the patch copy the code on a file named cuda.patch an locate this file on the directory where the cuda_gl_interop.h file is located and run the following command:

patch < cuda.patch

The following command might also be necessary:

cd /usr/lib/aarch64-linux-gnu/
sudo ln -sf tegra/libGL.so libGL.so

Articles related



For direct inquiries, please refer to the contact information available on our Contact page. Alternatively, you may complete and submit the form provided at the same link. We will respond to your request at our earliest opportunity.


Links to RidgeRun Resources and RidgeRun Artificial Intelligence Solutions can be found in the footer below.