Cameras
Bispectral
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 2int
orfloat
: 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 beTrue
orFalse
, CameraConfig will add a checkbox to edit the value (default can beTrue
orFalse
, 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)
, andcam = Camera()
, thencam.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 theCam_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 likecam.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.
- read_image() tuple [source]
This method is a wrapper for
get_image()
that will limit fps to max_fps.
- 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 doc = 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: int = 0, config_file: Optional[str] = None, camera_type: Optional[str] = None)[source]
Cameralink camera sensor.
- __init__(numdevice: int = 0, config_file: Optional[str] = None, camera_type: Optional[str] = None) None [source]
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.
Fake Camera
JAI
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, andcv2
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.
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
.
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 callingopen()
(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
Xi API
- class crappy.camera.xiapi.Xiapi[source]
Camera class for ximeas using official XiAPI.
- 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).
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
- 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).