Struct DetectionZones
pub struct DetectionZones(/* private fields */);Expand description
Detection zone functionality.
Includes the motion detection functionality for the size of the motion grid.
Implementations§
§impl DetectionZones
impl DetectionZones
pub fn add_zone(
&mut self,
coordinates: Vec<(f32, f32)>,
classes: Vec<DetectionClass>,
apply_to_video_search: bool,
) -> Result<ZoneID, Error>
pub fn add_zone( &mut self, coordinates: Vec<(f32, f32)>, classes: Vec<DetectionClass>, apply_to_video_search: bool, ) -> Result<ZoneID, Error>
Specify a detection zone polygon for a group of classes.
The zone can be used to verify whether a bounding-box is inside or outside
of it using the is_box_in_zone function. It can also be used internally
by the Plumerai library to improve detection quality. A single detection
zone can be used for one or more classes.
§Arguments
coordinates: A vector of (x, y) coordinates specifying the polygon of the detection zone in normalized coordinates, between 0 and 1. The code assumes that the first coordinate is also the final coordinate of the polygon: it should not be given by the user. The polygon must be simple (not complex): it can’t have holes or self-intersections. It is allowed to be both concave or convex.classes: A vector of classes that the zone applies to. Must contain at least one class.apply_to_video_search: Whentrue, this zone is used to gate per-track sampling and full-frame blackout in the VLM video search pipeline. Passfalseto keep the zone for detection-time queries only (e.g. notifications) and have video search behave as if the zone were not set.
§Errors
Error::InvalidZoneClassError::InvalidZoneGeometryError::MaximumDetectionZonesReached
pub fn remove_zone(&mut self, zone_id: ZoneID) -> Result<(), Error>
pub fn remove_zone(&mut self, zone_id: ZoneID) -> Result<(), Error>
pub fn is_box_in_zone(
&self,
zone_id: &ZoneID,
prediction: &BoxPrediction,
box_shrink_factor: f32,
) -> Result<bool, Error>
pub fn is_box_in_zone( &self, zone_id: &ZoneID, prediction: &BoxPrediction, box_shrink_factor: f32, ) -> Result<bool, Error>
Determines whether a box prediction is within a detection zone.
The box_shrink_factor parameter controls how much overlap is required.
Before the zone check the bounding box is shrunk towards its centre by
the given factor: at 0.0 (default) the full box is used, so even if only
a very small corner of the box touches the zone this will return true; at
1.0 the box is reduced to its centre point, so the centre must be inside
the zone for this to return true. Values in between require
proportionally more overlap.
§Errors
Error::InvalidZoneIDError::InvalidZoneClassError::InvalidZoneGeometryError::InvalidBoxifbox_shrink_factoris outside [0, 1]
pub fn has_track_left_zone(
&self,
zone_id: &ZoneID,
track_id: &TrackID,
box_shrink_factor: f32,
) -> Result<bool, Error>
pub fn has_track_left_zone( &self, zone_id: &ZoneID, track_id: &TrackID, box_shrink_factor: f32, ) -> Result<bool, Error>
Determines whether a tracked box prediction has left a detection zone.
For a tracked box to be considered as having left a zone, it must have its
origin completely or partially within the zone, and currently be
completely outside the zone. The origin is defined as the location of the
detected box at the start of the track (or when reset_track_origin was
last called). If the tracked box left the zone before, but has now
returned to it, this will not be considered as having left the zone.
The origin of the track can be reset using reset_track_origin.
§Arguments
box_shrink_factor: A factor in [0, 1] that shrinks the bounding box towards its centre before each zone check. Seeis_box_in_zonefor details. The same factor is applied to both the current position and the track origin.
§Errors
Error::InvalidZoneIDError::InvalidZoneClassError::InvalidZoneGeometryError::InvalidBoxif the track ID is invalid orbox_shrink_factoris outside [0, 1]
pub fn has_track_arrived_in_zone(
&self,
zone_id: &ZoneID,
track_id: &TrackID,
box_shrink_factor: f32,
) -> Result<bool, Error>
pub fn has_track_arrived_in_zone( &self, zone_id: &ZoneID, track_id: &TrackID, box_shrink_factor: f32, ) -> Result<bool, Error>
Determines whether a tracked box prediction has arrived in a detection zone.
For a tracked box to be considered as having arrived in a zone, it must
currently be completely or partially inside the zone and have its origin
completely outside the zone. The origin is defined as the location of the
detected box at the start of the track (or when reset_track_origin was
last called). If the tracked box originated in the zone, left the zone,
and has now arrived back into the zone, it will not be considered as
having arrived in the zone.
§Arguments
box_shrink_factor: A factor in [0, 1] that shrinks the bounding box towards its centre before each zone check. Seeis_box_in_zonefor details. The same factor is applied to both the current position and the track origin.
§Errors
Error::InvalidZoneIDError::InvalidZoneClassError::InvalidZoneGeometryError::InvalidBoxif the track ID is invalid orbox_shrink_factoris outside [0, 1]
pub fn reset_track_origin(&mut self, track_id: &TrackID) -> Result<(), Error>
pub fn reset_track_origin(&mut self, track_id: &TrackID) -> Result<(), Error>
Resets the origin of a track.
The origin of the track will be set to its current position, i.e. the position it had in the most recently processed frame.
The origin of a track is used by has_track_left_zone and
has_track_arrived_in_zone. When a track starts in a zone, leaves it and
later re-enters, has_track_arrived_in_zone will not return true
because the track originated in the zone. To change this behavior, the
origin can be reset after the track leaves the zone (for example, after a
timeout period outside the zone). This way, when the track re-enters, it
will be treated as having newly arrived in the zone.
§Errors
Error::InvalidBoxif the track ID is invalid
pub fn get_motion_grid_in_zone(&self, zone_id: &ZoneID) -> Result<Grid, Error>
pub fn get_motion_grid_in_zone(&self, zone_id: &ZoneID) -> Result<Grid, Error>
Get the motion detection grid, limited to a specific detection zone.
This function retrieves the motion detection grid similar to
MotionDetection::get_grid but sets all values outside the specified
detection zone to zero.
§Errors
Error::MotionGridNotYetReadyError::InvalidZoneID