Cameras

Bispectral

class crappy.camera.bispectral.Bispectral(**kwargs)[source]
get_ambiant_temperature() float[source]

Returns temperature of the board in °C.

get_sensor_temperature() float[source]

Returns sensor temperature in Kelvin.

open(**kwargs) None[source]

Opens the camera.

set_external_trigger(val) None[source]

Sets the external trigger to val by toggling the value of the 3rd bit of register 102.

crappy.camera.bispectral.calc_string(st: str, crc: int) int[source]

Given a binary string and starting CRC, Calc a final CRC-16.

Meta Camera

class crappy.camera.camera.Cam_setting(name: str, getter: Callable, setter: Callable, limits: Union[None, tuple, bool, dict], default: Any)[source]

This class represents an attribute of the camera that can be set.

__init__(name: str, getter: Callable, setter: Callable, limits: Union[None, tuple, bool, dict], default: Any) None[source]

Sets the instance attributes.

Parameters
  • name – The name of the setting.

  • default – The default value, if not specified it will be set to this value.

  • getter – Function to read this value from the device. If set to None, it will assume that the setting always happened correctly.

  • setter – A function that will be called when setting the parameter to a new value. Can do nothing, it will only change its value and nothing else.

  • limits

    It contains the available values for this parameter.

    The possible limit types are:

    • None: Values will not be tested and the parameter will not appear in CameraConfig.

    • A tuple of 2 int or float: Values must be between first and second value. CameraConfig will add a scale widget to set it. If they are integers, all the integers between them will be accessible, if they are floats, the range will be divided in 1000 in the scale widget.

      Note that if the upper value is callable (a function or method), it will be set to the return value of this function. It allows reading the max value from the device.

    • A bool: Possible values will be True or False, CameraConfig will add a checkbox to edit the value (default can be True or False, it doesn’t matter).

    • A dict: Possible values are the values of the dict, CameraConfig will add radio buttons showing the keys, to set it to the corresponding value.

class crappy.camera.camera.Camera[source]

This class represents a camera sensor.

It may have settings: They represent all that can be set on the camera: height, width, exposure, AEAG, external trigger, etc…

Note

Each parameter is represented by a Cam_setting object: it includes the default value, a function to set and get parameter, etc…

This class makes it transparent to the user: you can access a setting by using myinstance.setting = stuff.

It will automatically check the validity and try to set it (see Cam_setting).

Don’t forget to call the __init__() in the children or __getattr__() will fall in an infinite recursion loop looking for settings…

__getattr__(i: str) Any[source]

The idea is simple: if the camera has this attribute: return it (default behavior) else, try to find the corresponding setting and return its value.

Note that we made sure to raise an AttributeError if it is neither a camera attribute nor a setting.

Example

If Camera definition contains self.add_setting("width",1280,set_w), and cam = Camera(), then cam.width will return 1280.

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

Same as __getattr__(): if it is a setting, then set its value using the setter in the Cam_setting, else use the default behavior.

It is important to make sure we don’t try to set ‘settings’, it would recursively call __getattr__() and enter an infinite loop, hence the condition.

Example

cam.width = 2048 will be like cam.settings['width'].value = 2048. It allows for simple settings of the camera.

add_setting(name: str, getter: typing.Optional[typing.Callable] = None, setter: typing.Callable = <function Camera.<lambda>>, limits: typing.Union[None, tuple, bool, dict] = None, default: typing.Optional[typing.Any] = None) None[source]

Wrapper to simply add a new setting to the camera.

property available_settings: list

Returns a list of available settings.

read_image() tuple[source]

This method is a wrapper for get_image() that will limit fps to max_fps.

reset_all() None[source]

Reset all the settings to their default values.

set_all(override: bool = False, **kwargs) None[source]

Sets all the settings based on kwargs.

Note

If not specified, the setting will take its default value.

If override is True, it will not assume a setting and reset it unless it is already default.

property settings_dict: dict

Returns settings as a dict, keys are the names of the settings and values are setting.value.

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

Metaclass that will define all cameras.

Note

Camera classes should be of this type.

To do so, simply add __metaclass__ = MetaCam in the class definition. (Obviously, you must import this Metaclass first.)

MetaCam is a MetaClass: We will NEVER do c = MetaCam(...).

The __init__() is used to init the classes of type MetaCam (with __metaclass__ = MetaCam as a class attribute) and NOT an instance of MetaClass.

Camera GStreamer

class crappy.camera.gstreamer.Camera_gstreamer[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. In this case, the user has access to a range of parameters for tuning the image. Alternatively, it is possible to give a custom GStreamer pipeline to the block. 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 Camera OpenCV camera, that relies on OpenCV. The installation of GStreamer of however less straightforward than the one of OpenCV.

Note

For a better performance of this class in Linux, it is recommended to have v4l-utils installed.

__init__() None[source]

Simply initializes the instance attributes.

close() NoReturn[source]

Simply stops the image acquisition.

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

Reads the last image acquired from the camera.

Returns

The acquired image, along with a timestamp.

open(device: Optional[Union[int, str]] = None, user_pipeline: Optional[str] = None, nb_channels: Optional[int] = None, img_depth: Optional[int] = None, **kwargs) NoReturn[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 (str, optional) – A custom pipeline that can optionally be given. If given, the device argument is ignored. The pipeline should be given as it would be in a terminal.

  • nb_channels (int, optional) – 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 (int, optional) – 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 graphical interface.

Camera OpenCV

class crappy.camera.opencv.Camera_opencv[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. It is then also possible to tune the encoding format and the size.

This camera class is less performant than the Camera GStreamer one that relies on GStreamer, but the installation of OpenCv is way easier than the one of GStreamer.

Note

For a better performance of this class in Linux, it is recommended to have v4l-utils installed.

__init__() None[source]

Sets variables and adds the channels setting.

close() NoReturn[source]

Releases the videocapture object.

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

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

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

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

Parameters
  • device_num (int, optional) – The number of the device to open.

  • **kwargs – Any additional setting to set before opening the graphical interface.

Fake Camera

class crappy.camera.fakeCamera.Fake_camera[source]

Fake camera sensor object.

open(**kwargs) None[source]

Opens the fake camera.

JAI

class crappy.camera.jai.Jai(**kwargs)[source]

This class allows the use of 10 and 12 bits mode for the Jai Cameras. Obviously, the framerate will be slower than the 8 bits version.

open() None[source]

Opens the camera.

class crappy.camera.jai.Jai8(**kwargs)[source]

This class supports Jai GO-5000-PMCL gray cameras.

This one uses FullAreaGray8 module for maximum framerate.

open(**kwargs) None[source]

Opens the camera.

PiCamera

class crappy.camera.pi_camera.Picamera[source]

Class for reading images from a PiCamera.

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

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.

__init__() None[source]

Instantiates the available settings.

close() None[source]

Joins the thread and closes the stream and the picamera.PiCamera object.

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

Simply returns the last image in the buffer.

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

Returns

The timeframe and the image.

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

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

Seek Thermal Pro

class crappy.camera.seek_thermal_pro.Seek_thermal_pro[source]

Class for reading the Seek Thermal Pro infrared camera.

The Seek_thermal_pro Camera block 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.

__init__() None[source]

Selects the right USB device.

close() None[source]

Resets the camera and releases USB resources.

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

Reads a single image from the camera.

Returns

The timeframe and the captured image

open() None[source]

Sets the USB communication and device.

Streamer

class crappy.camera.streamer.Streamer[source]

This is a fake sensor meant to stream images that were already saved.

Note

It needs a way to locate the time of each frame in the name of the picture. This is done using regular expressions.

__init__() takes no args, the arguments must be given when calling open() (like all cameras).

open(path: str, pattern: str = 'img_\\d+_(\\d+\\.\\d+)\\.tiff', start_delay: float = 0, modifier: typing.Callable = <function Streamer.<lambda>>) None[source]

Sets the instance arguments.

Parameters
  • path (str) – The path of the folder containing the images.

  • pattern (str, optional) –

    The regular expression matching the images and returning the time.

    ..Note::

    ”d” matches digits, “d+” matches a group of digits. () is a capturing group, returning what is inside. Dot is a special character and needs to be escaped. The default value is compatible with the naming method of the Camera and VideoExtenso blocks.

  • start_delay (float, optional) –

    Before actually streaming the image flux you can set a delay in seconds during which the first image will be streamed in a loop.

    ..Note::

    This can be useful to give time for spot selection when using videoextenso.

  • modifier – To apply a function to the image before sending it.

Webcam

class crappy.camera.webcam.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 Camera OpenCV and Camera GStreamer for classes giving a finer control over the device.

__init__() None[source]

Sets variables and adds the channels setting.

close() NoReturn[source]

Releases the videocapture object.

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

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

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

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

Parameters
  • device_num (int, optional) – The number of the device to open.

  • **kwargs – Any additional setting to set before opening the graphical interface.

Xi API

class crappy.camera.xiapi.Xiapi[source]

Camera class for ximeas using official XiAPI.

close() None[source]

This method closes properly the camera.

Returns

void return function.

get_image() tuple[source]

This method get a frame on the selected camera and return a ndarray.

Returns

frame from ximea device (ndarray height*width).

open(sn: Optional[str] = None, **kwargs) None[source]

Will actually open the camera, args will be set to default unless specified otherwise in kwargs.

If sn is given, it will open the camera with the corresponding serial number.

Else, it will open any camera.

reopen(**kwargs) None[source]

Will reopen the camera, args will be set to default unless specified otherwise in kwargs.