Camera Module

Intro PythonVariables, loops, functions, imports, dictionaries, and basic debugging.

Before you start

  • Complete the SDK Overview
  • Know how to run a Python file from the robot's local Terminal
  • Keep the ZED lenses clean and its cable secured

Use Camera when your project needs to observe the world but does not need to move the robot.

Learning Goals

You will learn how to:

  • Open and close the ZED safely.
  • Capture RGB and depth arrays.
  • Recognize optional pose and IMU values.
  • Repeat a capture in a loop.
  • Move to the full ZED implementation when your project needs it.

Vocabulary

  • Frame: One camera update captured at a specific time.
  • RGB image: A height-by-width array with red, green, and blue values.
  • Depth map: A height-by-width array containing distance in meters. Invalid pixels can be NaN or infinite.
  • Pose: The camera position and orientation relative to its starting point.
  • IMU: Motion-sensor readings such as acceleration and angular velocity.

Capture One Frame

Create this program in ~/gather-sdk/projects:

from gather_sdk import Camera
 
with Camera() as camera:
    frame = camera.capture()
    print("RGB:", frame.rgb.shape)
    print("Depth:", frame.depth_m.shape if frame.depth_m is not None else "off")

The with block opens the camera before your indented code and closes it even when an error occurs.

What Each Line Does

  1. from gather_sdk import Camera loads the beginner camera interface.
  2. with Camera() as camera opens the ZED and guarantees it closes afterward.
  3. camera.capture() requests one fresh camera update.
  4. frame.rgb.shape prints image height, width, and color-channel count.
  5. The conditional prints a depth-map shape only when depth is available.

Understand CameraFrame

FieldValue
rgbNumPy array shaped (height, width, 3)
depth_mNumPy array of distances in meters, or None
poseGather pose object, or None when tracking is disabled/unavailable
imuGather IMU object, or None when IMU capture is disabled/unavailable
timestampCapture time in seconds

Capture Several Frames

from gather_sdk import Camera
 
with Camera(fps=30) as camera:
    for frame_number in range(10):
        frame = camera.capture()
        center_y = frame.rgb.shape[0] // 2
        center_x = frame.rgb.shape[1] // 2
        center_pixel = frame.rgb[center_y, center_x]
        print(frame_number, center_pixel)

Try These Changes

  1. Change range(10) to range(30).
  2. Print frame.pose.position when frame.pose is not None.
  3. Find the depth at the center pixel with frame.depth_m[center_y, center_x].
  4. Disable unused sensors with Camera(include_pose=False, include_imu=False).

Add a feature to Camera code

AI coding promptmodify

Inspect an existing Camera project and implement one focused image, depth, pose, or IMU feature.

Verify before running

Review the diff, confirm optional values are handled, and predict the expected output before running the file.

Preview the prompt
Work as a coding agent inside ~/gather-sdk/projects on the assigned Gather robot. Inspect the existing Camera program and implement the feature I request, such as image-shape reporting, center depth, a bounded capture loop, pose availability, or IMU availability. Use from gather_sdk import Camera before considering an advanced backend. Keep the with Camera() cleanup pattern and handle optional depth, pose, and IMU values when needed. Do not edit the installed SDK source. Run python3.10 -m py_compile on each changed Python file and report the exact files and validation result. Never initiate physical motion, run a hardware capture on your own, or claim the camera worked without actual output. Explain the diff briefly and leave one expected value or behavior for me to verify during the manual run.

Paste this into an AI coding tool opened in ~/gather-sdk/projects.

Repair Camera Code

Use this prompt when a project file needs a code correction. Hardware and platform problems remain instructor-managed.

Repair a Camera program

AI coding promptrepair

Inspect failing Camera code, make the smallest supported correction, and compile the result.

Verify before running

Review the correction and rerun the original command yourself, then compare its output with the reported cause.

Preview the prompt
Work as a coding agent inside ~/gather-sdk/projects. Inspect the failing Camera program, the exact command, and the available error output. Make the smallest code change supported by the documented gather_sdk Camera API. Check imports, lifecycle, context-manager cleanup, and optional CameraFrame values before considering advanced ZED code. Do not edit the installed SDK source or change operating-system, network, or camera configuration. Run python3.10 -m py_compile on every changed Python file. If the evidence points to a hardware or platform dependency instead of the project code, do not invent a code fix; report that boundary clearly. Never initiate physical motion, run hardware capture on your own, or claim the repair worked without new output. Summarize the cause, the diff, and one result I should verify when I rerun the original command.

Paste this into an AI coding tool opened in ~/gather-sdk/projects.

Constructor Options

OptionDefaultPurpose
resolution"HD720"ZED capture resolution
fps30Requested frames per second
include_depthTrueCapture distances in meters
include_poseTrueEnable positional tracking
include_imuTrueCapture motion-sensor data

Method Summary

MethodWhat it does
open()Opens and configures the ZED
capture()Returns one fresh CameraFrame
close()Releases the camera

Prefer the with Camera() pattern because it guarantees cleanup.

Use The Full ZED Implementation

The beginner class intentionally leaves out recording, streaming, spatial mapping, object/body detection, and detailed runtime tuning. Those existing features remain available:

from gather_sdk.advanced import ZEDCameraImpl, ZEDStreamClientImpl

You may also create your own Python files using pyzed.sl directly when a project needs raw ZED SDK behavior.

Troubleshooting

The camera is already in use

Close other test scripts, visualizers, installed robot projects, or recording processes before opening a second camera connection.

Depth contains NaN or infinity

The ZED could not measure that pixel. Reflective, very dark, very close, or distant surfaces can produce invalid depth.

Pose is None

Give positional tracking a few frames to initialize and provide visible features in the environment. Confirm include_pose=True.

Images look dark or unreliable

Check the physical camera guide for lens, lighting, alignment, and cable checks.

Next Guides