> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.stereolabs.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.stereolabs.com/_mcp/server.

# Using ZED and OpenCV in a Docker Container

This tutorial shows how to use ZED SDK applications together with the [OpenCV](https://opencv.org/) 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](/docs/integrations/docker/create-an-open-cv-docker-image), 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).

```bash
docker pull <container_tag>  # pull a container with ZED SDK, OpenCV, and OpenGL support
xhost +si:localuser:root     # allow the container to communicate with the X server
# On a desktop host:
docker run -it --gpus all --privileged -e NVIDIA_DRIVER_CAPABILITIES=all -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev:/dev <container_tag>
# On NVIDIA® Jetson™, replace "--gpus all" with "--runtime nvidia"
# Remember: replace <container_tag> with the tag of your container image
```

* `-it` starts an interactive terminal session in the container.
* `--gpus all` exposes all available GPUs to the container (use `--runtime nvidia` on NVIDIA® Jetson™).
* `--privileged` grants the container access to the camera connected over USB.
* `-e NVIDIA_DRIVER_CAPABILITIES=all` enables the graphics capabilities required by OpenGL.
* `-v /tmp/.X11-unix:/tmp/.X11-unix` lets the container access the display.
* `-e DISPLAY` makes your `DISPLAY` environment variable available inside the container.
* `-v /dev:/dev` shares the video devices with the container.

For more details on `docker run` and its options, see the [Docker run reference](https://docs.docker.com/reference/cli/docker/container/run/).

## Run a Sample OpenCV Application

Once a container is running, you are ready to get started. The [zed-opencv](https://github.com/stereolabs/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](/docs/integrations/opencv/).

Clone the `zed-opencv` sample from GitHub ([https://github.com/stereolabs/zed-opencv](https://github.com/stereolabs/zed-opencv)):

```bash
git clone https://github.com/stereolabs/zed-opencv.git
```

### Compile the Code and Run the Application

Build the C++ code and run the application:

```bash
cd zed-opencv/cpp
mkdir build && cd build
cmake ..
make
./ZED_with_OpenCV
```

Congratulations! You have built your first ZED + OpenCV application using Docker.

You can now build other [examples](https://github.com/stereolabs/zed-sdk) that use OpenCV in the same way. Program-specific explanations and build instructions can be found in their respective [GitHub repositories](https://github.com/stereolabs).