slmsuite.hardware.cameras.thorlabs.ThorCam
- class ThorCam(serial='', verbose=True, **kwargs)[source]
Bases:
Camera
Thorlabs camera.
- profile
Current operation mode.
‘free’ means always capturing.
‘single’ means only gets frame on command.
‘single_hardware’ means only gets frame on hardware trigger or command.
None means camera is disarmed.
- Type
{‘free’, ‘single’, ‘single_hardware’} or None
Methods
Sets the exposure of the camera such that the maximum value is at
set_fraction
of the dynamic range.Uses an FFT contrast metric to find optimal focus when scanning over some variable
z
.See
Camera.close()
.Close the TLCameraSDK instance.
See
Camera.flush()
.See
Camera.get_image()
.Grab
image_count
images in succession.Discovers all Thorlabs scientific cameras.
Determine whether or not the camera is currently capturing images.
See
Camera.reset()
.Set the binning of the camera.
See
Camera.set_woi()
.Set operation mode.
Attributes
- __init__(serial='', verbose=True, **kwargs)[source]
Initialize camera and attributes. Initial profile is
"single"
.- Parameters
serial (str) – Serial number of the camera to open. If empty, defaults to the first camera in the list returned by
TLCameraSDK.discover_available_cameras()
.verbose (bool) – Whether or not to print extra information.
kwargs – See
Camera.__init__()
for permissible options.
- Raises
RuntimeError – If the camera can not be reached.
- close(close_sdk=False)[source]
See
Camera.close()
.- Parameters
close_sdk (bool) – Whether or not to close the TLCameraSDK instance.
- static info(verbose=True)[source]
Discovers all Thorlabs scientific cameras.
- Parameters
verbose (bool) – Whether to print the discovered information.
- Returns
List of ThorCam serial numbers.
- Return type
list of str
- reset()[source]
See
Camera.reset()
.
- set_binning(bx=None, by=None)[source]
Set the binning of the camera. Will error if a certain binning is not supported.
- Parameters
bx (int) – The binning value in the horizontal direction.
by (int) – The binning value in the vertical direction.
- set_woi(woi=None)[source]
See
Camera.set_woi()
.
- get_image(timeout_s=0.1, trigger=True, grab=True, attempts=1)[source]
See
Camera.get_image()
. By defaulttrigger=True
andgrab=True
which will result in blocking image acquisition. For non-blocking acquisition, settrigger=True
andgrab=False
to issue a software trigger; then, call the method again withtrigger=False
andgrab=True
to grab the resulting frame.- Parameters
trigger (bool) – Whether or not to issue a software trigger.
grab (bool) – Whether or not to grab the frame (blocking).
- Returns
Array of shape
shape
ifgrab=True
, elseNone
.- Return type
numpy.ndarray or None
- flush(timeout_s=1, verbose=False)[source]
See
Camera.flush()
.- Parameters
verbose (bool) – Whether or not to print extra information.
- is_capturing()[source]
Determine whether or not the camera is currently capturing images.
- Returns
Whether or not the camera is actively capturing images.
- Return type
bool
- autoexposure(set_fraction=0.5, tol=0.05, exposure_bounds_s=None, window=None, average_count=5, timeout_s=5, verbose=True)[source]
Sets the exposure of the camera such that the maximum value is at
set_fraction
of the dynamic range. Useful for mitigating deleterious over- or under- exposure.- Parameters
set_fraction (float) – Fraction of camera dynamic range to target image maximum.
tol (float) – Fractional tolerance for exposure adjustment.
exposure_bounds_s ((float, float) OR None) – Shortest and longest allowable integration in seconds. If
None
, defaults toexposure_bounds_s
. If this attribute was not set (or not availible on a particular camera), thenNone
instead defaults to unbounded.window (array_like or None) – See
window
. IfNone
, the full camera frame will be used.average_count (int) – Number of frames to average intensity over for noise reduction.
timeout_s (float) – Stop attempting to autoexpose after
timeout_s
seconds.verbose (bool) – Whether to print exposure updates.
- Returns
Resulting exposure in seconds.
- Return type
float
- autofocus(z_get, z_set, z_list=None, plot=False)[source]
Uses an FFT contrast metric to find optimal focus when scanning over some variable
z
. Thisz
often takes the form of a vertical stage to position a sample precisely at the plane of imaging of a lens or objective. The contrast metric works particularly well when combined with a projected spot array hologram.- Parameters
z_get (lambda) – Gets the current position of the focusing stage. Should return a
float
.z_set (lambda) – Sets the position of the focusing stage to a given
float
.z_list (array_like or None) –
z
values to sweep over during search. Defaults (whenNone
) tonumpy.linspace(-4,4,16)
.plot (bool) – Whether to provide illustrative plots.
- get_images(image_count, flush=False)[source]
Grab
image_count
images in succession. Overwrite this implementation if a camera supports faster batch acquisition.- Parameters
image_count (int) – Number of images to grab.
flush (bool) – Whether to flush before grabbing.
- Returns
Array of shape
(image_count, height, width)
.- Return type
numpy.ndarray