s6.utils.camera_identifier¶

Rule‑based camera identifier using simple IR marker rectangular ROIs.

Provides CameraIDIdentifier to determine camera IDs by checking predefined regions for bright markers in grayscale frames. A small OpenCV UI in main() helps author a JSON config of ROIs and a detection threshold.

The expected input frames are 8‑bit single‑channel images with intensity values in [0, 255]. Regions are rectangles and may be marked as negative (region must not contain a marker).

class s6.utils.camera_identifier.CameraIDIdentifier(rule_config, threshold=250)

Bases: object

Identify camera IDs by testing configured regions for bright markers.

The identifier loads a rule_config mapping camera IDs to a list of region specs. Each spec describes a rectangle with bbox=(x1, y1, x2, y2), plus an optional negate flag: - negate=False → region must contain a marker (mean > threshold) - negate=True → region must not contain a marker (mean <= threshold)

Parameters:
  • rule_config (dict[int, list[dict]]) – Mapping from camera ID to a list of region specs. See above for keys.

  • threshold (float, default 250) – Mean intensity threshold in [0, 255] used to decide if a marker is present inside a region.

static load_default() CameraIDIdentifier

Load the default config from configs/camera_ident.config.json.

static from_json(config_path: str = 'configs/camera_ident.config.json') CameraIDIdentifier

Create an identifier from a JSON configuration file.

Parameters:

config_path (str, default "configs/camera_ident.config.json") – Path to the JSON config. Must contain threshold and rule_config keys.

Returns:

Instance configured with the given rules and threshold.

Return type:

CameraIDIdentifier

Raises:
  • FileNotFoundError – If the file does not exist.

  • json.JSONDecodeError – If the file is not valid JSON.

order(images: list[ndarray], erase_marker_region: bool = False) dict

Identify camera IDs and return a mapping from ID to image.

The input order is left unchanged. For each image, the first camera ID whose region specs are satisfied is assigned. If erase_marker_region is True, positive regions for matched specs are zeroed in‑place.

Parameters:
  • images (list[ndarray]) – Grayscale frames of shape (H, W).

  • erase_marker_region (bool, default False) – If True, zero out detected positive regions for matched IDs.

Returns:

Mapping of camera ID to its corresponding image.

Return type:

dict[int, ndarray]

s6.utils.camera_identifier.main()