pub struct WatchCondition {
pub name: String,
pub labels: Vec<String>,
pub min_score: f32,
pub min_frames: u32,
pub zone: Option<Zone>,
pub cooldown: Duration,
}Expand description
What a stream watches for, evaluated on the device so the kernel sees only the events that pass (spec 3.7 §7.10).
A region meets the condition when its label is one of labels (compared ignoring ASCII
case; an empty list takes any label), its score is at least min_score (a region with no
score has none), and, with a zone, its anchor point lies in the zone. A track fires once
it has met the condition in min_frames consecutive observations. After a firing, the
condition fires again no sooner than cooldown later, by the frames’ capture times.
| Field | Default |
|---|---|
min_score | 0.5 |
min_frames | 3 |
zone | none: the whole frame |
cooldown | zero |
§Example
use std::time::Duration;
use adk_vision::WatchCondition;
let seal = WatchCondition::new("torn-seal", ["torn seal"])
.with_min_score(0.6)
.with_min_frames(3)
.with_cooldown(Duration::from_secs(2));
assert!(seal.validate().is_ok());
let json = serde_json::to_value(&seal).unwrap();
assert_eq!(json["cooldownMs"], 2000);
assert!(WatchCondition::new("torn seal", ["seal"]).validate().is_err(), "names are keys");Fields§
§name: StringThe condition’s name: part of every event key, so [A-Za-z0-9._-], at most 64.
labels: Vec<String>The labels that count; empty for any.
min_score: f32The lowest score that counts, in [0, 1].
min_frames: u32How many consecutive observations a track must meet the condition in, at least 1.
zone: Option<Zone>The area of the frame the condition is limited to.
cooldown: DurationThe least time between two firings of the condition.
Implementations§
Source§impl WatchCondition
impl WatchCondition
Sourcepub fn new<L: Into<String>>(
name: impl Into<String>,
labels: impl IntoIterator<Item = L>,
) -> Self
pub fn new<L: Into<String>>( name: impl Into<String>, labels: impl IntoIterator<Item = L>, ) -> Self
A condition named name over labels, with the defaults in the table above.
Sourcepub fn with_min_score(self, min_score: f32) -> Self
pub fn with_min_score(self, min_score: f32) -> Self
Sets the lowest score that counts.
Sourcepub fn with_min_frames(self, min_frames: u32) -> Self
pub fn with_min_frames(self, min_frames: u32) -> Self
Sets how many consecutive observations a track must meet the condition in.
Sourcepub fn with_cooldown(self, cooldown: Duration) -> Self
pub fn with_cooldown(self, cooldown: Duration) -> Self
Sets the least time between two firings.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Checks the condition.
§Errors
VisionError::InvalidInput for a name outside [A-Za-z0-9._-] or longer than 64
characters, a min_score outside [0, 1], a min_frames of zero, or an invalid
zone.
Sourcepub fn matches(&self, region: &Region) -> bool
pub fn matches(&self, region: &Region) -> bool
Whether region meets the condition in this one frame: label, score and zone.
§Example
use adk_vision::{BBox, BackendId, CoordFrame, Digest, Region, RegionOrigin, Shape, TransformChain, WatchCondition};
let region = Region {
image: Digest::of(b"frame"),
shape: Shape::Box(BBox::new(10.0, 10.0, 50.0, 30.0)),
label: Some("Torn Seal".into()),
score: Some(0.8),
track: None,
origin: RegionOrigin {
backend: BackendId::new("rf-detr"),
manifest: None,
frame: CoordFrame::SentPixels,
chain: TransformChain::new(640, 480),
escalated_from: None,
},
};
assert!(WatchCondition::new("seal", ["torn seal"]).matches(®ion));
assert!(!WatchCondition::new("seal", ["torn seal"]).with_min_score(0.9).matches(®ion));Trait Implementations§
Source§impl Clone for WatchCondition
impl Clone for WatchCondition
Source§impl Debug for WatchCondition
impl Debug for WatchCondition
Source§impl<'de> Deserialize<'de> for WatchCondition
impl<'de> Deserialize<'de> for WatchCondition
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for WatchCondition
impl PartialEq for WatchCondition
Source§impl Serialize for WatchCondition
impl Serialize for WatchCondition
impl StructuralPartialEq for WatchCondition
Auto Trait Implementations§
impl Forget for WatchCondition
impl Freeze for WatchConditionwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<String>: Freeze,
PhantomData<[f32; 2]>: Freeze,
impl Move for WatchCondition
impl RefUnwindSafe for WatchCondition
impl Send for WatchConditionwhere
RawVecInner: Send,
impl Sync for WatchConditionwhere
RawVecInner: Sync,
impl Unpin for WatchCondition
impl UnsafeUnpin for WatchConditionwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<[f32; 2]>: UnsafeUnpin,
impl UnwindSafe for WatchConditionwhere
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
impl<T> MaybeSend for Twhere
T: Send,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> Scalar for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.