Cameras

Regular Cameras

Camera GStreamer

class crappy.camera.CameraGstreamer[source]

A class for reading images from a video device using Gstreamer.

It can read images from the default video source, or a video device can be specified. The user has access to a range of parameters for tuning the image, depending on the capability of the hardware. Alternatively, it is possible to give a custom GStreamer pipeline as an argument. In this case no settings are available, and it is up to the user to ensure the validity of the pipeline.

This class uses less resources and is compatible with more cameras than the CameraOpencv camera, that relies on OpenCV. The installation of GStreamer is however less straightforward than the one of OpenCV, especially on Windows !

Warning

There are two classes for CameraGstreamer, one for Linux based on v4l-utils, and another one for Linux (without v4l-utils) and other OS. Depending on the installation of v4l-utils and the OS, the correct class will be automatically imported. The version using v4l-utils allows tuning more parameters than the basic version.

Note

This Camera requires the module PyGObject to be installed, as well as GStreamer.

New in version 1.5.9.

Changed in version 2.0.0: renamed from Camera_gstreamer to CameraGstreamer

__init__() None[source]

Simply initializes the instance attributes.

open(device: int | str | None = None, user_pipeline: str | None = None, nb_channels: int | None = None, img_depth: int | None = None, **kwargs) None[source]

Opens the pipeline, sets the settings and starts the acquisition of images.

A custom pipeline can be specified using the user_pipeline argument. Simply copy-paste the pipeline as it is in the terminal, and the class will take care of adjusting it to make it compatible with the Python binding of GStreamer.

Note

For custom pipelines, it may be necessary to set a format directly in the pipeline (which isn’t the case in the terminal). For instance, this line

gst-launch-1.0 autovideosrc ! videoconvert ! autovideosink

May need to become

gst-launch-1.0 autovideosrc ! videoconvert ! video/x-raw,format=BGR ! autovideosink

Note

Pipelines built using a pipe for redirecting the stream from another application are also accepted. For example, the following user pipeline is valid :

gphoto2 --stdout --capture-movie | gst-launch-1.0 fdsrc fd=0 ! videoconvert ! autovideosink
Parameters:
  • device – The video device to open, if the device opened by default isn’t the right one. In Linux, should be a path like /dev/video0. In Windows and Mac, should be the index of the video device. This argument is ignored if a user_pipeline is given.

  • user_pipeline – A custom pipeline that can optionally be given as a str. If given, the device argument is ignored. The pipeline should be given as it would be in a terminal.

  • nb_channels – The number of channels expected in the acquired images, in case a custom pipeline is given. Otherwise, this argument is ignored. For now, Crappy only manages 1- and 3-channel images.

  • img_depth – The bit depth of each channel of the acquired images, in case a custom pipeline is given. Otherwise, this argument is ignored. For now, Crappy only manages 8- and 16-bits deep images.

  • **kwargs – Allows specifying values for the settings even before displaying the configuration window.

get_image() Tuple[float, ndarray][source]

Reads the last image acquired from the camera.

Returns:

The acquired image, along with a timestamp.

close() None[source]

Simply stops the image acquisition.

Camera OpenCV

class crappy.camera.CameraOpencv[source]

A class for reading images from any camera able to interface with OpenCV.

The number of the video device to read images from can be specified.

This camera class is less performant than the CameraGstreamer one that relies on GStreamer, but the installation of OpenCV is way easier than the one of GStreamer, especially on Windows !

Warning

There are two classes for CameraOpencv, one for Linux based on v4l-utils, and another one for Linux (without v4l-utils) and other OS. Depending on the installation of v4l-utils and the OS, the correct class will be automatically imported. The version using v4l-utils allows tuning more parameters than the basic version.

New in version 1.5.9.

Changed in version 2.0.0: renamed from Camera_opencv to CameraOpencv

__init__() None[source]

Sets variables and adds the channels setting.

open(device_num: int | None = 0, **kwargs) None[source]

Opens the video stream and sets any user-specified settings.

Parameters:
  • device_num – The index of the device to open, as an int.

  • **kwargs – Any additional setting to set before opening the configuration window.

get_image() Tuple[float, ndarray][source]

Grabs a frame from the videocapture object and returns it along with a timestamp.

close() None[source]

Releases the videocapture object.

Fake Camera

class crappy.camera.FakeCamera[source]

This camera class generates images without requiring any actual camera or existing image file.

The generated images are just a gradient of grey levels, with a line moving as a function of time. It is possible to tune the dimension of the image, the frame rate and the speed of the moving line.

New in version 1.4.0.

Changed in version 2.0.0: renamed from Fake_camera to FakeCamera

__init__() None[source]

Initializes the parent class and instantiates the settings.

open(width: int = 1280, height: int = 720, speed: float = 100.0, fps: float = 50.0) None[source]

Sets the settings, initializes the first image and starts the time counter.

Parameters:
  • width – The width of the image to generate in pixels.

  • height – The height of the image to generate in pixels.

  • speed – The evolution speed of the image, in pixels per second.

  • fps – The maximum update frequency of the generated images.

New in version 2.0.0: width, height, speed and fps arguments explicitly listed

get_image() Tuple[float, ndarray][source]

Returns the updated image, depending only on the current timestamp.

Also includes a waiting loop in order to achieve the right frame rate.

File Reader

class crappy.camera.FileReader[source]

This Camera class reads existing images from a given folder, in the same order in which they were acquired.

The name of the images to read must follow the following pattern : <frame_nr>_<frame_seconds>.<frame_subseconds>.<file_extension>. This pattern is the same as used for recording images with the Camera of Crappy, so images recorded via Crappy are readily readable and don’t need to be re-named.

This class tries to read the images at the same framerate as they were recorded, although the control of the framerate is not so precise. It might be that the images cannot be read fast enough to match the original framerate, in which case the images are read as fast as possible and the delay keeps growing.

New in version 1.4.0.

Changed in version 1.5.10: renamed from Streamer to File_reader

Changed in version 2.0.0: renamed from File_reader to FileReader

__init__() None[source]

Initializes the parent class and sets a few attributes.

open(reader_folder: Path | str, reader_backend: str | None = None, stop_at_end: bool = True) None[source]

Sets the reader backend and retrieves the images to read, sorted by their timestamp.

Parameters:
  • reader_folder

    The path to the folder containing the images to read.

    Changed in version 1.5.10: renamed from path to reader_folder

  • reader_backend

    The backend to use for reding the images. Should be one of :

    'sitk' or 'cv2'
    

    If not given, SimpleITK is preferred over OpenCV if available.

    New in version 1.5.10.

  • stop_at_end

    If True (the default), stops the Crappy script once the available images are all exhausted. Otherwise, simply remains idle while waiting for the test to finish.

    New in version 1.5.10.

Removed in version 1.5.10: pattern, start_delay and modifier arguments

get_image() Tuple[float, ndarray] | None[source]

Reads the next image in the image folder, and returns it at the right time so that the achieved framerate matches the original framerate.

If the original framerate cannot be achieved, just reads the image as fast as possible.

By default, stops the test when there’s no image left to read. If specified otherwise, just remains idle until the test ends.

Raspberry Pi Camera

class crappy.camera.RaspberryPiCamera[source]

Class for reading images from a Raspberry Pi Camera.

The RaspberryPiCamera Camera block is meant for reading images from a Raspberry Pi Camera. It uses the picamera module for capturing images, and cv2 for converting BGR images to black and white.

It can read images from the PiCamera V1, V2 and HQ models indifferently.

Warning

Only works on Raspberry Pi, with the picamera API. On the latest OS release “Bullseye”, it has to be specifically activated in the configuration menu.

New in version 1.4.0.

Changed in version 2.0.0: renamed from Picamera to RaspberryPiCamera

__init__() None[source]

Instantiates the available settings.

open(**kwargs: Any) None[source]

Sets the settings to their default values and starts the image acquisition thread.

get_image() Tuple[float, ndarray][source]

Simply returns the last image in the acquisition buffer.

The captured image is in GBR format, and converted into black and white if needed.

Returns:

The timeframe and the image.

close() None[source]

Joins the image acquisition thread, and closes the stream and the picamera.PiCamera object.

Seek Thermal Pro

class crappy.camera.SeekThermalPro[source]

Class for reading images from the Seek Thermal Pro infrared camera.

The SeekThermalPro Camera is meant for reading images from a Seek Thermal Pro infrared camera. It communicates over USB, and gets images by converting the received bytearrays into numpy arrays.

Important

Only for Linux users: In order to drive the Seek Thermal Pro, the appropriate udev rule should be set. This can be done using the udev_rule_setter utility in crappy’s util folder. It is also possible to add it manually by running:

$ echo "SUBSYSTEM==\"usb\", ATTR{idVendor}==\"289d\", MODE=\"0777\"" | sudo tee seek_thermal.rules > /dev/null 2>&1

in a shell opened in /etc/udev/rules.d.

New in version 1.4.0.

Changed in version 2.0.0: renamed from Seek_thermal_pro to SeekThermalPro

__init__() None[source]

Selects the right USB device.

open() None[source]

Sets the USB communication and initializes the device.

get_image() Tuple[float, ndarray][source]

Reads a single image from the camera.

Returns:

The captured image as well as a timestamp.

close() None[source]

Resets the camera and releases the USB resources.

Webcam

class crappy.camera.Webcam[source]

A basic class for reading images from a USB camera (including webcams).

It relies on the OpenCv library. Note that it was purposely kept extremely simple as it is mainly used as a demo. See CameraOpencv and CameraGstreamer for classes giving a finer control over the camera.

New in version 1.4.0.

__init__() None[source]

Sets variables and adds the channels setting.

open(device_num: int | None = 0, **kwargs) None[source]

Opens the video stream and sets any user-specified settings.

Parameters:
  • device_num – The index of the device to open, as an int.

  • **kwargs

    Any additional setting to set before opening the configuration window.

    Changed in version 1.5.9: renamed from numdevice to device_num

get_image() Tuple[float, ndarray][source]

Grabs a frame from the videocapture object and returns it along with a timestamp.

close() None[source]

Releases the videocapture object.

Xi API

class crappy.camera.XiAPI[source]

This class can read images from any of the Ximea cameras.

It heavily relies on the ximea module, distributed by Ximea, which is itself a wrapper around the XiAPI low-level library.

Note

Both the Python module and the camera drivers have to be installed from Ximea’s website in order for this class to run.

New in version 1.4.0.

Changed in version 2.0.0: renamed from Xiapi to XiAPI

__init__() None[source]

Instantiates a Ximea Camera and a Ximea Image object.

open(serial_number: str | None = None, timeout: int | None = None, trigger: str | None = None, data_format: str | None = None, exposure_time_us: int | None = None, gain: float | None = None, auto_exposure_auto_gain: bool | None = None, gamma_y: float | None = None, gamma_c: float | None = None, sharpness: float | None = None, image_width: int | None = None, image_height: int | None = None, x_offset: int | None = None, y_offset: int | None = None, framerate_mode: str | None = None, framerate: float | None = None, downsampling_mode: str | None = None, width: int | None = None, height: int | None = None, xoffset: int | None = None, yoffset: int | None = None, exposure: float | None = None, AEAG: bool | None = None, external_trig: bool | None = None) None[source]

Opens the connection to the camera, instantiates the available settings and starts the acquisition.

Also sets custom values for the settings if provided by the user, otherwise sets them to their default.

Parameters:
  • serial_number

    A str containing the serial number of the camera to open, in case several cameras are connected. If not provided and several cameras are available, one of them will be opened randomly.

    Changed in version 2.0.0: renamed from sn to serial_number

  • timeout

    The number of milliseconds the camera is allowed to wait for an image before raising a TimeoutError, as an int. Mostly useful when using an external trigger, or a very long exposure time. The default is 5000ms.

    New in version 2.0.2.

  • trigger

    Drives the trigger status of the camera. Can be either ‘Free run’, ‘Hdw after config’, or ‘Hardware’. The default is ‘Free run’.

    New in version 2.0.0.

  • data_format

    The data format to use for acquisition as a str (e.g. ‘Mono (8 bits)’). The available formats depend on the model of the camera. This setting is only implemented for a subset of all the Ximea cameras, get in touch with the maintainers to implement in on other models.

    New in version 2.0.2.

  • exposure_time_us

    The exposure time to use for acquiring images, in µs. Only has an effect if auto_exposure_auto_gain is set to False, and if framerate_mode is not in ‘Free run’. Depending on the camera might set the target or the limit framerate. The range of values depends on the model of the driven camera. This setting is only implemented for a subset of all the Ximea cameras, get in touch with the maintainers to implement in on other models.

    New in version 2.0.2.

  • gain – The gain in dB to apply to the acquired images, as a float. Only has an effect if auto_exposure_auto_gain is set to False. The valid range of values depends on the model of the driven camera.

  • auto_exposure_auto_gain

    When set to True, overwrites the exposure_time_us and gain values and drives the exposure and the gain automatically.

    New in version 2.0.2.

  • gamma_y

    The luminosity gamma value, for color images only, as a float. The valid range of values depends on the model of the driven camera.

    New in version 2.0.2.

  • gamma_c

    The chromaticity gamma value, for color images only, as a float. The valid range of values depends on the model of the driven camera.

    New in version 2.0.2.

  • sharpness

    The sharpness strength value, for color images only, as a float. The valid range of values depends on the model of the driven camera.

    New in version 2.0.2.

  • image_width

    The width of the ROI to acquire in pixels, as an int. The valid range of values depends on the model of the driven camera, and on the downsampling_mode if supported.

    New in version 2.0.2.

  • image_height

    The height of the ROI to acquire in pixels, as an int. The valid range of values depends on the model of the driven camera, and on the downsampling_mode if supported.

    New in version 2.0.2.

  • x_offset

    The X offset of the ROI to acquire in pixels, as an int. The valid range of values depends on the model of the driven camera, on the selected width, and on the downsampling_mode if supported.

    New in version 2.0.2.

  • y_offset

    The Y offset of the ROI to acquire in pixels, as an int. The valid range of values depends on the model of the driven camera, on the selected height, and on the downsampling_mode if supported.

    New in version 2.0.2.

  • framerate_mode

    The mode for driving the acquisition framerate. Can be one of ‘Free run’, ‘Framerate target’ or ‘Framerate limit’, but not all camera models support the three options. This setting is only implemented for a subset of all the Ximea cameras, get in touch with the maintainers to implement in on other models.

    New in version 2.0.2.

  • framerate

    Either the target or the limit framerate for image acquisition, depending on the framerate_mode value, as a float. The valid range of values depends on the model of the driven camera, and on the exposure_time_us value. Only has an effect if framerate_mode is not set to ‘Free run’. This setting is only implemented for a subset of all the Ximea cameras, get in touch with the maintainers to implement in on other models.

    New in version 2.0.2.

  • downsampling_mode

    The downsampling mode to apply to the acquired images, as a str (e.g. ‘2x2’). This setting is only implemented for a subset of all the Ximea cameras, get in touch with the maintainers to implement in on other models.

    New in version 2.0.2.

  • width

    Deprecated since version 2.0.2: Use image_width instead.

  • height

    Deprecated since version 2.0.2: Use image_height instead.

  • xoffset

    Deprecated since version 2.0.2: Use x_offset instead.

  • yoffset

    Deprecated since version 2.0.2: Use y_offset instead.

  • exposure

    Deprecated since version 2.0.2: Use exposure_time_us instead.

  • AEAG

    Deprecated since version 2.0.2: Use auto_exposure_auto_gain instead.

  • external_trig

    Deprecated since version 2.0.0: Use trigger instead.

get_image() Tuple[Dict[str, Any], ndarray][source]

Reads a frame from the camera, and returns it along with its metadata.

The acquired metadata contains the following fields :

  • ‘t(s)’: The current timestamp as returned by time.time.

  • ‘DateTimeOriginal’: The current date up to the second as a valid exif tag, based on the value of ‘t(s)’.

  • ‘SubsecTimeOriginal’: The sub-second part of the current date as a valid exif tag, based on the value of ‘t(s)’.

  • ‘XimeaSec’: The number of seconds the camera has been up.

  • ‘XimeaUSec’: The decimal part of the above field, value in µs.

  • ‘ImageWidth’: The width of the acquired image, in pixels.

  • ‘ImageHeight’: The height of the acquired image, in pixels.

  • ‘ExposureTime’: The exposure time of the acquired image, in µs.

  • ‘AbsoluteOffsetX’: The offset of the acquired ROI along the X axis, in pixels.

  • ‘AbsoluteOffsetY’: The offset of the acquired ROI along the Y axis, in pixels.

  • ‘DownsamplingX’: The downsampling factor along the X axis.

  • ‘DownsamplingY’: The downsampling factor along the Y axis.

  • ‘ImageUniqueID’: The index of the acquired image, as returned by the camera.

close() None[source]

Closes the connection to the camera and releases the resources.

Parent Camera

Camera

class crappy.camera.Camera(*_, **__)[source]

Base class for every Camera object. Implements methods shared by all the Cameras, and ensures their dataclass is MetaCamera.

The Camera objects are helper classes used by the Camera Block to interface with cameras.

New in version 1.4.0.

__init__(*_, **__) None[source]

Simply sets the dict containing the settings, and the name of the reserved settings.

Here, CameraSetting can be added to the camera. It can be done using one of the add_bool_setting(), add_scale_setting(), add_choice_setting(), add_trigger_setting(), or add_software_roi() methods. Refer to the documentation of these methods for more information.

Changed in version 2.0.0: now accepts args and kwargs

log(level: int, msg: str) None[source]

Records log messages for the Camera.

Also instantiates the logger when logging the first message.

Parameters:
  • level – An int indicating the logging level of the message.

  • msg – The message to log, as a str.

New in version 2.0.0.

open(**kwargs) None[source]

This method should initialize the connection to the camera, configure the camera, and start the image acquisition.

Here, CameraSetting can be added to the camera. It can be done using one of the add_bool_setting(), add_scale_setting(), add_choice_setting(), add_trigger_setting(), or add_software_roi() methods. Refer to the documentation of these methods for more information. It is preferable to add the settings during __init__(), but this is not always possible (e.g. if values read from the camera are required to instantiate a setting).

This method takes as arguments all the kwargs that were passed to the Camera Block but not used by it. These kwargs can have two possible usages. They can be used to parametrize the method, e.g. a serial number can be given to choose which camera to open. Alternatively, they can be used for adjusting camera settings values. It is also fine not to provide any argument to this method.

When providing a value for a setting, it should be done by giving the kwarg <setting_name>=<setting_value> to the Camera Block, with <setting_name> the exact name given to the setting. It can be desirable to provide setting values here in case the display of the CameraConfig is disabled (config=False set on the Camera Block), or to gain time if the correct values are already known.

Important

To effectively set the setting values, the method set_all() must be called e.g. self.set_all(**kwargs)). It is usually called at the very end of the method. This is true even if no value to set was given in the kwargs. If set_all() is not called, the settings won’t actually be set on the camera.

New in version 1.5.10.

get_image() Tuple[Dict[str, Any] | float, ndarray] | None[source]

Acquires an image and returns it along with its metadata or timestamp.

This method should return two objects, the second being the image as a numpy array. If the first object is a float, it is considered as the timestamp associated with the image (as returned by time.time). If it is a dict, it should contain the metadata associated with the image. It is also fine for this method to return None if no image could be acquired.

If metadata is returned, it should contain at least the 't(s)' and 'ImageUniqueID' keys, containing the timestamp as a float (as returned by time.time) and the frame number as an int. Any other field can be provided. This metadata is used by the ImageSaver class and saved along with the frames if the record_images argument of the Camera Block is True. The keys should preferably be valid EXIF tags, so that the information can be embedded in the recorded images.

If only a timestamp is provided, a metadata dict is built internally but the user has no control over it.

New in version 1.5.10.

close() None[source]

This method should perform any action required for properly stopping the image acquisition and/or closing the connection to the camera.

This step is usually extremely important in order for the camera resources to be released. Otherwise, it might be impossible to re-open the camera from Crappy without resetting the hardware connection with it.

New in version 1.5.10.

add_bool_setting(name: str, getter: Callable[[], bool] | None = None, setter: Callable[[bool], None] | None = None, default: bool = True) None[source]

Adds a boolean setting, whose value is either True or False.

It creates an instance of CameraBoolSetting using the provided arguments.

If a CameraConfig window is displayed (config=True set on the Camera Block), this setting will appear as a checkbox.

Parameters:
  • name – The name of the setting, that will be displayed in the configuration window and allows to access the setting directly with self.<name>. Also the name to use for setting the value as a kwarg of the Camera Block (<name>=<value>).

  • getter – The method for getting the current value of the setting. If not given, the returned value is simply the last one that was set.

  • setter – The method for setting the current value of the setting. If not given, the value to be set is simply stored.

  • default – The default value to assign to the setting.

New in version 1.5.10.

add_scale_setting(name: str, lowest: int | float, highest: int | float, getter: Callable[[], int | float] | None = None, setter: Callable[[int | float], None] | None = None, default: int | float | None = None, step: int | float | None = None) None[source]

Adds a scale setting, whose value is an int or a float lying between two boundaries.

It creates an instance of CameraScaleSetting using the provided arguments.

If a CameraConfig window is displayed (config=True set on the Camera Block), this setting will appear as a slider.

Note

If any of lowest or highest is a float, then the setting is considered to be of type float and can take float values. Otherwise, it is considered of type int and can only take integer values.

Parameters:
  • name – The name of the setting, that will be displayed in the configuration window and allows to access the setting directly with self.<name>. Also the name to use for setting the value as a kwarg of the Camera Block (<name>=<value>).

  • lowest – The lowest possible value for the setting.

  • highest – The highest possible value for the setting.

  • getter – The method for getting the current value of the setting. If not given, the returned value is simply the last one that was set.

  • setter – The method for setting the current value of the setting. If not given, the value to be set is simply stored.

  • default – The default value to assign to the setting. If not given, will be the average of lowest and highest.

  • step

    The step value for the variation of the setting values.

    New in version 2.0.0.

New in version 1.5.10.

add_choice_setting(name: str, choices: Iterable[str], getter: Callable[[], str] | None = None, setter: Callable[[str], None] | None = None, default: str | None = None) None[source]

Adds a choice setting, that can take a limited number of predefined str values.

It creates an instance of CameraChoiceSetting using the provided arguments.

If a CameraConfig window is displayed (config=True set on the Camera Block), this setting will appear as a set of radio buttons.

Parameters:
  • name – The name of the setting, that will be displayed in the configuration window and allows to access the setting directly with self.<name>. Also the name to use for setting the value as a kwarg of the Camera Block (<name>=<value>).

  • choices – An iterable (like a tuple or a list) containing the possible values for the setting.

  • getter – The method for getting the current value of the setting. If not given, the returned value is simply the last one that was set.

  • setter – The method for setting the current value of the setting. If not given, the value to be set is simply stored.

  • default – The default value to assign to the setting. If not given, will be the fist item in choices.

New in version 1.5.10.

add_trigger_setting(getter: Callable[[], str] | None = None, setter: Callable[[str], None] | None = None) None[source]

Adds a specific setting for controlling the trigger mode of the camera. The reserved name for this setting is 'trigger'.

It creates an instance of CameraChoiceSetting using a reserved name, and predefined choices and default.

This setting is mainly intended for cameras that can run either in free run mode or in hardware trig mode. The three possible choices for this setting are :

'Free run', 'Hdw after config', 'Hardware'

Default is 'Free run'.

The setter method is expected to set the camera to free run mode in 'Free run' and 'Hdw after config' choices, and to hardware trigger mode in the 'Hardware' choice. The getter method should return either 'Free run' or 'Hdw after config' in free run mode, depending on the last set value for the setting, and 'Hardware' in hardware trig mode. It can also be left to None.

The rationale behind the 'Hdw after config' choice is to allow the user to tune settings in the CameraConfig window with the camera in free run mode, and to switch afterward to the hardware trigger mode once the test begins. It proves extremely useful if the hardware triggers are generated from Crappy, as they’re not started yet when the configuration window is running.

Parameters:
  • getter – The method for getting the current value of the setting. If not given, the returned value is simply the last one that was set.

  • setter – The method for setting the current value of the setting. If not given, the value to be set is simply stored.

New in version 2.0.0.

add_software_roi(width: int, height: int) None[source]

Creates the settings needed for generating a software ROI.

The ROI is a rectangular area defining which part of the image to keep and return to the Camera Block. It can be tuned by the user by setting the position of the upper left corner as well as the width and the height of the rectangular box.

Using a ROI reduces the size of the image for processing, displaying and saving, which improves the overall performance.

This method creates instances of CameraScaleSetting using reserved names, and predefined choices and default. It takes as arguments the dimensions of the un-cropped image, so that it can adjust the boundaries of the sliders. These boundaries can later be adjusted using the reload_software_roi() method.

The reserved names for the instantiated settings are 'ROI_x', 'ROI_y', 'ROI_width', and 'ROI_height', respectively for the x and y position of the upper-left corner of the ROi and for the width and height of the ROI.

Important

To apply the ROI and crop the image to return, it is necessary to call the apply_soft_roi() method. Example :

...
frame = self._cam.read()
return time.time(), self.apply_soft_roi(img)
Parameters:
  • width – The width of the acquired images, in pixels.

  • height – The height of the acquired images, in pixels.

New in version 2.0.0.

reload_software_roi(width: int, height: int) None[source]

Updates the software ROI boundaries when the width and/or the height of the acquired images change.

The add_software_roi() method should have been called before calling this method.

Parameters:
  • width – The width of the acquired images, in pixels.

  • height – The height of the acquired images, in pixels.

New in version 2.0.0.

apply_soft_roi(img: ndarray) ndarray | None[source]

Takes an image as an input, and crops according to the selected software ROI dimensions.

Might return None in case there’s no pixel left on the cropped image. Returns the original image if the software ROI settings were not defined using add_software_roi().

New in version 2.0.0.

set_all(**kwargs) None[source]

Sets all the setting values on the camera.

The provided keys of the kwargs should be the names of valid CameraSetting, otherwise an error is raised.

For settings that are given in the kwargs, sets them to the given corresponding value. For the other settings, sets them to their default value.

This method should be called during the open() method, once the communication with the camera is established and the settings are instantiated. It is usually called at the very end of the method.

__getattr__(item: str) Any[source]

Method for getting the value of a setting directly by calling self.<setting name>.

It is called in case __getattribute__() doesn’t work properly, and tries to return the corresponding setting value.

__setattr__(key: str, val: Any) None[source]

Method for setting the value of a setting directly by calling self.<setting name> = <value>.

Meta Camera

class crappy.camera.MetaCamera(name: str, bases: tuple, dct: dict)[source]

Metaclass ensuring that two cameras don’t have the same name, and that all cameras define the required methods. Also keeps track of all the Camera classes, including the custom user-defined ones.

New in version 1.4.0.

Changed in version 1.5.10: not checking anymore for mandatory methods in __init__()

__init__(name: str, bases: tuple, dct: dict) None[source]

Camera Settings

Camera Setting

class crappy.camera.meta_camera.camera_setting.CameraSetting(name: str, getter: Callable[[], Any], setter: Callable[[Any], None], default: Any)[source]

Base class for each Camera setting.

It is meant to be subclassed and should not be used as is.

The Camera setting classes hold all the information needed to read and set a setting of a Camera object. Several types of settings are defined, as children of this class : CameraBoolSetting, CameraChoiceSetting, and CameraScaleSetting.

New in version 1.4.0.

Changed in version 2.0.0: renamed from Camera_setting to CameraSetting

__init__(name: str, getter: Callable[[], Any], setter: Callable[[Any], None], default: Any) None[source]

Sets the attributes.

Parameters:
  • name – The name of the setting, that will be displayed in the GUI.

  • getter – The method for getting the current value of the setting.

  • setter – The method for setting the current value of the setting.

  • default – The default value to assign to the setting.

log(level: int, msg: str) None[source]

Records log messages for the CameraSetting.

Also instantiates the logger when logging the first message.

Parameters:
  • level – An int indicating the logging level of the message.

  • msg – The message to log, as a str.

New in version 2.0.0.

property value: Any

Returns the current value of the setting, by calling the getter if one was provided or else by returning the stored value.

When the getter is called, calls the setter if one was provided and updates the sored value. After calling the setter, checks that the value was set by calling the getter and displays a warning message if the target and actual values don’t match.

reload(*_, **__) None[source]

Allows modifying a setting once it is already being displayed in the GUI.

Mostly helpful for adjusting the ranges of sliders.

New in version 2.0.0.

Camera Bool Setting

class crappy.camera.meta_camera.camera_setting.CameraBoolSetting(name: str, getter: Callable[[], bool] | None = None, setter: Callable[[bool], None] | None = None, default: bool = True)[source]

Camera setting that can only be True or False.

It is a child of CameraSetting.

New in version 1.5.10.

Changed in version 2.0.0: renamed from Camera_bool_setting to CameraBoolSetting

__init__(name: str, getter: Callable[[], bool] | None = None, setter: Callable[[bool], None] | None = None, default: bool = True) None[source]

Sets the attributes.

Parameters:
  • name – The name of the setting, that will be displayed in the GUI.

  • getter – The method for getting the current value of the setting.

  • setter – The method for setting the current value of the setting.

  • default – The default value to assign to the setting.

Camera Choice Setting

class crappy.camera.meta_camera.camera_setting.CameraChoiceSetting(name: str, choices: Tuple[str, ...], getter: Callable[[], str] | None = None, setter: Callable[[str], None] | None = None, default: str | None = None)[source]

Camera setting that can take any value from a predefined list of values.

It is a child of CameraSetting.

New in version 1.5.10.

Changed in version 2.0.0: renamed from Camera_choice_setting to CameraChoiceSetting

__init__(name: str, choices: Tuple[str, ...], getter: Callable[[], str] | None = None, setter: Callable[[str], None] | None = None, default: str | None = None) None[source]

Sets the attributes.

Parameters:
  • name – The name of the setting, that will be displayed in the GUI.

  • choices – A tuple listing the possible values for the setting.

  • getter – The method for getting the current value of the setting.

  • setter – The method for setting the current value of the setting.

  • default – The default value to assign to the setting.

reload(choices: Tuple[str, ...], default: str | None = None) None[source]

Allows modifying the choices of the radio buttons once they have been instantiated.

As the layout of the GUI is already fixed, the number of displayed options cannot vary. It is thus not possible to propose more choices than those initially proposed. Reversely, if fewer new options ar proposed then some radio buttons won’t be affected a value.

New in version 2.0.0.

Camera Scale Setting

class crappy.camera.meta_camera.camera_setting.CameraScaleSetting(name: str, lowest: int | float, highest: int | float, getter: Callable[[], int | float] | None = None, setter: Callable[[int | float], None] | None = None, default: int | float | None = None, step: int | float | None = None)[source]

Camera setting that can take any value between a lower and an upper boundary.

It is a child of CameraSetting.

This class can handle settings that should only take int values as well as settings that can take float value. The type used is int is both of the given lowest or highest values are int, otherwise float is used.

New in version 1.5.10.

Changed in version 2.0.0: renamed from Camera_scale_setting to CameraScaleSetting

__init__(name: str, lowest: int | float, highest: int | float, getter: Callable[[], int | float] | None = None, setter: Callable[[int | float], None] | None = None, default: int | float | None = None, step: int | float | None = None) None[source]

Sets the attributes.

Parameters:
  • name – The name of the setting, that will be displayed in the GUI.

  • lowest – The lower boundary for the setting values.

  • highest – The upper boundary for the setting values.

  • getter – The method for getting the current value of the setting.

  • setter – The method for setting the current value of the setting.

  • default – The default value to assign to the setting.

  • step – The step value for the variation of the setting values.

New in version 2.0.0: add step argument

property value: int | float

Returns the current value of the setting, by calling the getter if one was provided or else by returning the stored value.

When the getter is called, calls the setter if one was provided and updates the sored value. After calling the setter, checks that the value was set by calling the getter and displays a warning message if the target and actual values don’t match.

reload(lowest: int | float, highest: int | float, value: int | float, default: int | float | None = None, step: int | float | None = None) None[source]

Allows modifying the limits and the step of the scale bar once it is already instantiated.

New in version 2.0.0.