In the previous section, Linux-ZED SDK docker images along with OpenCV and ROS support were discussed. Here, we learn to run and build ZED-SDK with OpenCV and ROS docker images for NVIDIA® Jetson.

Creating the image and using OpenCV or ROS in Docker is very much similar to that discussed earlier. The difference here would be that the Docker images are created for NVIDIA® Jetson platforms and hence the parent image also changes to the one that is built for the same platform.

Running OpenCV and ROS sample applications will be entirely the same as running them on desktop-based images hence this tutorial only discusses creating Docker images using Dockerfile and build scripts

Before you go ahead and try creating the Docker images we suggest you go through an earlier tutorial that explains Running and Building ARM Docker Containers on x86.

Creating Docker Image for NVIDIA® Jetson with OpenCV #

Similar to the Linux images Dockerfile and build-opencv-jetson-image.sh scripts are provided here.

# Build arguments
ARG ZED_SDK_MAJOR
ARG ZED_SDK_MINOR
ARG L4T_MINOR_VERSION

# Specify the parent image from which we build
FROM stereolabs/zed:${ZED_SDK_MAJOR}.${ZED_SDK_MINOR}-devel-l4t-r32.${L4T_MINOR_VERSION}

ARG OPENCV_VERSION 

The parent images are based on the NVIDIA® l4t-base container with the ZED SDK library and dependencies installed. The official ZED SDK Docker images for NVIDIA® Jetson are located in Stereolabs DockerHub repository.

Build Script #

Building scripts for NVIDIA® Jetson is simpler. build-opencv-jetson-image.sh configures the build arguments and runs the docker build command by assigning the default image tag.

#!/bin/bash
set -e

# This is a shell script that configures the build arguments to the Dockerfile
# and builds a Docker image for NVIDIA® Jetson  with a default tag. 

#Build Arguments
ZED_SDK_MAJOR=3 		# ZED SDK major version 
ZED_SDK_MINOR=7			# ZED SDK minor version
L4T_MINOR_VERSION=7 	#L4T Minor version
OPENCV_VERSION=4.5.3	#OpenCV Version


# Default Tag based on the selected versions
TAG="${ZED_SDK_MAJOR}.${ZED_SDK_MINOR}-opencv-tools-devel-l4t-r32.${L4T_MINOR_VERSION}"          
           
echo "Building '${TAG}'" 

docker build --build-arg 4T_MINOR_VERSION=${L4T_MINOR_VERSION} \
		     --build-arg ZED_SDK_MAJOR=${ZED_SDK_MAJOR} \
			 --build-arg ZED_SDK_MINOR=${ZED_SDK_MINOR} \
			 --build-arg OPENCV_VERSION=${OPENCV_VERSION} \
			 -t "${TAG}" -f Dockerilfe.opencvjetson .

Build and Run your Docker Image #

After configuring the build arguments run the script to build the docker image.

./build-opencv-jetson-image.sh
docker run --gpus all -it --privileged <container tag>

That’s it! You can install zed-opencv sample to test your image.

Creating Docker Image for NVIDIA® Jetson with ROS #

The files can be downloaded from here, Instead of choosing the OpenCV version ROS_DISTRO is chosen. Since the OS on NVIDIA® Jetson boards is based on Ubuntu 18.04, melodic would be the preferred distro and build-ros-jetson-image.sh script creates a Docker image with configured SDK version and L4T_MINOR_VERSION. Below you can find corresponding sections of Dockerfile.rosjetson and build-ros-jetson-image.sh script

ARG ZED_SDK_MAJOR
ARG ZED_SDK_MINOR
ARG L4T_MINOR_VERSION
ARG ROS_DISTRO_ARG

# Specify the parent image from which we build
FROM stereolabs/zed:${ZED_SDK_MAJOR}.${ZED_SDK_MINOR}-devel-l4t-r32.${L4T_MINOR_VERSION} 
#!/bin/bash
set -e

# This is a shell script that configures the build arguments to the Dockerfile
# and builds a Docker image for Jetson  with a default tag. 


ZED_SDK_MAJOR=3 		 # ZED SDK major version 
ZED_SDK_MINOR=7			 # ZED SDK minor version
L4T_MINOR_VERSION=7 	 #L4T Minor version
ROS_DISTRO_ARG="melodic" # ROS DISTRO 



# Default Tag based on the selected versions

TAG="${ZED_SDK_MAJOR}.${ZED_SDK_MINOR}-ros-tools-devel-l4t-r32.${L4T_MINOR_VERSION}" 
                   

echo "Building '${TAG}'" 

docker build --build-arg 4T_MINOR_VERSION=${L4T_MINOR_VERSION} \
		     --build-arg ZED_SDK_MAJOR=${ZED_SDK_MAJOR} \
			 --build-arg ZED_SDK_MINOR=${ZED_SDK_MINOR} \
			 --build-arg ROS_DISTRO_ARG=${ROS_DISTRO_ARG} \
			 -t "${TAG}" -f Dockerilfe.rosjetson .

Build and Run your Docker Image #

After configuring the build arguments run the script to build the docker image.

./build-ros-jetson-image.sh
docker run --gpus all -it --privileged <container tag>

Make sure you follow best practices while creating your image, a few of the best practices are discussed earlier

Note: Although l4t-base containers include OpenGL support it can be tricky to use it with display support, hence we suggest you run the containers without display support.