pub struct TransformChain {
pub source_width: u32,
pub source_height: u32,
pub steps: Vec<Transform>,
}Expand description
The transforms from a source image of source_width × source_height to the image a
backend saw, in order.
Mapping a point to the backend’s image and back returns it within floating-point error; the property tests hold it within 0.5 px for random chains.
§Example
use adk_vision::{Transform, TransformChain};
// A 3024x1964 screenshot, cropped, then resized to half size.
let chain = TransformChain::new(3024, 1964)
.then(Transform::Crop { x: 1000, y: 500, width: 800, height: 600 })
.unwrap()
.then(Transform::Resize { width: 400, height: 300 })
.unwrap();
assert_eq!(chain.output_size(), (400, 300));
assert_eq!(chain.to_target([1200.0, 700.0]), [100.0, 100.0]);
assert_eq!(chain.to_source([100.0, 100.0]), [1200.0, 700.0]);Fields§
§source_width: u32The source image’s width.
source_height: u32The source image’s height.
steps: Vec<Transform>The steps, in the order they were applied.
Implementations§
Source§impl TransformChain
impl TransformChain
Sourcepub fn new(source_width: u32, source_height: u32) -> Self
pub fn new(source_width: u32, source_height: u32) -> Self
The empty chain of a source image: the backend sees the image as it is.
Sourcepub fn then(self, step: Transform) -> Result<Self>
pub fn then(self, step: Transform) -> Result<Self>
Appends a step.
§Errors
Returns VisionError::InvalidInput for a crop outside the current image, an empty
crop or a resize to zero.
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
true when the chain has no step that moves coordinates.
Sourcepub fn output_size(&self) -> (u32, u32)
pub fn output_size(&self) -> (u32, u32)
The size of the image after every step.
Sourcepub fn to_target(&self, point: [f64; 2]) -> [f64; 2]
pub fn to_target(&self, point: [f64; 2]) -> [f64; 2]
Maps a point in source pixels to the backend’s image.
Sourcepub fn to_source(&self, point: [f64; 2]) -> [f64; 2]
pub fn to_source(&self, point: [f64; 2]) -> [f64; 2]
Maps a point in the backend’s image back to source pixels.
Sourcepub fn bbox_to_source(&self, bbox: &BBox) -> BBox
pub fn bbox_to_source(&self, bbox: &BBox) -> BBox
Maps a box in the backend’s image to source pixels; a rotation keeps it axis-aligned.
Sourcepub fn bbox_to_target(&self, bbox: &BBox) -> BBox
pub fn bbox_to_target(&self, bbox: &BBox) -> BBox
Maps a box in source pixels to the backend’s image.
Sourcepub fn shape_to_source(&self, shape: &Shape) -> Result<Shape>
pub fn shape_to_source(&self, shape: &Shape) -> Result<Shape>
Maps a shape in the backend’s image to source pixels. A mask must be the size of the backend’s image and comes back resampled to the source size.
§Errors
Returns VisionError::InvalidInput for a mask whose size is not the target size.
Sourcepub fn shape_to_target(&self, shape: &Shape) -> Result<Shape>
pub fn shape_to_target(&self, shape: &Shape) -> Result<Shape>
Maps a shape in source pixels to the backend’s image, resampling a mask to the target size.
§Errors
Returns VisionError::InvalidInput for a mask whose size is not the source size.
Trait Implementations§
Source§impl Clone for TransformChain
impl Clone for TransformChain
Source§impl Debug for TransformChain
impl Debug for TransformChain
Source§impl<'de> Deserialize<'de> for TransformChain
impl<'de> Deserialize<'de> for TransformChain
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>,
impl Eq for TransformChain
Source§impl PartialEq for TransformChain
impl PartialEq for TransformChain
Source§impl Serialize for TransformChain
impl Serialize for TransformChain
impl StructuralPartialEq for TransformChain
Auto Trait Implementations§
impl Forget for TransformChain
impl Freeze for TransformChain
impl Move for TransformChain
impl RefUnwindSafe for TransformChain
impl Send for TransformChainwhere
RawVecInner: Send,
impl Sync for TransformChainwhere
RawVecInner: Sync,
impl Unpin for TransformChain
impl UnsafeUnpin for TransformChain
impl UnwindSafe for TransformChainwhere
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
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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.