DocTrPostProcess

Struct DocTrPostProcess 

Source
pub struct DocTrPostProcess {
    pub scale: f32,
}
Expand description

Post-processor for document transformation results.

The DocTrPostProcess struct handles the post-processing of document transformation model outputs, converting normalized coordinates back to pixel coordinates and applying various transformations.

Fields§

§scale: f32

Scale factor to convert normalized values back to pixel values.

Implementations§

Source§

impl DocTrPostProcess

Source

pub fn new(scale: f32) -> Self

Creates a new DocTrPostProcess instance.

§Arguments
  • scale - Scale factor for converting normalized coordinates to pixels.
§Examples
use oar_ocr::processors::DocTrPostProcess;

let postprocessor = DocTrPostProcess::new(1.0);
Source

pub fn scale(&self) -> f32

Gets the current scale factor.

§Returns

The scale factor used for coordinate conversion.

Source

pub fn set_scale(&mut self, scale: f32)

Sets a new scale factor.

§Arguments
  • scale - New scale factor.
Source

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::processors::DocTrPostProcess;

let postprocessor = DocTrPostProcess::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]);
Source

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::processors::DocTrPostProcess;

let postprocessor = DocTrPostProcess::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]);
Source

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::processors::DocTrPostProcess;

let postprocessor = DocTrPostProcess::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]);
Source

pub fn process_bboxes(&self, bboxes: &[[f32; 4]]) -> Vec<[f32; 4]>

Processes multiple bounding boxes.

§Arguments
  • bboxes - Vector of bounding boxes in normalized coordinates.
§Returns
  • Vec<[f32; 4]> - Vector of bounding boxes in pixel coordinates.
Source

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::processors::DocTrPostProcess;

let postprocessor = DocTrPostProcess::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]);
Source

pub fn clamp_coordinates( &self, coords: &[f32], min_val: f32, max_val: f32, ) -> Vec<f32>

Clamps coordinates to valid ranges.

§Arguments
  • coords - Vector of coordinates to clamp.
  • min_val - Minimum allowed value.
  • max_val - Maximum allowed value.
§Returns
  • Vec<f32> - Vector of clamped coordinates.
Source

pub fn validate_coordinates( &self, coords: &[f32], min_val: f32, max_val: f32, ) -> bool

Validates that coordinates are within expected ranges.

§Arguments
  • coords - Vector of coordinates to validate.
  • min_val - Minimum expected value.
  • max_val - Maximum expected value.
§Returns
  • true - If all coordinates are within range.
  • false - If any coordinate is out of range.
Source

pub fn round_coordinates(&self, coords: &[f32]) -> Vec<i32>

Rounds coordinates to integer values.

§Arguments
  • coords - Vector of coordinates to round.
§Returns
  • Vec<i32> - Vector of rounded integer coordinates.
Source

pub fn process_transformation_matrix(&self, matrix: &[f32; 9]) -> [f32; 9]

Processes transformation matrix values.

§Arguments
  • matrix - 3x3 transformation matrix as a flat vector.
§Returns
  • Vec<f32> - Processed transformation matrix.
Source

pub fn apply_inverse_transform( &self, coords: &[[f32; 2]], matrix: &[f32; 9], ) -> Result<Vec<[f32; 2]>, String>

Applies inverse transformation to coordinates.

§Arguments
  • coords - Vector of coordinates to transform.
  • matrix - 3x3 transformation matrix.
§Returns
  • Result<Vec<[f32; 2]>, String> - Transformed coordinates or error.
Source

pub fn apply_batch(&self, output: &Tensor4D) -> Result<Vec<RgbImage>, String>

Applies batch processing to tensor output to produce rectified images.

§Arguments
  • output - 4D tensor output from the model [batch, channels, height, width].
§Returns
  • Result<Vec<image::RgbImage>, String> - Vector of rectified images or error.

Trait Implementations§

Source§

impl Debug for DocTrPostProcess

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DocTrPostProcess

Source§

fn default() -> Self

Creates a default DocTrPostProcess with scale factor 1.0.

Source§

impl FromStr for DocTrPostProcess

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Creates a DocTrPostProcess from a string representation of the scale factor.

§Arguments
  • s - String representation of the scale factor.
§Returns
  • Ok(DocTrPostProcess) - If the string can be parsed as a float.
  • Err(ParseFloatError) - If the string cannot be parsed.
Source§

type Err = ParseFloatError

The associated error which can be returned from parsing.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

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§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

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 SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more