img package

Submodules

img.file_io module

img.sensor_io module

class img.sensor_io.SensorIO(cfg: dict)[source]

Bases: object

A class representing the sensor input/output for image processing.

Args:

cfg (dict): The configuration dictionary containing sensor information.

Attributes:

manufacturer (str): The manufacturer of the camera sensor. model (str): The model of the camera sensor. serial_no (str): The serial number of the camera sensor. cfg (dict): The configuration dictionary. img_count (int): The number of images in the data. handle (Handler): The handler for reading the sensor data. reader (Iterator): The iterator for reading the sensor data. idx (int): The current index of the sensor data.

Methods:

__getitem__(self, idx): Retrieves the image at the specified index. __len__(self): Returns the number of images in the data. close(self): Closes the sensor data handler.

Raises:

NotImplementedError: If the manufacturer or model is not supported.

close()[source]

Closes the sensor data handler.

img.viz module

Module contents

The img package comprises two types of handlers: (1) file handlers for reading image files and (2) sensor handlers for capturing images from live camera feeds. The file_io.py and sensor_io.py modules should not be modified except for contributions to the framework application logic.

### Creating a New Sensor Stream Handler:

To create a new sensor stream handler to support a new camera sensor:

  1. Create a new Python file named handler_<manufacturer>_<model>.py in the img directory.

  2. Replace <manufacturer> and <model> with the respective manufacturer and model of the camera.

  3. The manufacturer and model are passed from config.yml under sensors:camera:manufacturer and sensors:camera:model, respectively, and are used to select the appropriate handler.

### Handler File Structure:

The handler_<manufacturer>_<model>.py file should contain a class named Handler with the following structure:

```python # hander_<manufacturer>_<model>.py

class Handler:

‘’’ Args:

cfg (dict): Configuration dictionary containing camera settings.

Attributes:

manufacturer (str): The manufacturer of the camera. model (str): The model of the camera. serial_no (str): The serial number of the camera. reader (generator): A generator that yields image arrays.

Raises:

Exception: If fails to connect to the camera or receive images from it.

‘’’

def __init__(self, cfg):

self.manufacturer = cfg[‘sensors’][‘camera’][‘manufacturer’].lower() self.model = cfg[‘sensors’][‘camera’][‘model’].lower().replace(‘-’, ‘’) self.serial_no = cfg[‘sensors’][‘camera’][‘serial_number’].lower()

# Connect to the camera and initialize the reader self.reader = self.__get_reader__()

def __get_reader__(self):

# Return a generator that yields image arrays pass

def close(self):

# Release the camera resources self.reader.close()

```