Camera control#

class hs.control.Camera(input)#

The camera interface type.

This type can represent either a real camera (through a TCP or GigE connection) or a simulated image-based camera.

classmethod __new__(*args, **kwargs)#
get_analog_gain()#

Get Analog gain

Returns:

Analog gain

Return type:

float

get_bands()#

Get the current band selection.

Each entry is either a single band index (int), a band range (start, end), or a stepped band range (start, end, step).

Returns:

List of band selections.

Return type:

list[int | tuple[int, int] | tuple[int, int, int]]

get_bit_mode()#

Get the current bit mode.

Returns:

The current bit mode as bits (8, 10, or 12).

Return type:

int

get_config()#

Get the hyperspectral camera configuration.

Returns:

The configuration object.

Return type:

HSCameraConfig

get_crop()#

Get the current crop settings.

The returned object exposes max_width, max_height, current_width, and current_height attributes, all measured in pixels (the height values are bands).

Returns:

The current crop information.

Return type:

object

get_exposure()#

Get the exposure time in microseconds.

Returns:

Exposure time in microseconds.

Return type:

int

get_framerate()#

Get the current framerate.

Returns:

The framerate.

Return type:

float

get_framerate_list()#

Get the possible framerates.

Returns:

Either a min/max framerate range or a list of possible discrete values.

Return type:

dict | list

get_horizontal_binning()#

Get the horizontal binning factor.

Returns:

The current horizontal binning factor.

Return type:

int

get_vertical_binning()#

Get the vertical binning factor.

Returns:

The current vertical binning factor.

Return type:

int

get_wavelengths()#

Get the wavelengths of the camera’s spectral bands.

Returns:

List of wavelengths in nanometers.

Return type:

list[float]

set_analog_gain(value)#

Set Analog gain

Parameters:

value (float) – The new analog gain

Returns:

Analog gain

Return type:

float

set_bands(value)#

Set the bands configuration.

Each entry is either a single band index (int), a band range (start, end), or a stepped band range (start, end, step).

Parameters:

value (list[int | tuple[int, int] | tuple[int, int, int]]) – The new band selections.

Returns:

The actual set band selections.

Return type:

list[int | tuple[int, int] | tuple[int, int, int]]

set_bit_mode(bit_mode)#
set_config(value)#

Set the hyperspectral camera configuration.

Parameters:

value (HSCameraConfig) – The new configuration.

Returns:

The actual set configuration.

Return type:

HSCameraConfig

set_exposure(value)#

Set the exposure time.

Parameters:

value (int) – The new exposure time in microseconds.

Returns:

The actual set value.

Return type:

int

set_framerate(value)#

Set the current framerate.

Parameters:

value (float) – The desired framerate.

Returns:

The framerate that was set on the camera.

Return type:

float

set_horizontal_binning(value)#

Set the horizontal binning factor.

Parameters:

value (int) – The desired horizontal binning factor.

Returns:

The actual horizontal binning factor set on the camera.

Return type:

int

set_horizontal_crop(start, end)#

Set the horizontal crop boundaries.

Parameters:
  • start (int) – The start position of the crop.

  • end (int) – The end position of the crop.

Returns:

The actual set horizontal crop.

Return type:

HorizontalCrop

set_vertical_binning(value)#

Set the vertical binning factor.

Parameters:

value (int) – The desired vertical binning factor.

Returns:

The actual vertical binning factor set on the camera.

Return type:

int

stream(n_frames=None)#

Start camera stream.

Returns once the camera has accepted the connection and is streaming, so a camera that cannot start raises here rather than yielding a stream that ends immediately. A camera that has just stopped a stream needs a moment to release the video device; this waits that out, so back-to-back CameraStream.stop()/stream() pairs need no delay in between, at the cost of the call occasionally taking a second to return.

Buffering is configured on the camera through stream_options, so it applies to pipelines built from this camera too, not just to streams started here.

Parameters:

n_frames (Optional[int]) – If set, the stream delivers at most this many frames before terminating on its own. Unless the stream is buffered with on_full="block", frames can be evicted or skipped along the way, so the delivered frames are not necessarily consecutive. If None (the default), the stream runs until CameraStream.stop() is called.

to_hs_image()#

Convert to Image.

Returns:

Hyperspectral image.

Return type:

Image

__module__ = 'builtins'#
stream_options#

The buffering configuration used by every stream this camera starts.

This covers stream() as well as streams driven by an Image pipeline built from this camera, which have no other way to pass options.

The returned object is a live view of the camera’s configuration, so individual fields can be assigned through it:

cam.stream_options.capacity = 64

Assigning the property itself copies the values across, which is the convenient way to change several at once:

cam.stream_options = control.StreamOptions(capacity=64, on_full="block")
Type:

StreamOptions

class hs.control.CameraStream#

Type representing a regular two-dimensional frame stream.

__enter__()#
__exit__(_exc_type, _exc_value, _traceback)#
__iter__()#

Implement iter(self).

__next__()#

Implement next(self).

dropped()#

Number of frames discarded locally because the buffer was full and the consumer had fallen behind.

Always 0 for a buffered stream started with on_full="block". An unbuffered stream also counts the older frames each read skips. This is unrelated to FrameMeta.dropped, which reports frames lost between the camera and the host.

Return type:

int

get_frame()#

Get a single frame from the stream.

Returns:

The frame data as a 2D Numpy array and metadata.

Return type:

tuple[FrameMeta, numpy.ndarray] | None

Raises:

TimeoutError – If no frame arrives within wait_timeout. The stream keeps running, so the call can be retried.

stop()#

Stop the stream.

__module__ = 'builtins'#
class hs.control.HSCameraConfig#

Configuration options of a given camera.

These include invariants of the spectrograph and calibration parameters.

__repr__()#

Return repr(self).

__str__()#

Return str(self).

__module__ = 'builtins'#
calibration#

Calibration parameters.

spectrograph#

Spectrograph invariants.

class hs.control.HSCameraSettings#
__repr__()#

Return repr(self).

__str__()#

Return str(self).

__module__ = 'builtins'#
bands#
exposure#
horizontal_binning#
horizontal_crop#
vertical_binning#
class hs.control.HorizontalCrop#

Horizontal cropping descriptor.

__repr__()#

Return repr(self).

__str__()#

Return str(self).

__module__ = 'builtins'#
end#

End pixel position.

start#

Start pixel position.

hs.control.list_devices(address)#
class hs.control.StreamOptions(*, buffered=None, capacity=None, wait_timeout=None, on_full=None)#

How a camera buffers frames for its consumer.

Obtained from Camera.stream_options, where it is a live view of that camera’s configuration: assigning a field takes effect immediately. Constructing one directly gives a detached value, useful for assigning several settings at once.

buffered#

Deliver frames oldest-first (FIFO).

Type:

bool

capacity#

Number of frames the buffer holds.

Type:

int

on_full#

What to do when the buffer is full, either "block" or "evict".

Type:

str

wait_timeout#

How long a read waits for a frame before raising TimeoutError, which usually means the camera has stalled.

Type:

datetime.timedelta