camazing package

Submodules

camazing.core module

exception camazing.core.AcquisitionException

Bases: Exception

class camazing.core.Camera(device_info)

Bases: object

dump_feature_info(filepath, overwrite=False, **kwargs)

Dump all feature info from the camera to a configuration file.

If no filepath is passed as a parameter, the functions tries to write the file to the default location. The existing file won’t be overwritten unless the overwrite parameter is set to True.

Parameters
  • filepath (str or None, optional) – A file path where the file will be written.

  • overwrite (bool) – True if one wishes to overwrite the existing file.

  • **kwargs – Keyword arguments for selecting features to dump using get_features.

features()

Get a view of feature objects.

Returns

A view of feature objects.

Return type

dict_values

Notes

This is same as values() in regular dictionaries. The features name is used to avoid confusion, that values() would return the actual values of the features.

finalize()

Free the camera resources.

Stops the acquisition if it’s not already stopped. Also disconnect the node map and close the connection to the device.

get_features(feature_types=<class 'camazing.feature_types.Feature'>, access_modes=['', 'w', 'r', 'rw'], pattern='')

Return a filtered list of feature names.

Parameters
  • feature_types (list) – List of feature types to include. See camazing.feature_types for valid values.

  • access_modes (list of str) – Access modes to have in the result.

  • pattern (str, optional) – Substring that must be included in the feature name.

Returns

features – Dictionary of feature names and corresponding feature objects.

Return type

dict

get_frame()
initialize()

Initialize the camera.

The function finds the XML description file (described in section 4.1.2.1 of the GenICam GenTL Standard v1.5) of the camera and creates a node map based on it. After that it initializes a features dictionary containing the wrapped GenICam features.

Raises
  • RuntimeError – If the URL pointing to XML description file is invalid.

  • FileNotFoundError – If GenICam XML description file is not found.

is_acquiring()

Check if camera is acquiring images.

Returns

True if camera is acquiring images. Otherwise False.

Return type

bool

is_initialized()

Check if camera is initialized.

Returns

True if camera is initialized. Otherwise False.

Return type

bool

items()

Get a view of cameras items.

Returns

A view of cameras items.

Return type

dict_items

keys()

Get a view of dictionary keys (names of the available features).

Returns

A view of dictionary keys, or names of the available features.

Return type

dict_keys

load_config_from_dict(settings)

Load a given configuration from a dictionary.

Attempt to set feature values based on a dictionary of feature names and values.

Since settings may have interdependencies (setting A may set B to be write-only, for example), this process cannot be guaranteed to succeed even when the settings to be set have previously been dumped from the camera, when the settings are set in a unknown order. For this reason, the default behaviour is to loop through the given settings and attempt to set each value in order, until all the remaining settings are non-writable. Tries to get a value set are logged and can be seen by using a logger with level DEBUG.

Parameters

settings (dict) – Dictionary of feature names and values.

Returns

  • unmodified settings (dict) – Subset of the original dictionary containing settings which could not be set even after iteration.

  • reasons (dict) – Dictionary of unset feature names and reasons why they could not be set (in the final iteration).

load_config_from_file(filepath)

Reads and immediately loads a config from a file.

See read_config_from_file and load_config_from_dict for more info.

Parameters

filepath (str) – A file path to a TOML configuration file containing user given settings for the camera.

Returns

  • unmodified settings (dict) – Subset of the original dictionary containing settings which could not be set even after iteration.

  • reasons (dict) – Dictionary of unset feature names and reasons why they could not be set (in the final iteration).

read_config_from_file(filepath=None)

Read configuration file and return it as a dict.

The function assumes that the filepath given as a parameter contains a TOML configuration file (doesn’t check the file extension) and starts parsing it. If no configuration file is passed as a parameter, the functions looks up the configuration from the default location, and evaluates the file if it finds one.

Parameters

filepath (str or None, optional) – A file path to a TOML configuration file containing user given settings for the camera. If not given, will attempt to find a configuration from the default directory with the name “<Vendor>_<Model>_<Serial number>_<TL type>.toml” as given by the GenICam device info.

Returns

Dictionary of camera settings and their values.

Return type

dict

Raises
  • FileNotFoundError – If configuration file given as parameter is not found.

  • TomlDecodeError – If functions fails to parse the configuration file.

Notes

Since the set of features varies between camera models, configuration file is also model specific. However it’s possible that same file can be used between two very similar camera models. Also, if the configuration file contains very few general settings, it’s very likely that the file works with multiple cameras.

save_config_to_file(filepath, overwrite=False, **kwargs)

Save current camera configuration to a file.

Tries to save all accessible camera features and their values to a file. By default only features that are set to read-write are included. If you want to include parameters that are read-only or write-only, pass access_modes=[‘r’, ‘w’, ‘rw’] or variants thereof. See get_features for other ways to select camera features.

Parameters
  • filepath (str) – File to save the config to.

  • overwrite (bool) – Whether to overwrite existing configuration file, if it exists.

  • **kwargs – Keyword arguments passed to get_features, used to select config features. By default only includes features with readable and writable values.

start_acquisition(n_buffers=None, payload_size=None, meta=None)

Start image acquisition.

Parameters
  • n_buffers (int) – Number of buffers.

  • payload_size (int) – Payload size.

  • meta (list of str) – List of GenICam metadata fields to include in frames.

stop_acquisition()

Stop image acquisition.

Notes

If acquisition has not been started, this function won’t do anything.

class camazing.core.CameraList(cti_file=None)

Bases: object

List of all the cameras connected to the machine.

property cti_file

CTI file used to detect cameras.

update()

Update the list of available cameras.

camazing.core.check_initialization(method)

Decorator for checking camera initialization.

Checks that the Camera object is initialized by calling is_initialized before executing the given method.

Parameters

method (method) – Method to execute with checks.

Raises

RuntimeError – Raised when Camera is not initialized.

camazing.core.get_cti_file()

Tries to find an existing GenICam Producer file.

The function checks if GENICAM_GENTL[64|32]_PATH environment variable (which is described in GenICam GenTL standard version 1.5, section 6.1.1) is set, and returns the path to the CTI file..

Returns

cti_file – A path to GenICam Producer file.

Return type

str

Raises
  • OSError – If environment variable GENICAM_GENTL[64|32]_PATH is not set.

  • FileNotFoundError – If GenICam Producer file (.cti) is not found.

camazing.feature_types module

exception camazing.feature_types.AccessModeError

Bases: Exception

class camazing.feature_types.Boolean(feature)

Bases: camazing.feature_types.Valuable

A wrapper class for IBoolean GenApi node.

class camazing.feature_types.Bounded

Bases: abc.ABC

A base class for features that are numeric values.

property max

Gives the maximum value of the feature.

Returns

The maximum value of the feature.

Return type

int or float

property min

Gives the minimum value of the feature.

Returns

The minimum value of the feature.

Return type

int or float

class camazing.feature_types.Command(feature)

Bases: camazing.feature_types.Feature

A wrapper class for ICommand GenApi node.

execute()
class camazing.feature_types.Enumeration(feature)

Bases: camazing.feature_types.Valuable

A wrapper class for IEnumeration GenApi node.

property valid_values

Gives a tuple containing all of the valid values. The enumeration doesn’t accept any value that is not included in this tuple.

Returns

A tuple containing all of the valid values.

Return type

tuple

class camazing.feature_types.Feature(feature)

Bases: abc.ABC

A base class for GenICam GenApi node wrappers.

property access_mode

Get access mode of the feature.

Returns

access_mode – Access mode of the feature. ‘’: Feature is not accessable ‘r’: Feature is read-only ‘w’: Feature is write-only ‘rw’ Feature is readable and writable

Return type

{‘’, ‘r’, ‘w’, ‘rw’}

info()
class camazing.feature_types.Float(feature)

Bases: camazing.feature_types.Valuable, camazing.feature_types.Bounded

A wrapper class for IFloat GenApi node.

property unit

Gives a physical unit that is associated with the features value.

Returns

A physical unit associated with the value. If the feature has no physical unit, an empty string is returned.

Return type

str

class camazing.feature_types.Integer(feature)

Bases: camazing.feature_types.Valuable, camazing.feature_types.Bounded

A wrapper class for IInteger GenApi node.

property increment

returns: An increment :rtype: int

class camazing.feature_types.String(feature)

Bases: camazing.feature_types.Valuable

A wrapper class for IString GenApi node.

class camazing.feature_types.Valuable(feature)

Bases: camazing.feature_types.Feature, abc.ABC

a base class for features with value.

property value

Gets the current value of the feature.

Raises

AccessModeError – If the feature is not readable.

Returns

Return type

The current value of the feature.

camazing.pixelformats module

exception camazing.pixelformats.PixelFormatError

Bases: Exception

camazing.pixelformats.decode_RGB(bpp)

Decode RGB buffer with a given bit depth.

camazing.pixelformats.decode_YCbCr422_8()

Decode YCbCr422 buffer with given bit depth.

camazing.pixelformats.decode_raw(dtype)

Decode raw buffer with a given bit depth.

camazing.pixelformats.get_decoder(pxformat)

Return a numpy decoder for a given GenICam pixel format.

Parameters

pxformat (str) – Pixel format as given by cameras PixelFormat.

Returns

decoder – Function for decoding a buffer

Return type

function

camazing.pixelformats.get_valid_range(pxformat)

Return the valid range of values for a given pixel format.

Parameters

pxformat (str) – Pixel format as given by cameras GenICam PixelFormat feature.

Returns

A vector of [min_value, max_value] with the same type as the decoded pixel format.

Return type

np.array

camazing.util module

Miscellaneous utility functions and classes.

class camazing.util.Singleton

Bases: type

camazing.util.to_bool(value)

A slight modification of bool(). This function converts string literals ‘True’ and ‘False’ to boolean values accordingly.

Parameters

value – The value to be converted to boolean.

Raises

ValueError – If literal value is not convertible to boolean value.

Returns

The boolean value acquired after conversion.

Return type

bool

Module contents