Rust bindings for the Stereolabs ZED SDK, providing safe and idiomatic Rust interfaces for ZED camera operations.
Before using this crate, you need to install the ZED SDK:
-
Download and install the ZED SDK from Stereolabs website
-
Ensure the SDK is installed in the standard location:
- Linux:
/usr/local/zed/
- The library should be at
/usr/local/zed/lib/libsl_zed_c.so
- Headers should be at
/usr/local/zed/include/
- Linux:
-
Set up library path (Linux):
export LD_LIBRARY_PATH=/usr/local/zed/lib:/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Add this to your Cargo.toml
:
[dependencies]
zed-rs-api = "0.1.0"
use zed_sdk::{Camera, InitParameters, Resolution, DepthMode};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create and configure camera
let mut camera = Camera::new(0)?;
let params = InitParameters::default()
.with_resolution(Resolution::HD1080)
.with_fps(30)
.with_depth_mode(DepthMode::Neural);
// Open camera
camera.open(¶ms)?;
println!("Camera serial: {}", camera.get_serial_number()?);
// Capture frames
for i in 0..10 {
camera.grab()?;
let timestamp = camera.get_timestamp()?;
println!("Frame {}: {}", i, timestamp);
}
Ok(())
}
To run the included example:
# Set library path and run
LD_LIBRARY_PATH=/usr/local/zed/lib:/usr/local/cuda/lib64:$LD_LIBRARY_PATH cargo run --bin zed_example
use zed_sdk::{Camera, InitParameters, Resolution};
// Create camera
let mut camera = Camera::new(0)?;
// Configure parameters
let params = InitParameters::default()
.with_resolution(Resolution::HD1080)
.with_fps(30);
// Open and use camera
camera.open(¶ms)?;
let serial = camera.get_serial_number()?;
use zed_sdk::RuntimeParameters;
// Basic frame capture
camera.grab()?;
// With custom parameters
let runtime_params = RuntimeParameters::default();
camera.grab_with_params(&runtime_params)?;
// Get frame timestamp
let timestamp = camera.get_timestamp()?;
use zed_sdk::{InitParameters, Resolution, DepthMode};
let params = InitParameters::default()
.with_resolution(Resolution::HD1080) // Camera resolution
.with_fps(30) // Frame rate
.with_depth_mode(DepthMode::Neural) // Depth computation mode
.with_depth_maximum_distance(40.0) // Max depth distance
.with_image_enhancement(true) // Enable image enhancement
.with_verbose(false); // SDK logging
The crate provides comprehensive error handling through the ZedError
enum:
use zed_sdk::ZedError;
match camera.open(¶ms) {
Ok(()) => println!("Camera opened successfully"),
Err(ZedError::CameraOpenFailed(code)) => {
eprintln!("Failed to open camera: error code {}", code);
}
Err(e) => eprintln!("Error: {}", e),
}
- ZED Camera (ZED, ZED Mini, ZED 2, ZED 2i, ZED X, etc.)
- CUDA (for depth processing)
- ZED SDK 4.0 or later
- Rust 1.70 or later
- ✅ Linux (x86_64, aarch64)
git clone https://github.com/yourusername/zed-rs-api.git
cd zed-rs-api
# Build the library
cargo build
# Run tests (requires ZED camera)
LD_LIBRARY_PATH=/usr/local/zed/lib:/usr/local/cuda/lib64:$LD_LIBRARY_PATH cargo test
# Build documentation
cargo doc --open
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Install the ZED SDK
- Clone this repository
- Set up the library path
- Run
cargo test
to ensure everything works
This project is licensed under the MIT License. See LICENSE for details.
It provides Rust bindings to the ZED C API, which is developed and maintained by Stereolabs. The SDK is MIT licensed. See LICENSE-upstream for the upstream license.