Object Selector
Object Selector Analyzer Module Overview
This module provides an analyzer (ObjectSelector
) for selecting the top-K detections from
object detection results based on various strategies and optional tracking. It enables
intelligent filtering of detection results to focus on the most relevant objects.
Key Features
Selection Strategies: Supports selecting by highest confidence score or largest bounding-box area
Tracking Integration: Uses
track_id
fields to persist selections across frames with configurable timeoutTop-K Selection: Configurable number of objects to select per frame
Visual Overlay: Draws bounding boxes for selected objects on images
Selection Persistence: Maintains selection state across frames when tracking is enabled
Timeout Control: Configurable frame count before removing lost objects from selection
Typical Usage
Create an
ObjectSelector
instance with desired selection parametersProcess each frame's detection results through the selector
Access selected objects from the augmented results
Optionally visualize selected objects using the annotate method
Use selected objects in downstream analyzers for focused processing
Integration Notes
Works with any detection results containing bounding boxes and confidence scores
Optional integration with
ObjectTracker
for persistent selection across framesSelected objects are marked in the result object for downstream processing
Supports both frame-based and tracking-based selection modes
Key Classes
ObjectSelector
: Main analyzer class that processes detections and maintains selectionsObjectSelectionStrategies
: Enumeration of available selection strategies
Configuration Options
top_k
: Number of objects to select per frameselection_strategy
: Strategy for ranking objects (by highest confidence score or by largest bounding box area)use_tracking
: Enable/disable tracking-based selection persistencetracking_timeout
: Frames to wait before removing lost objects from selectionshow_overlay
: Enable/disable visual annotationsannotation_color
: Customize overlay appearance
Classes
ObjectSelectionStrategies
ObjectSelectionStrategies
Bases: Enum
Enumeration of object selection strategies.
Members
HIGHEST_SCORE (int): Selects objects with the highest confidence scores. LARGEST_AREA (int): Selects objects with the largest bounding-box area.
ObjectSelector
ObjectSelector
Selects the top-K detected objects per frame based on a specified strategy.
This analyzer examines the detection results for each frame and retains only the
top-K detections according to the chosen ObjectSelectionStrategies
(e.g.,
highest confidence score or largest bounding-box area).
When tracking is enabled, it uses object track_id
information to continue
selecting the same objects across successive frames, removing an object from the
selection if it has not appeared for a certain number of frames (the tracking timeout).
Classes
_SelectedObject
_SelectedObject
dataclass
Selected object data structure.
Attributes:
detection
dict
The detection result dictionary.
counter
int
Frames since last seen before removal.
Functions
__init__(*, ...)
__init__(*, top_k=1, selection_strategy=ObjectSelectionStrategies.HIGHEST_SCORE, use_tracking=True, tracking_timeout=30, show_overlay=True, annotation_color=None)
Constructor.
Parameters:
top_k
int
Number of objects to select. Default 1.
1
selection_strategy
Strategy for ranking objects. Default ObjectSelectionStrategies.HIGHEST_SCORE.
HIGHEST_SCORE
use_tracking
bool
Whether to enable tracking-based selection. If True, only objects with a track_id
field are selected (requires an ObjectTracker to precede this analyzer in the pipeline). Default True.
True
tracking_timeout
int
Number of frames to wait before removing an object from selection if it is not detected. Default 30.
30
show_overlay
bool
Whether to draw bounding boxes around selected objects on the output image. If False, the image is passed through unchanged. Default True.
True
annotation_color
tuple
RGB color for annotation boxes. Default None (uses the complement of the result overlay color).
None
Raises:
ValueError
If an unsupported selection strategy is provided.
analyze(result)
analyze(result)
Select the top-K objects based on the configured strategy, updating the result.
Uses tracking IDs to update selected objects when tracking is enabled. All other objects not selected are removed from results.
Parameters:
result
InferenceResults
Model result with detection information.
required
Returns:
None
The result object is modified in-place.
Last updated
Was this helpful?