Skip to navigation

Frame Rate and Latency

Set the camera grab rate, avoid dropped frames, choose between read() and grab(), and minimize the glass-to-glass latency

Open in ClaudeOpen in ChatGPT

The grab rate, set with the camera_fps parameter, is the frame rate at which the camera captures images. The available values depend on the camera model and on the selected resolution, and the grab rate directly affects three aspects of your application:

  • Latency: the capture pipeline has a fixed latency measured in frames, so a higher frame rate reduces the time between the moment a scene is captured and the moment your application receives the image.
  • Image quality: the exposure time cannot exceed the frame period. A higher frame rate allows shorter exposure times, which reduce motion blur on fast-moving scenes.
  • Computation load: by default, the ZED SDK processes every captured frame, so a higher frame rate increases the CPU and GPU load of the host.

This page explains how to:

  • select the grab rate for your camera model,
  • detect and avoid the frames that grab() drops when your application cannot keep up,
  • acquire the frames with read() instead of grab(),
  • combine the highest frame rate with the grab_compute_capping_fps parameter to get the lowest latency without overloading the host.

Available frame rates by camera model

The available frame rates depend on the camera model and on the video mode:

Video modeResolution (per sensor)Frame rates (fps)
HD2K2208x124215
HD10801920x108030, 15
HD7201280x72060, 30, 15
VGA672x376100, 60, 30, 15

A virtual stereo camera built with two ZED X One cameras uses the frame rates of the ZED X One model it is made of.

Set the grab rate

Select the resolution and the frame rate with the camera_resolution and camera_fps initialization parameters, before opening the camera:

sl::Camera zed;
sl::InitParameters init_params;
init_params.camera_resolution = sl::RESOLUTION::HD1200;
init_params.camera_fps = 60;
sl::ERROR_CODE err = zed.open(init_params);
if (err != sl::ERROR_CODE::SUCCESS)
exit(-1);

Keep in mind the following rules:

  • If camera_fps is set to 0, the default value, the ZED SDK uses the highest frame rate available for the selected resolution.
  • If the requested frame rate is not available for the selected resolution, the ZED SDK uses the closest available frame rate.
  • If camera_resolution is left at AUTO, the default value, the ZED SDK selects HD1200 for the ZED X and ZED X Mini, and HD720 for the other cameras.
  • The resolution and the frame rate cannot be changed while the camera is open. Close and reopen the camera to change them.

To check the frame rate actually reached by your application, call getCurrentFPS() (get_current_fps() in Python) while grabbing. It returns the rate at which frames are acquired, computed from the camera timestamps of two consecutive frames. Frames are acquired by grab(), or by read() when your application uses it (see Acquire frames without processing them with read()).

Host limits on the grab rate

The frame rate that your system can sustain can be lower than the maximum frame rate of the camera:

  • USB cameras: the USB 3.0 bandwidth of a controller is shared by all the cameras connected to it. When the bandwidth is exceeded, corrupted frames appear and cameras can disconnect.
  • GMSL2 cameras: each camera uses a dedicated link of the ZED Link capture card or of the ZED Box, but the number of cameras, the resolutions, and the frame rates are limited by the capture card and by the Jetson™ module.
  • Computation: if the processing of each frame (depth, positional tracking, object detection, and so on) takes longer than the frame period, grab() runs slower than camera_fps and frames are dropped, as explained in How grab() delivers frames.

The Multi-Camera page gives hardware recommendations for USB and GMSL2 setups.

How grab() delivers frames

grab() does not keep a queue of the captured frames: each call returns the most recent frame captured by the camera.

  • If your loop is faster than the camera, grab() blocks until the next frame is captured, so every frame is returned once.
  • If your loop is slower than the camera, several frames are captured between two grab() calls. grab() returns the newest one, and the older ones are dropped: they never reach your application.

This keeps the latency as low as possible, but it means that a slow loop silently loses frames. For example, with a camera at 30 fps (a frame every 33 ms) and a loop iteration that takes 50 ms, about one frame in three is dropped.

A dropped frame is also lost for every feature that relies on the acquired frames:

  • SVO recording: only the acquired frames are written to the file. The file holds fewer frames per second than camera_fps, with timestamp gaps where frames were dropped.
  • ZED SDK modules: positional tracking, object detection, body tracking, and spatial mapping only process the grabbed frames.
  • Fusion: a camera that publishes with startPublishing() sends its data from its grab() loop, so the Fusion module receives only the grabbed frames.

The IMU samples are not affected: getSensorsDataBatch() returns all the samples received since the previous frame acquisition, including those received during the dropped frames. With a live camera, the ZED SDK keeps up to 2.5 seconds of IMU samples with the ZED 2 and ZED 2i, and 0.5 seconds with the other cameras: a longer gap between two acquisitions loses the older samples.

When reading an SVO file, grab() returns every frame of the file in order, whatever the speed of your loop, so no frame is dropped during the playback. The only exception is the real-time mode (svo_real_time_mode set to true), which skips frames to follow the recording timing. During playback, getFrameDroppedCount() reports the frames dropped during the recording.

When grab_compute_capping_fps is set, frames are dropped on purpose: grab() skips frames to stay at or below the capping rate. See Reduce the computation load with grab_compute_capping_fps.

Detect dropped frames

There are three ways to detect dropped frames:

  • getFrameDroppedCount() (get_frame_dropped_count() in Python, GetFrameDroppedCount() in C#) returns the number of frames dropped since the first grab(). The frames skipped because of grab_compute_capping_fps are included. The counter can already be non-zero after the first grab(), because it also counts the frames captured before that call, for example while the depth model is loading.
  • getCurrentFPS() (get_current_fps() in Python) returns a value lower than camera_fps when frames are dropped.
  • The difference between the image timestamps of two consecutive grabbed frames is larger than the frame period. A difference of N frame periods means that N - 1 frames were dropped.

The following example checks both the counter and the timestamps after each grab():

const double frame_period_ms = 1000.0 / zed.getCameraInformation().camera_configuration.fps;
unsigned int last_dropped = zed.getFrameDroppedCount();
uint64_t last_ts = 0;
while (true) {
if (zed.grab() != sl::ERROR_CODE::SUCCESS)
continue;
// Frames dropped since the previous grab(), from the counter
unsigned int dropped = zed.getFrameDroppedCount();
if (dropped > last_dropped)
std::cout << dropped - last_dropped << " frame(s) dropped" << std::endl;
last_dropped = dropped;
// Gap between the image timestamps of two consecutive frames
uint64_t ts = zed.getTimestamp(sl::TIME_REFERENCE::IMAGE).getMilliseconds();
if (last_ts > 0 && (ts - last_ts) > 1.5 * frame_period_ms)
std::cout << "Timestamp gap: " << ts - last_ts << " ms" << std::endl;
last_ts = ts;
}

Avoid dropped frames

To make sure that every frame is acquired:

  • Move the heavy processing to another thread. Keep the grab() loop short: grab, retrieve the data you need, copy it, and hand it over to a worker thread. The ZED SDK modules, the SVO recording, and the Fusion publishing then get every frame, even if your own processing runs at a lower rate. When recording, check getFrameDroppedCount() to make sure that the file has the expected frame rate. See the example below.
  • Lower the frame rate to a value that your loop can sustain. A lower camera_fps increases the latency. If the latency matters more than processing every frame, use grab_compute_capping_fps instead, which drops frames on purpose.
  • Reduce the workload of each frame: select a lower resolution, a lighter depth mode, or disable the modules that your application does not need. You can also skip the depth computation of a frame by setting the enable_depth runtime parameter to false.
  • Acquire the frames with read() when only some frames, or none, need the processing of grab(), for example to record or stream. See Acquire frames without processing them with read().

The following example, a complete program in C++ and Python, keeps the grab() loop at the camera frame rate while a worker thread runs 100 ms of processing on the most recent image. The worker skips the images that arrive while it is busy, but grab() itself does not drop any frame:

#include <sl/Camera.hpp>
#include <chrono>
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>
void heavyProcessing(const sl::Mat &img) {
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Stands for 100 ms of processing
}
int main() {
sl::Camera zed;
sl::InitParameters init_params;
init_params.camera_fps = 30;
if (zed.open(init_params) != sl::ERROR_CODE::SUCCESS)
return EXIT_FAILURE;
sl::Mat latest; // Most recent image, shared with the worker
bool has_new = false;
bool running = true;
std::mutex mtx;
std::condition_variable cv;
std::thread worker([&]() {
sl::Mat frame;
while (true) {
{
std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock, [&] { return has_new || !running; });
if (!running)
break;
latest.copyTo(frame); // Take the most recent image
has_new = false;
}
heavyProcessing(frame);
}
});
sl::Mat image;
unsigned int dropped_at_start = 0;
bool first_frame = true;
for (int i = 0; i < 300; i++) {
if (zed.grab() == sl::ERROR_CODE::SUCCESS) {
if (first_frame) { // Ignore the frames dropped before the first grab()
dropped_at_start = zed.getFrameDroppedCount();
first_frame = false;
}
zed.retrieveImage(image, sl::VIEW::LEFT);
{
std::lock_guard<std::mutex> lock(mtx);
image.copyTo(latest); // Copy: image is overwritten by the next grab()
has_new = true;
}
cv.notify_one();
}
}
{
std::lock_guard<std::mutex> lock(mtx);
running = false;
}
cv.notify_one();
worker.join();
std::cout << "Dropped frames: " << zed.getFrameDroppedCount() - dropped_at_start << std::endl;
zed.close();
return EXIT_SUCCESS;
}

Acquire frames without processing them with read()

grab() performs two steps on each frame:

  1. Acquisition: it waits for a new frame and makes the most recent one available, together with its IMU samples.
  2. Processing: it runs the processing enabled in your application, such as depth computation, positional tracking, object detection, body tracking, or spatial mapping.

read() (read() in Python, Read() in C#) performs only the acquisition step. It is available for sl::Camera, and for sl::CameraOne in C++. When grab() is called after read(), it does not acquire a new frame: it processes the frame acquired by read(). When grab() is called without read(), it acquires a new frame first.

Differences between read() and grab()

read()grab()
Waits for a new frame and returns the most recent oneYesYes, unless read() already acquired the frame
Rectified images with retrieveImage()Yes, rectified when retrievedYes
IMU samples with getSensorsDataBatch()YesYes
SVO recording and streaming (ZED SDK 5.4 and later)YesYes
Depth, point cloud, positional tracking, object detection, body tracking, spatial mappingNoYes
Computation costLowDepends on the enabled modules

Both functions follow the same frame delivery rules, described in How grab() delivers frames:

  • The frames dropped by read() are counted by getFrameDroppedCount().
  • getCurrentFPS() reports the acquisition rate: if you call read() on every frame and grab() on only some of them, it returns the read() rate.
  • grab_compute_capping_fps also limits the rate of read().
  • When reading an SVO file, each read() moves to the next frame of the file, and a grab() that follows processes that same frame.
  • The IMU samples returned by getSensorsDataBatch() belong to the last acquired frame. If you call read() twice without reading the batch in between, the samples of the first frame are lost: read the batch after each read().

read() does not update the data computed by grab(). After a read(), retrieveMeasure() and getPosition() still return the depth and the pose computed by the last grab(), but labeled with the timestamp of the frame acquired by read(). Use the measures and the pose only after a grab().

When to use read() instead of grab()

Use grab() alone when your application needs the processing of the ZED SDK on every frame: it is the simplest loop.

Use read() in the following cases:

  • Images at full rate, processing at a lower rate: call read() on every frame to retrieve the images, and grab() only every N frames to compute the depth or the other measures. Your application gets every image, whereas grab_compute_capping_fps would lower the image rate too. The Split Process tutorial shows this pattern.
  • Recording or streaming only: since ZED SDK 5.4, SVO recording and streaming run from read(). A loop that only calls read() records or streams every frame without paying for the depth computation or the image rectification. Before ZED SDK 5.4, a grab() was required to record or stream a frame.
  • Custom depth before the ZED SDK processing: with DEPTH_MODE::CUSTOM, call read(), retrieve the rectified images, compute your own depth map, pass it with ingestCustomDepth(), then call grab() to run the ZED SDK modules on it. See the Custom Depth sample.

The following example retrieves the left image of every frame with read(), and computes the depth every 6 frames with grab():

sl::Mat image, depth;
const int depth_every_n_frames = 6;
for (int i = 0; i < 300; i++) {
// Acquire the most recent frame, without processing it
if (zed.read() != sl::ERROR_CODE::SUCCESS)
continue;
zed.retrieveImage(image, sl::VIEW::LEFT); // Rectified image of every frame
// Process the same frame every 6 frames
if ((i % depth_every_n_frames) == 0 && zed.grab() == sl::ERROR_CODE::SUCCESS) {
zed.retrieveMeasure(depth, sl::MEASURE::DEPTH); // Depth of this frame
}
}

Minimize the glass-to-glass latency

The glass-to-glass latency is the time between the moment a scene is captured by the camera sensor and the moment the corresponding image is displayed or used by your application. The part introduced by the camera and the ZED SDK capture pipeline is fixed when measured in frames:

  • about 2 to 3 frames for GMSL2 cameras,
  • about 3 to 4 frames for USB cameras.

This latency is therefore proportional to the frame period: the higher the grab rate, the lower the latency. To minimize it, set camera_fps to the highest frame rate offered by the selected resolution that your host can sustain, as described in Host limits on the grab rate. If latency matters more than image resolution, also consider a lower resolution with a higher maximum frame rate, for example SVGA at 120 fps on a ZED X.

The following table gives the expected latency of the grab operation at the highest frame rate of each video mode:

Camera modelVideo modeHighest frame rateExpected latency
ZED 2i, ZED 2, ZED MiniVGA100 fps~30 to 40 ms
ZED 2i, ZED 2, ZED MiniHD72060 fps~50 to 67 ms
ZED 2i, ZED 2, ZED MiniHD108030 fps~100 to 133 ms
ZED 2i, ZED 2, ZED MiniHD2K15 fps~200 to 267 ms
ZED X, ZED X Mini, ZED X Nano
ZED X One GS, ZED X One S
SVGA120 fps~17 to 25 ms
ZED X, ZED X Mini, ZED X Nano
ZED X One GS, ZED X One S, ZED X One 4K
HD1200, HD108060 fps~33 to 50 ms
ZED X One 4KHD4K, QHDPLUS15 fps~133 to 200 ms

These values refer to the pure grab operation, that is, the time needed to capture a frame and make it available through grab() or read(). The processing performed by the ZED SDK on each frame, such as image rectification, depth computation, positional tracking, or object detection, adds its own time, which depends on the enabled modules and on the processing power of the host. On a less powerful host, or with heavier settings, the actual latency can therefore be noticeably higher than the values in the table.

The glass-to-glass latency of your system also includes the processing time of your application and, if the images are displayed, the latency of the display pipeline.

A higher frame rate is also useful when the exposure is controlled manually: since the exposure time is expressed as a percentage of the frame period, a higher frame rate allows shorter exposure times and reduces motion blur.

Reduce the computation load with grab_compute_capping_fps

By default, running the camera at its highest frame rate also forces the ZED SDK to process every frame at that rate, which maximizes the CPU and GPU load. If your application does not need to process all the frames, or if the host cannot sustain this load, use the grab_compute_capping_fps initialization parameter.

grab_compute_capping_fps sets an upper limit to the processing rate of grab(), independently of the capture frame rate. It also limits the rate of read():

  • The camera keeps capturing at camera_fps, so the capture pipeline latency stays as low as the camera frame rate allows.
  • grab() always returns the latest available image, so processing at a lower rate does not make the images older: each processed image is the most recent one captured. The frames captured in between are dropped.
  • The ZED SDK modules (image and depth retrieval, positional tracking, object detection, body tracking, and so on) run at most at the capping rate, which reduces the CPU and GPU load.

Unlike camera_fps, the capping value is not limited to the fixed frame rates of the camera: you can set any strictly positive value lower than camera_fps, for example 25.0. Set it to 0 to disable the capping, which is the default behavior.

For example, to capture at 120 fps with a ZED X in SVGA mode for the lowest latency, while processing at most 30 frames per second:

sl::InitParameters init_params;
init_params.camera_resolution = sl::RESOLUTION::SVGA;
init_params.camera_fps = 120; // Highest frame rate: lowest capture latency
init_params.grab_compute_capping_fps = 30; // Process at most 30 frames per second
  • grab_compute_capping_fps is an upper limit: it has no effect if the processing is already slower than the capping value.
  • It has no effect when reading an SVO file. Since ZED SDK 5.6, it also applies to stream inputs, where it previously had no effect.
  • Before ZED SDK 5.6, it could delay the images by up to one capping period (about 200 ms at 5 FPS). Since ZED SDK 5.6, grab() processes the newest image.

Find the best capping value

The best value depends on the processing power of the host and on the configuration of your application: resolution, depth mode, and enabled modules. To find it:

  1. Set camera_fps to the highest frame rate available for your resolution.
  2. Set grab_compute_capping_fps to the processing rate required by your application.
  3. Run your application with its full workload and monitor the processing rate with getCurrentFPS(), and the CPU and GPU load of the host.
  4. If the processing rate stays steadily at the capping value and the host has resources left, you can increase the capping value. If the processing rate cannot reach the capping value, the host cannot sustain this processing rate: decrease the capping value, or reduce the workload, for example with a lighter depth mode.

Tune the power mode of a ZED Box

On a ZED Box, a ZED Box Mini, a ZED Box 2, or a ZED Box 2 Max, the power mode of the NVIDIA® Jetson™ module sets the number of active CPU cores and the maximum CPU and GPU frequencies, and therefore the processing rate that the host can sustain. Once your capping value is defined, you can tune the power mode to balance processing frequency and power consumption:

  • If the processing rate cannot reach the capping value, select a higher power mode to increase the processing power of the module, within the limits of your power supply.
  • If the processing rate stays steadily at the capping value, try lower power modes and keep the lowest one that still sustains the required processing rate. This minimizes the power consumption and the heat of the host.

The available power modes and how to change them are described in the Power Modes guides of the ZED Box, of the ZED Box Mini, of the ZED Box 2, and of the ZED Box 2 Max.

With the ZED ROS 2 Wrapper, the same behavior is available through the general.grab_frame_rate and general.grab_compute_capping_fps parameters. See Stereo Node Frequency Tuning.