pub struct RegionNormalizer { /* private fields */ }Expand description
Turns a backend’s answers into regions of the source image.
A raw shape is mapped from the backend’s CoordFrame to the pixels of the image it was
sent, back through the TransformChain to source pixels, and clamped to the source
image. A box or mask left with no area is dropped.
§Example
use adk_vision::{
AxisOrder, BBox, BackendId, CoordFrame, Digest, RawRegion, RegionNormalizer, Shape,
Transform, TransformChain,
};
// The source was halved before it was sent; Gemini answered on 0-1000.
let chain = TransformChain::new(2000, 1000)
.then(Transform::Resize { width: 1000, height: 500 })
.unwrap();
let frame = CoordFrame::Normalized { scale: 1000, order: AxisOrder::Yx };
let normalizer =
RegionNormalizer::new(Digest::of(b"source"), chain, frame, BackendId::new("gemini"));
let raw = RawRegion::boxed(frame.box_from_raw([100.0, 250.0, 500.0, 750.0]), "cat", 0.9);
let region = normalizer.region(raw).unwrap().unwrap();
assert_eq!(region.shape, Shape::Box(BBox::new(500.0, 100.0, 1500.0, 500.0)));Implementations§
Source§impl RegionNormalizer
impl RegionNormalizer
Sourcepub fn new(
image: Digest,
chain: TransformChain,
frame: CoordFrame,
backend: BackendId,
) -> Self
pub fn new( image: Digest, chain: TransformChain, frame: CoordFrame, backend: BackendId, ) -> Self
A normalizer for answers about the source image image, seen through chain, given
in frame by backend.
Sourcepub fn with_manifest(self, manifest: Option<String>) -> Self
pub fn with_manifest(self, manifest: Option<String>) -> Self
Names the model manifest entry the backend ran.
Sourcepub fn chain(&self) -> &TransformChain
pub fn chain(&self) -> &TransformChain
The transform chain.
Sourcepub fn origin(&self) -> RegionOrigin
pub fn origin(&self) -> RegionOrigin
The origin every region from this normalizer carries.
Sourcepub fn shape(&self, raw: &Shape) -> Result<Shape>
pub fn shape(&self, raw: &Shape) -> Result<Shape>
Maps a shape from the backend’s frame to source pixels, clamped to the source image.
§Errors
Returns VisionError::Parse for a mask in a frame with no raster, or of the wrong
size, and for a non-finite coordinate.
Trait Implementations§
Source§impl Clone for RegionNormalizer
impl Clone for RegionNormalizer
Auto Trait Implementations§
impl Forget for RegionNormalizer
impl Freeze for RegionNormalizer
impl Move for RegionNormalizer
impl RefUnwindSafe for RegionNormalizer
impl Send for RegionNormalizerwhere
RawVecInner: Send,
impl Sync for RegionNormalizerwhere
RawVecInner: Sync,
impl Unpin for RegionNormalizer
impl UnsafeUnpin for RegionNormalizerwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<Transform>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
impl UnwindSafe for RegionNormalizerwhere
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
Mutably borrows from an owned value. Read more
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,
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> ⓘ
Converts
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> ⓘ
Converts
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,
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.