RodTracker.backend.detection

Includes objects and methods used for detection of particles by RodTracker.

Author: Adrian Niemann (adrian.niemann@ovgu.de)

Date: 2022-2024

class Detector(cam_id: str, model: ScriptModule, images: List[Path], frames: List[int], classes: Dict[int, list], threshold: float = 0.5)[source]

Bases: QRunnable

Object for running the detection of rods in a thread different from the main thread.

This object runs the detection of rods in a set of frames for one camera angle. The desired colors to detect and their expected occurrences must be specified. Only predefined colors are supported at the moment.

Parameters:
  • cam_id (str) – ID of the camera on whos images the detection of rods shall be run.

  • model (ScriptModule) – Neural network model that shall be used for detection.

  • images (List[Path]) – Paths to the image files the detection of rods shall be performed on. Each entry in images corresponds to one in frames.

  • frames (List[int]) – Frames the detection of rods will be performed on. Each entry in frames corresponds to one in images.

  • classes (Dict[int, list]) – Classes of objects to detect in the images, i.e. rod colors that shall be detected, togther with their human readable name and the amount of particles that shall be detected per frame individually for each class. list[0] : color as a str list[1] : expected amount of particles as an int

  • threshold (float, optional) –

    Confidence threshold \(\in [0, 1]\) below which objects are rejected after detection.

    Default is 0.5.

Raises:

ValueError – Is raised when len(images) != len(frames).

See also

DEFAULT_CLASSES

cam_id

ID of the camera on whos images the detection of rods shall be run.

Type:

str

frames

Frames the detection of rods will be performed on. Each entry in frames corresponds to one in images.

Type:

List[int]

images

Paths to the image files the detection of rods will be performed on. Each entry in images corresponds to one in frames.

Type:

List[Path]

model

Neural network model that will be used for detection.

Type:

ScriptModule

signals

Signals that can be emitted during the running of a Detector object. Their purpose is to report errors, progress, and (intermediate) results.

Type:

DetectorSignals

threshold

Confidence threshold \(\in [0, 1]\) below which objects are rejected after detection.

\(\in [0, 1]\)

Type:

float

expected

The amount of particles per frame for each class that shall be detected. expected[class] = amount

Type:

Dict[int, int]

classes: Dict[int, str] = {}

Classes of objects to detect in the images, i.e. rod colors that will be detected.

Default is {}.

Type:

Dict[int, str]

run()[source]

Run the detection of rods with the parameters set in this Detector object.

This function is not intended to be run directly but by invoking it via a QThreadPool.start(detector) call.

class DetectorSignals[source]

Bases: QObject

Helper object to provide Detector access to pyqtSignal.

error

Signal for propagating errors occuring in the Worker’s thread.

The transferred tuple should contain the following values:
[0]: Exception type
[1]: Exception value
[2]: Exception traceback

See also

sys.exc_info()

sys.exc_info

Type:

pyqtSignal(tuple)

finished

Indicates the detection has finished successfully.

The payload is the ID of the camera dataset this detection process was run on.

Type:

pyqtSignal(str)

progress

Reports the progress of started detections.

[0]: progress as the ratio of finished frames over all frames, so \(\in [0, 1]\)

[1]: DataFrame containing only the 2D data of the detected rods.

See also: ParticleDetection.utils.datasets.add_points()

[2]: ID of the camera dataset the frame is taken from.

Type:

pyqtSignal(float, DataFrame, str)

class RodDetection(frame: int, cam_id: str, num_detected: int, *args, **kwargs)[source]

Bases: Action

Representation of the detection of rods on one frame as a loggable action.

Parameters:
  • frame (int) – Frame the rods have been detected on.

  • cam_id (str) – ID of the camera the image was produced by.

  • num_detected (int) – Total number of rods that have been detected, i.e. all colors combined.

  • *args (Iterable) – Positional arguments after text of the Action superclass.

  • **kwargs (dict) – Keyword arguments of the Action superclass.

num_detected

Total number of rods that have been detected, i.e. all colors combined.

Type:

int

cam_id: str

ID of the camera the image was produced by.

Type:

str

undo(_)[source]
Raises:

NotInvertableError – This action is generally not invertable.