Cameras — Crappy 1.5.3 documentation

# Cameras

## Bispectral

class crappy.camera.bispectral.Bispectral(**kwargs)
  get_ambiant_temperature()

    Returns temperature of the board in °C.

  get_sensor_temperature()

    Returns sensor temperature in Kelvin.

  open(**kwargs)

    Opens the camera.

  set_external_trigger(val)

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

crappy.camera.bispectral.calc_string(st, crc)

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

## Meta Camera

class crappy.camera.camera.Cam_setting(name, getter, setter, limits, default)

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

  __init__(name, getter, setter, limits, default)

    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

  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)

    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, val)

    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, getter=None, setter=<function Camera.<lambda>>, limits=None, default=None)

    Wrapper to simply add a new setting to the camera.

  property available_settings

    Returns a `list` of available settings.

  read_image()

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

  reset_all()

    Reset all the settings to their default values.

  set_all(override=False, **kwargs)

    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

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

class crappy.camera.camera.MetaCam(name, bases, dict_)

  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 link

class crappy.camera.cameralink.Cl_camera(numdevice=0, config_file=None, camera_type=None)

  Cameralink camera sensor.

  __init__(numdevice=0, config_file=None, camera_type=None)

    Using the clModule, will open a cameraLink camera.

    Note

    If a config file is specified, it will be used to configure the camera.

    If not set, it will be asked, unless set to `False` (or 0).

    Else, you must at least provide the camera type (eg: “FullAreaGray8”).

    Using a config file is recommended over changing all settings manually.

  configure()

    Configure the frame grabber to trig the camera internally.

  open(**kwargs)

    Opens the camera.

## Fake Camera

class crappy.camera.fakeCamera.Fake_camera

  Fake camera sensor object.

  open(**kwargs)

    Opens the fake camera.

## JAI

class crappy.camera.jai.Jai(**kwargs)

  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()

    Opens the camera.

class crappy.camera.jai.Jai8(**kwargs)

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

  This one uses FullAreaGray8 module for maximum framerate.

  open(**kwargs)

    Opens the camera.

## PiCamera

class crappy.camera.picamera_picamera.Picamera

  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 !

  __init__() → None

    Instantiates the available settings.

  close() → None

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

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

    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

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

## PiCamera - Webcam

class crappy.camera.picamera_webcam.Picamera_webcam

  Class for reading images from a PiCamera.

  The Picamera_webcam Camera block is meant for reading images from a Picamera. It relies on `cv2` and the V4L2 API just like the Webcam block, hence its name. The only differences with the Webcam block are that here the height and width must be multiples of 32, and the resolution limits are those of the Picamera.

  Note

  Actually works with any camera, not only the Picamera.

  close() → None

    Releases the resources and joins the thread.

  get_image() → Tuple[float, Any]

    Reads an image from the PiCamera using V4L2.

    Returns

      The timeframe and the image

  open(**kwargs: Any) → None

    Sets the settings to their default values and starts buffering images.

## Seek Thermal Pro

class crappy.camera.seek_thermal_pro.Seek_thermal_pro

  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

    Selects the right USB device.

  close() → None

    Resets the camera and releases USB resources.

  get_image() → Tuple[float, numpy.array]

    Reads a single image from the camera.

    Returns

      The timeframe and the captured image

  open() → None

    Sets the USB communication and device.

## Streamer

class crappy.camera.streamer.Streamer

  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, pattern='img_\\d+_(\\d+\\.\\d+)\\.tiff', start_delay=0, modifier=<function Streamer.<lambda>>)

    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

  Camera class for webcams, read using opencv.

## Xi API

class crappy.camera.xiapi.Xiapi

  Camera class for ximeas using official XiAPI.

  close()

    This method closes properly the camera.

    Returns

      void return function.

  get_image()

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

    Returns

      frame from ximea device (ndarray height*width).

  open(sn=None, **kwargs)

    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)

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

## Ximea CV

class crappy.camera.ximeaCV.Ximea_cv

  Camera class for ximeas using openCV.

  Note

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

  __str__()

    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()

    This method close properly the frame grabber.

    Returns

      void return function.

  get_image()

    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=0, **kwargs)

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

  reopen(**kwargs)

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