Skip to content

Connect ​

SUMMARY

Connect opens a connection to the camera hardware so frames can be acquired. It initializes the underlying vendor SDK, opens the device, allocates buffers or starts the pipeline, and registers any BabyROS nodes the camera class exposes.

Always pair it with Disconnect inside a try / finally block so the device is freed even if an exception is raised.

All subsequent operations on the camera require an active connection.

Available on: All cameras.

The Skill ​

python
camera.connect()

For RealSense, optional stream parameters can be passed to connect:

python
camera.connect(width=640, height=480, fps=30)

The Code ​

python
from loguru import logger
from telekinesis.medulla.cameras import webcam

camera = webcam.Webcam(name="my_webcam_camera", camera_id=0)
try:
    camera.connect()
except Exception as e:
    logger.error(f"Unable to connect to the camera. {type(e).__name__}: {e}")
finally:
    camera.disconnect()
python
from loguru import logger
from telekinesis.medulla.cameras import ids

camera = ids.IDS(
    name="my_ids_camera",
    serial_number="4108909352",
    load_factory_defaults=False,
)
try:
    camera.connect()
except Exception as e:
    logger.error(f"Unable to connect to the camera. {type(e).__name__}: {e}")
finally:
    camera.disconnect()
python
from loguru import logger
from telekinesis.medulla.cameras import realsense

camera = realsense.RealSense(name="my_realsense_camera")
try:
    camera.connect()
except Exception as e:
    logger.error(f"Unable to connect to the camera. {type(e).__name__}: {e}")
finally:
    camera.disconnect()
python
from loguru import logger
from telekinesis.medulla.cameras import zivid

camera = zivid.Zivid(name="my_zivid_camera")
try:
    camera.connect()
except Exception as e:
    logger.error(f"Unable to connect to the camera. {type(e).__name__}: {e}")
finally:
    camera.disconnect()

The Explanation of the Code ​

connect performs the vendor-specific initialization needed before any frame can be acquired:

  • IDS — opens the device by serial_number through the IDS Peak library and allocates the acquisition buffers needed to receive frames from the sensor. With load_factory_defaults=False, parameters previously configured in IDS Peak Cockpit are preserved.
  • Webcam — opens the device via OpenCV's VideoCapture using the integer camera_id reported by the OS (0 for the first camera) and verifies that frames can be read.
  • RealSense — initializes the RealSense pipeline with default stream settings, enabling the depth and colour streams. No serial number is required; the class connects to the first available device automatically. Optional width, height, and fps parameters configure both the colour and depth streams simultaneously.
  • Zivid — initializes the Zivid SDK application and connects to the first available Zivid camera. Default capture settings are created with a single 3D acquisition and a single 2D colour acquisition. Use load_settings after connecting to apply a configuration exported from Zivid Studio.

WARNING

Make sure to disconnect from the camera with disconnect() at the end of your script to avoid a freezing terminal when the script finishes.

Parameter Configuration ​

ParameterTypeDefaultDescription
load_factory_defaultsboolFalseIDS only. Whether to load the camera's factory default settings on connect.
widthint | NoneNoneRealSense only. Stream width in pixels. Must be provided together with height and fps, or all three omitted for camera defaults.
heightint | NoneNoneRealSense only. Stream height in pixels. Must be provided together with width and fps, or all three omitted for camera defaults.
fpsint | NoneNoneRealSense only. Target frames per second. Must be provided together with width and height, or all three omitted for camera defaults.
warmup_framesint30RealSense only. Number of frames captured and discarded after the pipeline starts, to let auto-exposure and auto-white-balance converge before the first real capture. Set to 0 to skip.

Webcam and Zivid take no parameters; camera identity (camera index, serial number) is supplied through the constructor instead.

Returns ​

TypeDescription
boolIDS, Webcam, RealSense: True once connected (also True, with a logged warning, if the camera was already connected).
NoneZivid: no return value.

Raises ​

ExceptionCondition
RuntimeErrorThe device could not be found or opened: no device matches the requested serial number (IDS, RealSense), OpenCV could not open camera_id (Webcam), or the Zivid SDK failed to connect (Zivid).
ArgumentErrorRealSense only: only some of width, height, fps were provided, or the requested combination isn't a supported stream configuration.

Calling connect() again while already connected does not raise on any camera — it logs and returns instead.

Where to Use the Skill ​

Connect is the first call against any Medulla camera. Pair it with Disconnect inside a try / finally block so resources are released regardless of how the script exits. See Capture Color Image for the full pattern in practice.