Skip to content

IDS: Capture Single Image

SUMMARY

Capture a single color frame, optionally adjust exposure beforehand, and visualize the result with Rerun.

Example

Single image capture output

Camera parameters can be set in two ways:

  1. IDS Peak Cockpit — Connect, adjust settings, then close the app. Parameters persist until the camera is disconnected or the PC restarts.
  2. Code — Use get_parameter / set_parameter. Supported parameter names are listed in parameter_name_to_type_map in medulla/cameras/ids.py (e.g. AcquisitionFrameRate, ExposureTime, DeviceLinkThroughputLimit).

Code

python
"""
Connect to an IDS camera, get/set parameters, capture an image, and disconnect.

Run from a terminal to avoid issues with Rerun's spawn mode.
"""
from loguru import logger
import rerun as rr

from medulla.cameras import ids


def main():
    camera = ids.IDS(
        name="my_ids_camera",
        serial_number="4108909352",
        load_factory_defaults=False
    )
    try:
        rr.init("IDS_Example", spawn=True)
        camera.connect()

        logger.info(f"ExposureTime: {camera.get_parameter('ExposureTime')}")
        camera.set_parameter('ExposureTime', 35000.0)

        image = camera.capture_single_color_frame()

        rr.log("Single_Image_Capture", rr.Image(image))
    except Exception as e:
        logger.error(f"Unable to capture image. {type(e).__name__}: {e}")
    finally:
        camera.disconnect()


if __name__ == "__main__":
    main()

Explanation

Now, let’s break down the code piece by piece.

An IDS camera object is created by supplying a unique name and the physical camera's serial_number. Setting load_factory_defaults=False preserves any parameters previously configured in IDS Peak Cockpit, rather than resetting them to factory values on connect.

python
camera = ids.IDS(
    name="my_ids_camera",
    serial_number="4108909352",
    load_factory_defaults=False
)

A Rerun viewer is opened with rr.init(..., spawn=True), then camera.connect() initializes the IDS Peak library, opens the device by serial number, and allocates the acquisition buffers needed to receive frames from the sensor. All subsequent operations require an active connection.

python
rr.init("IDS_Example", spawn=True)
camera.connect()

The current ExposureTime is read back with get_parameter so you can verify the starting value before making changes, then set_parameter updates it to 35 ms (35 000 µs). The parameter name must exist in parameter_name_to_type_map in medulla/cameras/ids.py — passing an unknown name raises a KeyError.

python
logger.info(f"ExposureTime: {camera.get_parameter('ExposureTime')}")
camera.set_parameter('ExposureTime', 35000.0)

capture_single_color_frame sets the camera to SingleFrame acquisition mode, triggers one exposure, waits for the buffer to fill, converts it to a color image, and returns a NumPy array. The frame is then logged to Rerun under the path "Single_Image_Capture" for immediate visual inspection.

python
image = camera.capture_single_color_frame()

rr.log("Single_Image_Capture", rr.Image(image))

The finally block guarantees that camera.disconnect() is always called — regardless of whether an exception occurred. It stops acquisition, releases all allocated buffers, closes the IDS Peak library, and shuts down any BabyROS nodes registered inside the IDS instance.

python
finally:
    camera.disconnect()

Run

bash
python capture_image_example.py

A Rerun viewer opens automatically. The captured frame appears under Single_Image_Capture once acquisition completes.