Tutorial - Using 3D Object Detection
This tutorial shows how to enable the AI-based Object Detection module to detect, classify and localize objects in 3D space, with a runtime-adjustable confidence threshold. Detection and localization work with both a static and a moving camera. This module requires a stereo camera with an integrated IMU (ZED 2/2i, ZED Mini, or ZED X family); the original ZED is not supported.
Getting Started
- First, download the latest version of the ZED SDK.
- Download the Object Detection sample code in C, C++, Python or C#.
Code Overview
Open the camera
In this tutorial, we will use the Object Detection AI module of the ZED SDK. As in previous tutorials, we create, configure and open the camera.
Enable 3D Object detection
Before enabling object detection, we specify the ObjectDetectionParameters of the module. In this tutorial, we use the following settings:
enable_trackingallows objects to be tracked across frames and keep the same ID as long as possible. Positional tracking must be active in order to track objects’ movements independently from camera motion.enable_segmentationoutputs 2D masks over detected objects. Since it requires additional processing, disable this option if not used.
Now let’s enable object detection which will load an AI model. This operation can take a few seconds. The first time the module is used, the model will be optimized for your hardware and this can take up to a few minutes. The model optimization operation is done only once.
Retrieve object data
To retrieve detected objects in an image, use the retrieveObjects() function with an Objects parameter that will store objects’ data.
For each grab call, the image is fed into the AI module, which outputs the objects detected in that frame. We also set the object confidence threshold at 40: detections with a lower confidence are discarded. Raise it to keep only the most confident detections.
Disable modules and exit
Before exiting the application, modules need to be disabled and the camera closed.
zed.close() can also disable properly all active modules. The close() function is also called automatically by the destructor if necessary.
And this is it!

