Skip to main content
Provides comprehensive filtering capabilities for detection collections including confidence thresholding, class-based filtering, geometric constraints, zone-based filtering, and tracking-related filters. Designed for zero-overhead method injection into Detections class for seamless chaining operations.

Functions

filter_by_confidence

Filter detections by minimum confidence score threshold. Applies confidence-based filtering to remove low-confidence detections that may represent false positives or uncertain predictions. Essential preprocessing step for improving detection quality and reducing noise in downstream analysis.

Function Signature

Parameters

float
required
Minimum confidence score (inclusive). Range: [0.0, 1.0]. Detections with confidence >= threshold are retained. Higher values are more restrictive.

Returns

Detections
New Detections object containing only high-confidence detections. Preserves all detection attributes including tracking data.

Example

Example

filter_by_class_id

Filter detections by class identifier(s). Enables class-specific filtering to focus analysis on particular object types. Supports both single class selection and multi-class filtering with flexible ID format handling for different model outputs and naming conventions.

Function Signature

Parameters

Union[int, str, List[Union[int, str]]]
required
Single class ID or list of class IDs to include. Accepts both numeric IDs (e.g., COCO indices) and string class names. Mixed types are supported in lists.

Returns

Detections
New Detections object containing only detections with matching class IDs. Preserves all detection attributes and metadata.

Example

Example

remap_class_ids

Remap class IDs to consolidate or standardize classification labels. Creates new Detection objects with modified class IDs while preserving all other detection attributes. Useful for consolidating similar classes or standardizing class schemas across different models.

Function Signature

Parameters

Union[int, str, List[Union[int, str]]]
required
Source class ID(s) to remap. Single ID or list of IDs.
Union[int, str]
required
Target class ID to map to.

Returns

Detections
New Detections object with remapped class IDs and cleared class names.

Example

Example

filter_by_size

Filter detections by bounding box area constraints.

Function Signature

Parameters

Optional[float]
default:"None"
Minimum bounding box area in pixels (inclusive). If None, no minimum constraint is applied.
Optional[float]
default:"None"
Maximum bounding box area in pixels (inclusive). If None, no maximum constraint is applied.

Returns

Detections
New Detections object containing only detections within size range.

Example

Example

filter_by_dimensions

Filter detections by individual width and height constraints. Provides fine-grained control over detection dimensions, useful for filtering objects based on expected physical dimensions or removing artifacts.

Function Signature

Parameters

Optional[float]
default:"None"
Minimum bounding box width in pixels (inclusive).
Optional[float]
default:"None"
Maximum bounding box width in pixels (inclusive).
Optional[float]
default:"None"
Minimum bounding box height in pixels (inclusive).
Optional[float]
default:"None"
Maximum bounding box height in pixels (inclusive).

Returns

Detections
New Detections object containing only detections within dimension constraints.

Example

Example

filter_by_aspect_ratio

Filter detections by bounding box aspect ratio (width/height). Useful for filtering objects based on their shape characteristics, such as identifying square objects, wide banners, or tall structures.

Function Signature

Parameters

Optional[float]
default:"None"
Minimum aspect ratio (width/height) (inclusive). Values > 1.0 favor wide objects.
Optional[float]
default:"None"
Maximum aspect ratio (width/height) (inclusive). Values < 1.0 favor tall objects.

Returns

Detections
New Detections object containing only detections within aspect ratio range.

Example

Example

filter_by_zones

Filter detections based on zone intersection status. Enables spatial filtering by including or excluding detections that intersect with specified zones. Requires prior zone assignment via update_zones().

Function Signature

Parameters

Union[str, int, List[Union[str, int]]]
required
Single zone ID or list of zone IDs to filter by. Supports both string names and numeric IDs.
bool
default:"False"
If True, exclude detections in specified zones. If False, include only detections in specified zones. Default is False.

Returns

Detections
New Detections object with zone-based filtering applied.

Example

Example

filter_by_position

Filter detections by their position within the frame. Enables spatial filtering based on detection center position relative to frame regions. Useful for focusing on specific areas of interest or excluding edge artifacts.

Function Signature

Parameters

str
required
Target region to filter by. Options: “center”, “edge”, “top”, “bottom”, “left”, “right”, “corners”.
float
default:"0.1"
Margin as percentage of frame size. Range: [0.0, 0.5]. Default is 0.1 (10% margin).
Optional[int]
default:"None"
Frame width in pixels. Required for filtering.
Optional[int]
default:"None"
Frame height in pixels. Required for filtering.

Returns

Detections
New Detections object containing only detections in specified region.

Example

Example

filter_by_relative_size

Filter detections by size relative to total frame area. Provides scale-invariant filtering based on detection size as percentage of total frame area. More robust than absolute size filtering across different resolution inputs.

Function Signature

Parameters

Optional[float]
default:"None"
Minimum size as percentage of frame area. Range: [0.0, 1.0]. If None, no minimum constraint.
Optional[float]
default:"None"
Maximum size as percentage of frame area. Range: [0.0, 1.0]. If None, no maximum constraint.
Optional[int]
default:"None"
Frame width in pixels. Required for calculation.
Optional[int]
default:"None"
Frame height in pixels. Required for calculation.

Returns

Detections
New Detections object containing only detections within relative size range.

Example

Example

filter_by_tracking_duration

Filter detections by their tracking duration.

Function Signature

Parameters

Optional[float]
default:"None"
Minimum tracking duration in seconds (inclusive). If None, no minimum constraint is applied.
Optional[float]
default:"None"
Maximum tracking duration in seconds (inclusive). If None, no maximum constraint is applied.

Returns

Detections
New Detections object containing only detections within duration range.

Example

Example

filter_by_first_seen_time

Filter detections by when they were first observed.

Function Signature

Parameters

Optional[float]
default:"None"
Earliest first seen time (inclusive). Time units depend on tracking implementation (frames, seconds, timestamps).
Optional[float]
default:"None"
Latest first seen time (inclusive).

Returns

Detections
New Detections object containing only detections first seen within time range.

Example

Example

filter_tracked_objects

Filter detections based on tracking status.

Function Signature

Parameters

bool
default:"True"
If True, keep only objects with tracker IDs. If False, keep only objects without tracker IDs. Default is True.

Returns

Detections
New Detections object filtered by tracking status.

Example

Example

remove_duplicates

Remove duplicate or highly overlapping detections using Non-Maximum Suppression. Identifies groups of overlapping detections and keeps only one detection per group based on the specified strategy. Essential for cleaning up multi-model outputs or removing redundant detections.

Function Signature

Parameters

float
default:"0.8"
IoU threshold for considering detections as duplicates. Range: [0.0, 1.0]. Higher values are more restrictive. Default is 0.8.
str
default:"'first'"
Strategy for selecting which detection to keep from each group. Options: ‘first’, ‘last’, ‘highest_confidence’. Default is ‘first’.

Returns

Detections
New Detections object with duplicate detections removed.

Example

Example

filter_overlapping

Filter detections that significantly overlap with other detections. Useful for finding co-occurring objects, validating detection consistency, or identifying regions with multiple overlapping predictions.

Function Signature

Parameters

float
default:"0.5"
Minimum IoU overlap required to consider detections as overlapping. Range: [0.0, 1.0]. Default is 0.5.
Optional[List[Union[int, str]]]
default:"None"
Optional list of class IDs to check overlap against. If None, checks overlap with all other detections.

Returns

Detections
New Detections object containing only detections that overlap sufficiently with other detections.

Example

Example