Using ZED and OpenCV in a Docker Container
This tutorial shows how to use ZED SDK applications together with the OpenCV library in a Docker container. It gives an overview of using ZED cameras and OpenCV in a container, and demonstrates how to build and run an OpenCV application.
In the next section, you will learn how to create your own Docker image with the ZED SDK and OpenCV. The present tutorial assumes you are already running a container that includes all the required libraries, so we can focus on using OpenCV in Docker.
Download and Run the Docker Image
To build an application with OpenCV, you need to pull and run a Docker image that includes the ZED SDK and OpenCV. If you want to run applications with display windows, make sure your container also supports OpenGL (a gl-devel image).
--gpus allexposes all available GPUs to the container (use--runtime nvidiaon NVIDIA® Jetson™).--privilegedgrants the container access to the camera connected over USB.-e NVIDIA_DRIVER_CAPABILITIES=allenables the graphics capabilities required by OpenGL.-v /tmp/.X11-unix:/tmp/.X11-unixlets the container access the display.-e DISPLAYmakes yourDISPLAYenvironment variable available inside the container.-v /dev:/devshares the video devices with the container.
For more details on docker run and its options, see the Docker run reference.
Run a Sample OpenCV Application
Once a container is running, you are ready to get started. The zed-opencv sample is a great starting point.
The sample performs the following tasks:
- Sets several parameters: depth sensing mode, image resolution, and units.
- Captures image, depth, and point cloud data from the ZED.
- Converts the image and depth map to compatible 32-bit float OpenCV matrices.
- Displays the video and depth with OpenCV.
- Saves side-by-side images, depth images, and point clouds in various formats.
For a detailed explanation of the code, refer to the ZED OpenCV documentation.
Clone the zed-opencv sample from GitHub (https://github.com/stereolabs/zed-opencv):
Compile the Code and Run the Application
Build the C++ code and run the application:
Congratulations! You have built your first ZED + OpenCV application using Docker.
You can now build other examples that use OpenCV in the same way. Program-specific explanations and build instructions can be found in their respective GitHub repositories.

