ci_lab_utilities

Utility functions for the CI-group lab.

Package Contents

Classes

IPCamera

A general class to steam and record from IP cameras via opencv.

Functions

calibrate_camera() → tuple[tuple[int, Ellipsis], ...)

Calibrate cameras for distortion and fisheye effects.

calibrate_camera(calibration_images_paths: list[str], checkerboard_size: tuple[int, int] = (9, 9)) tuple[tuple[int, Ellipsis], numpy.typing.NDArray[numpy.float_], numpy.typing.NDArray[numpy.float_]]

Calibrate cameras for distortion and fisheye effects.

In order to use this function effectively please use at least 5 valid calibration images, with differently places checkerboards. The checkerboard has to be fully visible with no occlusion, but it does mot have to lie flat on the ground.

Parameters:
  • calibration_images_paths – The calibration images.

  • checkerboard_size – The checkerboard size. Note if you have a 10 x 10 checkerboard the size should be (9, 9).

Returns:

The dimension of the calibration images, the camera matrix and the distortion coefficient.

class IPCamera(camera_location: str, recording_path: str | None = None, image_dimensions: tuple[int, int] = (1920, 1080), distortion_coefficients: numpy.typing.NDArray[numpy.float_] = np.array([[-0.2976428547328032], [3.2508343621538445], [-17.38410840159056], [30.01965021834286]]), camera_matrix: numpy.typing.NDArray[numpy.float_] = np.array([[1490.4374643604199, 0.0, 990.6557248821284], [0.0, 1490.6535480621505, 544.6243597123726], [0.0, 0.0, 1.0]]), fps: int = 30)

A general class to steam and record from IP cameras via opencv.

How to use: >>> address = “rtsp://<user>:<password>@<ip>:<port (554)>/…” >>> camera = IPCamera(camera_location=address, recording_path=”<example_path>”) >>> camera.start(display=True, record=True)

If you are experiencing XDG_SESSION_TYPE error messages because of wayland use the following code before you start the recording: >>> import os >>> os.environ[“XDG_SESSION_TYPE”] = “xcb” >>> os.environ[“OPENCV_FFMPEG_CAPTURE_OPTIONS”] = “rtsp_transport;udp”

start(record: bool = False, display: bool = True) None

Start the camera.

Parameters:
  • record – Whether to record.

  • display – Whether to display the video stream.