poulet_py.hardware.camera.basler module#

class BaslerCamera(max_cameras=2)[source]#

Bases: object

A class to interact with multiple Basler cameras using pypylon and OpenCV. Each camera will record to its own video file and log timestamps to a CSV.

__init__(max_cameras=2)[source]#

Initializes the BaslerCamera object by enumerating devices and attaching up to max_cameras.

Args:

max_cameras (int): The maximum number of cameras to use.

set_frames_per_second(frames_per_second)[source]#

Sets the frame rate for each camera.

Args:

frames_per_second (float): Desired frame rate in frames per second.

set_error_log_path(path, file_name)[source]#

Sets the error log file.

Args:

path (str): Directory for the error log. file_name (str): Name of the error log file.

set_output_file(path, extra_name, base_file_name='basler-camera')[source]#

Sets up output video files and timestamp CSV files for all cameras.

Args:

path (str): Directory to save the output files. extra_name (str): Extra name to add to the file names. base_file_name (str): Base name for the files.

save_timestamp(camera_index, timestamp)[source]#

Save a timestamp to the CSV file for the specified camera.

Args:

camera_index (int): Index of the camera. timestamp (float): Timestamp to record.

start_streaming()[source]#

Starts the grabbing (streaming) for all cameras.

stop_streaming()[source]#

Stops the streaming and closes all cameras and video writers.

capture_frame()[source]#

Captures a single frame from whichever camera has a frame ready. The frame is written to its corresponding video file and timestamp logged.

stream_video(window_width=None, window_height=None)[source]#

Streams the live video feed from all cameras. Each camera is shown in its own window.

Args:

window_width (int, optional): Width to resize the window. window_height (int, optional): Height to resize the window.

save_metadata(base_file_name='basler-camera', extra_name='')[source]#

Saves metadata about the recording for each camera to a JSON file.

Args:

path (str): Directory to save the metadata files. base_file_name (str, optional): Base name for the metadata files. extra_name (str, optional): Extra name to add to the file names.

recording(data_save_folder, cage_id, n_mouse, condition, mouse_ids=[], duration_s=10, buffer_s=10, total_rec=4, fps=30, video_format='mp4')[source]#
static log_error(self, error_message)[source]#

Logs an error message to the error log file if set; otherwise, prints the error.

Args:

error_message: The error message or exception.