Image Stitching for NVIDIA Jetson - Compiling OpenCV for Image Stitching

From RidgeRun Developer Connection
Jump to: navigation, search



Previous: User Guide/Additional Details Index Next: Examples



Nvidia-preferred-partner-badge-rgb-for-screen.png



Introduction

This guide will help you build OpenCV from source specifically to work with the cudastitcher element. It will guide you through the process of configuring your build according to your needs. As of now, these instructions are for Ubuntu and, in general, Debian-based systems.

Uninstall Current OpenCV Installation

In order to avoid conflicts with existing versions, remove the current installation from your system.

sudo apt purge libopencv-dev libopencv-python libopencv-samples libopencv*

Install Dependencies

These are the basic dependencies you will need.

sudo apt install build-essential cmake git

The following are optional packages you may want to install depending if you are planning to use OpenCV for other things. You will find among those packages libraries to process JPEG, TIFF, PNG, and more, but they are not strictly required for the Image Stitcher.

sudo apt install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev \
python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev python3-pip python3-numpy

Optional GStreamer packages

If you are planning on adding support for GStreamer, you may be interested on the following packages as well, but note they are not required for a basic integration of GStreamer, OpenCV, and the Stitcher Element.

sudo apt install ubuntu-restricted-extras
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

CUDA

If you are planning on adding support for CUDA, make sure you have it installed on your system.

x86
Follow the instructions provided by NVIDIA.
NVIDIA Jetson
We recommend installing CUDA via SDK Manager.

Clone the Project

For the image stitcher to work properly, you need to use a specific version of the RidgeRun OpenCV Fork. RidgeRun's fork also contains some improvements around speed and efficiency.

These commands will avoid downloading the full repo history (which is a lot), so it's faster. If you'd like to keep the history, get rid of the --depth 1.

git clone https://github.com/ridgerun/opencv.git -b add-vector-traits-compare-function --depth 1

Clone the Contrib Extra Modules

If you'd like to install the non-free modules please clone the following project.

git clone https://github.com/RidgeRun/opencv_contrib.git -b feature/add-transparency-to-cudawarp --depth 1

Configure the Project

cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=$(which python2) \
-D BUILD_opencv_python2=OFF \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules/ \
-D WITH_GSTREAMER=ON \
-D WITH_CUDA=ON \
-D PYTHON_DEFAULT_EXECUTABLE=$(which python3) \
 ..

The script will try to detect the architecture. If you'd like to explicitly specify your configuration, set CUDA_ARCH_BIN to one of the following values:

Table 1. Jetson Compute Capabilities related to its architecture (CUDA_ARCH_BIN)
GPU Compute Capability
Jetson AGX Xavier 7.2
Jetson TX2 6.2
Jetson TX1 5.3
Jetson Nano 5.3

Build the Project

This will take some time. Please be patient.

make -j8

Note that on smaller systems (like the Jetson Nano), parallel build may eat up all the memory, resulting in a failed build as the following:

[ 98%] Built target opencv_test_mcc
[ 98%] Built target opencv_test_face
Segmentation fault (core dumped)
CMake Error at cuda_compile_1_generated_pyrlk.cu.o.RELEASE.cmake:281 (message):
  Error generating file
  /home/mgruner/RidgeRun/opencv/build/modules/cudaoptflow/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_pyrlk.cu.o

In such cases try removing the -j8 from the make call and freeing up some space in your FS.

Install the Project

sudo make install
sudo ldconfig

Troubleshooting

Eigen/core

In case of issues with Eigen/core, for example:

opencv/modules/core/include/opencv2/core/private.hpp:66:12: fatal error: Eigen/Core: No such file or directory
 #  include <Eigen/Core>

Disable the precompiled headers from the cmake configuration, and append the next flag:

-DENABLE_PRECOMPILED_HEADERS=OFF \

Make sure that precompiled headers are disabled in the configuration summary.

Out of Space in Jetson Boards

A full OpenCV build can take up to 2GB of space. This is a lot for smaller platforms. Here are some things I usually erase in order to make some space on NVIDIA Jetson boards:

#
# Please double check you actually don't need these before purging
#
sudo apt purge chromium-browser
sudo apt purge thunderbird*
sudo apt purge libreoffice*

# If you're not planning on using docker
sudo apt purge docker*


RidgeRun Resources

Quick Start Client Engagement Process RidgeRun Blog Homepage
Technical and Sales Support RidgeRun Online Store RidgeRun Videos Contact Us

OOjs UI icon message-progressive.svg Contact Us

Visit our Main Website for the RidgeRun Products and Online Store. RidgeRun Engineering informations are available in RidgeRun Professional Services, RidgeRun Subscription Model and Client Engagement Process wiki pages. Please email to support@ridgerun.com for technical questions and contactus@ridgerun.com for other queries. Contact details for sponsoring the RidgeRun GStreamer projects are available in Sponsor Projects page. Ridgerun-logo.svg
RR Contact Us.png


Previous: User Guide/Additional Details Index Next: Examples