Skip to content

Update ZED Open Capture to v1.0.0 - #49

Open
Myzhar wants to merge 18 commits into
masterfrom
walterlucetti/update-zed-open-capture-to-v100
Open

Myzhar wants to merge 18 commits into
masterfrom
walterlucetti/update-zed-open-capture-to-v100

Conversation

@Myzhar

@Myzhar Myzhar commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Summary

Full review of the library and of the examples for v1.0.0, to give reliable access to ZED 2i, ZED 2 and ZED Mini on Linux computers without the ZED SDK and without an NVIDIA GPU, including Raspberry Pi 4.

What changes for users

Reliability

  • Frames returned by getLastFrame() are no longer overwritten while the application uses them
  • No IMU sample is lost: new getIMUData() returns all the samples received after the previous call
  • Fixed the reset functions that never returned, the crash when connecting the sensors to a second camera, the application blocked when closing right after opening, and resources left allocated when opening a camera fails
  • A disconnected camera is detected (isOpened()), and a warning is printed when the environmental sensors of the camera stop providing new data

Camera controls

  • Gain, exposure, white balance, hue and the other controls are applied reliably, at start-up and while streaming: the library waits for the camera to complete each command and reads the setting back
  • The manual exposure stays within the limit of the current frame rate
  • ZED 2 and ZED 2i: gain and exposure of the left sensor are applied and read correctly also while the sensors module sends data. In that condition the left sensor can stop answering for 0.5 to several seconds at a time: the access is now verified and repeated until it answers, for up to 6 s. getGain() and getExposure() return an error instead of a wrong value (e.g. an exposure of 95325)
  • ZED 2 and ZED 2i: when the image sensors of the camera do not answer at the start of the stream, initializeVideo() waits for the camera to start them again (about 6 s), then restarts the camera through its sensors module if needed, instead of returning a camera without frames

Timestamps

  • Frames and sensors data use the same clock from the first sample, also without synchronization
  • With enableSensorSync() each frame takes the timestamp of the IMU sample acquired with its hardware sync signal, immediately (99-100% of the frames in the tests)

New functions

  • VideoCapture::getDeviceList(), initializeVideoBySerialNumber(), close(), isOpened(), getFps(), getCameraModel()
  • SensorCapture::getIMUData(), close(), isOpened()

Depth example

  • Fixed the depth values: the disparity was increased by one pixel before the conversion to depth, and failed matches were used as valid values
  • The point cloud is drawn in a standard window: the previous viewer did not work on Raspberry Pi 4 and on computers without the OpenCV Viz module, like NVIDIA Jetson
  • Less CPU for the same depth map: the matching uses grayscale images reduced before the rectification
  • The stereo matching parameters are the same as in v0.6.0

Tools, build and documentation

  • New zed_open_capture_benchmark: image, sensors and depth performance of the host as Markdown tables, without a display
  • Hardware tests based on GoogleTest (-DBUILD_TESTS=ON), with camera control tests and long stress tests (ZED_OC_STRESS_SCALE sets their length)
  • README "Known issues": when the camera stops its image sensors or its environmental sensors, how to avoid it, and how to reset the sensors module at start-up
  • make install provides a CMake package and a pkg-config file
  • C++17, CMake 3.16, warnings enabled (the build has no warnings), sanitizer build option
  • README, changelog and Doxygen pages updated, with benchmarks for Raspberry Pi 4 and NVIDIA Jetson AGX Thor

Continuous integration (from #50)

  • Each pull request is built with GCC and Clang on x86_64 and ARM64 in every module configuration, with warnings as errors; the installed package is used by a small application; the tests that do not need a camera run also with the address and thread sanitizers
  • Documentation generated without warnings and published from master, static analysis, CodeQL, and a workflow that creates the release when a version tag is pushed
  • The job Build check is the one to set as required status check of master

API changes

Existing applications need small changes, listed in the changelog. The main ones:

  • The functions that change a camera setting return true if the camera accepted it. setAECAGC, setLEDstatus, getLEDstatus and toggleLED returned an int with 0 for success
  • Frame::frame_id is the frame counter of the driver
  • The functions used internally by the synchronization and the log macros are no longer public

Tests

Host Camera Result
NVIDIA Jetson AGX Thor ZED 2i, ZED Mini All the video, sensors, sync and control tests pass, also built with the address and thread sanitizers (no report)
Raspberry Pi 4 ZED 2 All the video, sensors, sync and control tests pass
x86_64, Ubuntu 22.04 ZED 2i All the control tests pass

Stress tests, 1.5 times the default length, on the three cameras (all pass: 17 on the Thor, 8 on the Pi):

  • 225 start-ups with manual gain and exposure, 1,800 changes while streaming, 120 open/close cycles in every mode: no failure
  • 450 s of constant manual exposure: the value never changed
  • 90 s of mixed settings changed from another thread (3,166 on the Thor, 7,206 on the Pi): none failed
  • 270 s of video and sensors together: no IMU pause
  • 360 s of sensors only, after a reset of the sensors module: no IMU pause, environmental data at 25 Hz without gaps
  • 155 open/close cycles with the sensors streaming on the ZED 2: 4 starts where the image sensors did not answer, all recovered by the new wait, no failed open

USB power management was ruled out as the cause of the sensors issues: they also happen with every USB device of the camera, its hubs and the root hubs kept powered.

Gain and exposure with the sensors module streaming, on x86_64 with ZED 2i: 1000 cycles of brightness, gain and exposure on both sensors with read-back, repeated 3 times, with an IMU thread: no failure (15 failed cycles out of 400 before the fix).

Not tested: the first ZED model, the stress tests on x86 hosts, Windows.

Before the release

  • The changelog still reports v1.0.0 as "in development": the date has to be set when the release is created

Library
- Frames returned by getLastFrame() are no longer overwritten while in use
- Frames and sensors data share the host clock; frames take the timestamp
  of their hardware sync signal when the synchronization is enabled
- Add getIMUData() to receive every IMU sample, camera listing, open by
  serial number, close() and isOpened() for video and sensors
- Camera settings report if they have been accepted
- Fix hangs in the reset functions and when closing right after opening,
  the crash when connecting the sensors to a second camera, leaks when
  opening fails and a buffer overflow in the LED commands
- resetGamma() restores the factory gamma, getGamma() reads the real value

Examples and tools
- Depth is extracted on CPU from grayscale images with new default
  parameters and automatic refinement of the rectification
- Add zed_open_capture_benchmark to measure image, sensors and depth
  performance without a display
- Sensors and sync examples no longer lose IMU samples; the multi-camera
  example searches the connected cameras

Build
- C++17, CMake 3.16, warnings enabled, sanitizer option
- Install a CMake package and a pkg-config file
- The udev installer applies the rules without replugging the camera
The tests run on every connected camera, without a display, and check
video streaming in every mode, camera controls, sensors rate and
timestamps, and the video/sensors synchronization.
Enable them with -DBUILD_TESTS=ON.
Add usage of the new functions, build options, test instructions, depth
settings and the benchmarks measured on Raspberry Pi 4 and NVIDIA Jetson
AGX Thor.
- Print a warning when the environmental and temperature sensors of the
  camera stop providing new data, pointing to resetSensorModule()
- Benchmarks measured again with a ZED 2i on the Jetson AGX Thor and
  with a textured scene for the depth
- Describe MODE_HH4 and the left-right check in the depth settings
- Build: GCC and Clang, x86_64 and ARM64, every module configuration with
  warnings as errors, installed package used through CMake and pkg-config,
  tests that do not need a camera, also with address and thread sanitizers
- Documentation: generated without warnings on pull requests, published
  from master
- Checks: static analysis, CodeQL, no references to internal tools
- Release: created from the changelog when a version tag is pushed
- Fix two warnings reported by Clang
@Myzhar Myzhar mentioned this pull request Nov 14, 2026
Myzhar and others added 4 commits November 14, 2026 18:36
- The depth example no longer uses the OpenCV Viz module: on Raspberry
  Pi 4 its window opened and closed continuously with shader errors, and
  it was not available with OpenCV builds without Viz, like on NVIDIA
  Jetson. The point cloud is drawn on CPU with mouse controls
- The depth map is displayed with the size of the left image
- Complete the v0.6.0 section of the changelog and bring the v1.0.0
  section up to date
The old product links of the website all redirected to the same page
@Myzhar
Myzhar marked this pull request as draft November 14, 2026 18:55
@Myzhar Myzhar self-assigned this Nov 14, 2026
@Myzhar
Myzhar marked this pull request as ready for review November 14, 2026 18:56
…ot answer

- Wait for the camera to complete each control command, check the
  register writes and read back the settings, so gain, exposure, hue and
  the other controls are applied at start-up and while streaming
- Keep the manual exposure within the limit of the current frame rate
- ZED 2 and ZED 2i: when the image sensors do not answer at the start of
  the stream, wait for the camera to start them again, then restart the
  camera through its sensors module if needed
- README: describe when the image sensors and the environmental sensors
  stop, how to avoid it, and how to reset the sensors module at start-up
- New control tests and long stress tests of video, sensors and camera
  settings, with the duration scaled by an environment variable
- The sensors stress test resets the sensors module first, so earlier
  video-only cases cannot leave the environmental sensors stopped
The release workflow reads the release notes from the new file name
@Myzhar

Myzhar commented Nov 15, 2026

Copy link
Copy Markdown
Member Author

Summary for the review

What changes for users

  • Frames, IMU samples and timestamps are reliable: no overwritten frames, no lost IMU samples, one clock for video and sensors, hardware-synchronized frame timestamps
  • Camera controls (gain, exposure, white balance, hue and others) are applied reliably at start-up and while streaming
  • ZED 2 and ZED 2i: when the image sensors do not answer at the start of the stream, initializeVideo() recovers instead of returning a camera without frames
  • New functions (device list, open by serial number, close(), isOpened(), getIMUData()…), a benchmark tool, hardware tests and continuous integration
  • README "Known issues" explains two camera behaviours and how to avoid them: the environmental sensors can stop after minutes of video with the sensors module closed, and the image sensors can fail to start when the video is opened while the sensors stream

Breaking changes (listed in CHANGELOG.md): the setters return bool (true = accepted), Frame::frame_id is the driver counter, some internal functions are no longer public.

Validation of the final code, full pass at 1.5 times the default stress length:

Host Camera Video, sensors, sync, controls Stress
NVIDIA Jetson AGX Thor ZED 2i, ZED Mini all pass 17 / 17 pass
Raspberry Pi 4 ZED 2 all pass 8 / 8 pass

Address and thread sanitizer builds on the Thor: no report. No failed open, refused setting or changed manual exposure in any stress case; 360 s of sensors with no IMU pause and environmental data at 25 Hz without gaps.

For the reviewer

  • Set Build check as required status check of master
  • Set the release date of v1.0.0 in CHANGELOG.md when the release is created
  • Not tested: the first ZED model, x86 hosts with a camera (x86 build verified), Windows

The variables of the camera restart are only used when the sensors module is built
While the sensors module sends data, the left image sensor of the ZED 2
and ZED 2i stops answering for 0.5 to several seconds at a time: reads
return 0xff or 0x00 and writes are lost. Outside these windows a single
reply can also carry a wrong value.

- Gain and exposure are accessed as a group of 3 registers, between two
  reads of the chip ID: if either is wrong, the group is repeated every
  10 ms, for up to 6 seconds
- Every register is read twice, and a write must be read back with the
  written value
- No retry when the camera cannot be reached
- getGain() and getExposure() return an error instead of a wrong value

Tested on ZED 2i with the IMU streaming, 1000 cycles of brightness,
gain and exposure on both sensors with read-back: 0 failures in 3 runs
(previously 15 failed cycles out of 400). test_controls passes.
The depth example shows how to use the camera images: the quality of the
depth map is not a goal of this repository.

- Stereo matching defaults back to the previous values (blockSize 3,
  disp12MaxDiff 96)
- Remove the automatic correction of the vertical misalignment of the
  images and the median filter of the disparity
- Remove the recording, replay and depth quality measures of the
  benchmark, and the "Valid pixels" and "Refine" columns of its table
- Remove the depth quality claims and the parameter guide from README,
  changelog and benchmarks page

The fixes of the depth example are kept: disparity no longer increased
by one pixel, failed matches and out of range values not used, point
cloud viewer without OpenCV Viz.
The depth timing tables were measured with the previous stereo matching
defaults. The complete benchmarks stay in the documentation.
They were measured with the previous stereo matching defaults.
@P-yver

P-yver commented Nov 17, 2026

Copy link
Copy Markdown
Member

initializeVideo() recovery: the retry loop has no pause when the sensors module is in use

else
{
// The sensors module is in use: the camera cannot be restarted, but it can still start the image
// sensors by itself
const uint64_t start = getSteadyTimestamp();
while( !recovered && getSteadyTimestamp()-start < RECOVERY_TIMEOUT_NSEC )
{
recovered = initializeVideoBySerialNumber(sn);
}
}

When resetSensorModule(sn) fails, this loop calls initializeVideoBySerialNumber(sn) back to back for RECOVERY_TIMEOUT_NSEC (15 s). The other branch waits usleep(500000) between attempts.

When the camera opens, each attempt already takes up to about 7 s (SENSORS_READY_MSEC + SENSORS_RESTART_MSEC), so that case is fine. When the open fails fast, the loop opens every /dev/video* and reads its serial number continuously for 15 s, using a full CPU core. Logs are silenced the whole time, because verbose is set to NONE. The open fails fast when:

the camera is unplugged,
the device is busy in another process,
the serial number can't be read.
Suggestion: use the same usleep(500000) in both branches. The two loops could also be merged into one, since they only differ by that pause.

@Myzhar

Myzhar commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

initializeVideo() recovery: the retry loop has no pause when the sensors module is in use

else
{
// The sensors module is in use: the camera cannot be restarted, but it can still start the image
// sensors by itself
const uint64_t start = getSteadyTimestamp();
while( !recovered && getSteadyTimestamp()-start < RECOVERY_TIMEOUT_NSEC )
{
recovered = initializeVideoBySerialNumber(sn);
}
}

When resetSensorModule(sn) fails, this loop calls initializeVideoBySerialNumber(sn) back to back for RECOVERY_TIMEOUT_NSEC (15 s). The other branch waits usleep(500000) between attempts.

When the camera opens, each attempt already takes up to about 7 s (SENSORS_READY_MSEC + SENSORS_RESTART_MSEC), so that case is fine. When the open fails fast, the loop opens every /dev/video* and reads its serial number continuously for 15 s, using a full CPU core. Logs are silenced the whole time, because verbose is set to NONE. The open fails fast when:

the camera is unplugged,
the device is busy in another process,
the serial number can't be read.
Suggestion: use the same usleep(500000) in both branches. The two loops could also be merged into one, since they only differ by that pause.

Good catch. Fixing it

@Myzhar
Myzhar requested review from P-yver and removed request for adujardin November 17, 2026 16:13
When the sensors module cannot restart the camera, the recovery loop
retried without pause for 15 s. If opening failed fast (camera
unplugged, device busy, serial number not readable), it scanned every
video device about 1,300 times per second with logs silenced. Both
cases now wait 500 ms between attempts.

The log after a successful recovery now says whether the camera was
actually restarted.
@Myzhar

Myzhar commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Thanks, fixed in 849b1a7: the two loops are merged and every attempt waits 500 ms. The log after a recovery now also says whether the camera was actually restarted, since that branch logged "Camera restarted" even when the reset had failed.

Tested on a ZED 2i with a fault-injection build that forces the "image sensors do not answer" path:

Case Before After
Reset fails, opening fails fast 19,023 attempts in 15 s 30 attempts in 15 s
Reset succeeds reopened in 2.9 s same
Reset fails, sensors module held by a SensorCapture reopened in 0.9 s reopened in 1.5 s

One correction on the cost: the process used about 1.25 s of CPU over the 15 s, not a full core. Most of the time went into opening each /dev/video* and reading its serial number over USB, about 1,300 times per second, with logs silenced. So it was still worth fixing.

The pause now also comes before the first attempt when the reset fails. This costs 0.5 s on a rare path. It keeps both cases identical, and after a successful reset it avoids opening the camera before it drops off the bus.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants