pub struct UVDocPostProcess {
pub scale: f32,
}Expand description
Post-processor for document transformation results.
The UVDocPostProcess struct handles the post-processing of document
transformation model outputs, converting normalized coordinates back
to pixel coordinates and applying various transformations.
Fields§
§scale: f32Scale factor to convert normalized values back to pixel values.
Implementations§
Source§impl UVDocPostProcess
impl UVDocPostProcess
Sourcepub fn new(scale: f32) -> UVDocPostProcess
pub fn new(scale: f32) -> UVDocPostProcess
Sourcepub fn denormalize_coordinates(&self, normalized_coords: &[f32]) -> Vec<f32>
pub fn denormalize_coordinates(&self, normalized_coords: &[f32]) -> Vec<f32>
Converts normalized coordinates to pixel coordinates.
§Arguments
normalized_coords- Vector of normalized coordinates (0.0 to 1.0).
§Returns
Vec<f32>- Vector of pixel coordinates.
§Examples
use oar_ocr_core::processors::UVDocPostProcess;
let postprocessor = UVDocPostProcess::new(100.0);
let normalized = vec![0.1, 0.2, 0.8, 0.9];
let pixels = postprocessor.denormalize_coordinates(&normalized);
assert_eq!(pixels, vec![10.0, 20.0, 80.0, 90.0]);Sourcepub fn normalize_coordinates(&self, pixel_coords: &[f32]) -> Vec<f32>
pub fn normalize_coordinates(&self, pixel_coords: &[f32]) -> Vec<f32>
Converts pixel coordinates to normalized coordinates.
§Arguments
pixel_coords- Vector of pixel coordinates.
§Returns
Vec<f32>- Vector of normalized coordinates (0.0 to 1.0).
§Examples
use oar_ocr_core::processors::UVDocPostProcess;
let postprocessor = UVDocPostProcess::new(100.0);
let pixels = vec![10.0, 20.0, 80.0, 90.0];
let normalized = postprocessor.normalize_coordinates(&pixels);
assert_eq!(normalized, vec![0.1, 0.2, 0.8, 0.9]);Sourcepub fn process_bbox(&self, bbox: &[f32; 4]) -> [f32; 4]
pub fn process_bbox(&self, bbox: &[f32; 4]) -> [f32; 4]
Processes a bounding box from normalized to pixel coordinates.
§Arguments
bbox- Bounding box as [x1, y1, x2, y2] in normalized coordinates.
§Returns
[f32; 4]- Bounding box in pixel coordinates.
§Examples
use oar_ocr_core::processors::UVDocPostProcess;
let postprocessor = UVDocPostProcess::new(100.0);
let normalized_bbox = [0.1, 0.2, 0.8, 0.9];
let pixel_bbox = postprocessor.process_bbox(&normalized_bbox);
assert_eq!(pixel_bbox, [10.0, 20.0, 80.0, 90.0]);Sourcepub fn process_polygon(&self, polygon: &[[f32; 2]]) -> Vec<[f32; 2]>
pub fn process_polygon(&self, polygon: &[[f32; 2]]) -> Vec<[f32; 2]>
Processes a polygon from normalized to pixel coordinates.
§Arguments
polygon- Vector of points as [x, y] pairs in normalized coordinates.
§Returns
Vec<[f32; 2]>- Vector of points in pixel coordinates.
§Examples
use oar_ocr_core::processors::UVDocPostProcess;
let postprocessor = UVDocPostProcess::new(100.0);
let normalized_polygon = vec![[0.1, 0.2], [0.8, 0.2], [0.8, 0.9], [0.1, 0.9]];
let pixel_polygon = postprocessor.process_polygon(&normalized_polygon);
assert_eq!(pixel_polygon[0], [10.0, 20.0]);Sourcepub fn round_coordinates(&self, coords: &[f32]) -> Vec<i32>
pub fn round_coordinates(&self, coords: &[f32]) -> Vec<i32>
Sourcepub fn apply_inverse_transform(
&self,
coords: &[[f32; 2]],
matrix: &[f32; 9],
) -> Result<Vec<[f32; 2]>, OCRError>
pub fn apply_inverse_transform( &self, coords: &[[f32; 2]], matrix: &[f32; 9], ) -> Result<Vec<[f32; 2]>, OCRError>
Trait Implementations§
Source§impl Debug for UVDocPostProcess
impl Debug for UVDocPostProcess
Source§impl Default for UVDocPostProcess
impl Default for UVDocPostProcess
Source§fn default() -> UVDocPostProcess
fn default() -> UVDocPostProcess
Creates a default UVDocPostProcess with scale factor 1.0.
Source§impl FromStr for UVDocPostProcess
impl FromStr for UVDocPostProcess
Source§fn from_str(
s: &str,
) -> Result<UVDocPostProcess, <UVDocPostProcess as FromStr>::Err>
fn from_str( s: &str, ) -> Result<UVDocPostProcess, <UVDocPostProcess as FromStr>::Err>
Source§type Err = ParseFloatError
type Err = ParseFloatError
The associated error which can be returned from parsing.
Auto Trait Implementations§
impl Freeze for UVDocPostProcess
impl RefUnwindSafe for UVDocPostProcess
impl Send for UVDocPostProcess
impl Sync for UVDocPostProcess
impl Unpin for UVDocPostProcess
impl UnwindSafe for UVDocPostProcess
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
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<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().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.