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: Optional[Callable] = None, setter: Callable = <function Camera.<lambda>>, limits: Union[None, tuple, bool, dict] = None, default: Optional[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.

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: 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]

Camera class for webcams, read using opencv.

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.

Ximea CV

class crappy.camera.ximeaCV.Ximea_cv[source]

Camera class for ximeas using openCV.

Note

It requires cv2 3.0 or higher, compiled with WITH_XIMEA flag.

__str__() str[source]

Method to prints out main parameter.

Returns

A formatted string with the value of the main parameter.

Example

>>> camera = Ximea_cv(numdevice=0)
>>> camera.new(exposure=10000, width=2048, height=2048)
>>> print camera

these lines will print out:

Exposure: 10000
Numdevice: 0
Width: 2048
Height: 2048
X offset: 0
Y offset: 0
close() None[source]

This method close properly the frame grabber.

Returns

void return function.

get_image() tuple[source]

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

If the camera breaks down, it reinitializes it, and tries again.

Returns

frame from ximea device (ndarray height*width).

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

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

reopen(**kwargs) None[source]

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