Skip to main content

BoundingBox

Struct BoundingBox 

Source
pub struct BoundingBox {
    pub points: Vec<Point>,
}
Expand description

A bounding box represented by a collection of points.

Fields§

§points: Vec<Point>

The points that define the bounding box.

Implementations§

Source§

impl BoundingBox

Source

pub fn new(points: Vec<Point>) -> BoundingBox

Creates a new bounding box from a vector of points.

§Arguments
  • points - A vector of points that define the bounding box.
§Returns

A new BoundingBox instance.

Source

pub fn from_coords(x1: f32, y1: f32, x2: f32, y2: f32) -> BoundingBox

Creates a bounding box from coordinates.

§Arguments
  • x1 - The x-coordinate of the top-left corner.
  • y1 - The y-coordinate of the top-left corner.
  • x2 - The x-coordinate of the bottom-right corner.
  • y2 - The y-coordinate of the bottom-right corner.
§Returns

A new BoundingBox instance representing a rectangle.

Source

pub fn translate(&self, dx: f32, dy: f32) -> BoundingBox

Returns a new bounding box translated by (dx, dy).

Source

pub fn from_contour(contour: &Contour<u32>) -> BoundingBox

Creates a bounding box from a contour.

§Arguments
  • contour - A reference to a contour from imageproc.
§Returns

A new BoundingBox instance with points converted from the contour.

Source

pub fn area(&self) -> f32

Calculates the area of the bounding box using the shoelace formula.

§Returns

The area of the bounding box. Returns 0.0 if the bounding box has fewer than 3 points.

Source

pub fn perimeter(&self) -> f32

Calculates the perimeter of the bounding box.

§Returns

The perimeter of the bounding box.

Source

pub fn x_min(&self) -> f32

Gets the minimum x-coordinate of all points in the bounding box.

§Returns

The minimum x-coordinate, or 0.0 if there are no points.

Source

pub fn y_min(&self) -> f32

Gets the minimum y-coordinate of all points in the bounding box.

§Returns

The minimum y-coordinate, or 0.0 if there are no points.

Source

pub fn get_min_area_rect(&self) -> MinAreaRect

Computes the minimum area rectangle that encloses the bounding box.

This method uses the rotating calipers algorithm on the convex hull of the bounding box to find the minimum area rectangle.

§Returns

A MinAreaRect representing the minimum area rectangle. If the bounding box has fewer than 3 points, returns a rectangle with zero dimensions.

Source

pub fn approx_poly_dp(&self, epsilon: f32) -> BoundingBox

Approximates a polygon using the Douglas-Peucker algorithm.

§Arguments
  • epsilon - The maximum distance between the original curve and the simplified curve.
§Returns

A new BoundingBox with simplified points. If the bounding box has 2 or fewer points, returns a clone of the original bounding box.

Source

pub fn x_max(&self) -> f32

Gets the maximum x-coordinate of all points in the bounding box.

§Returns

The maximum x-coordinate, or 0.0 if there are no points.

Source

pub fn y_max(&self) -> f32

Gets the maximum y-coordinate of all points in the bounding box.

§Returns

The maximum y-coordinate, or 0.0 if there are no points.

Source

pub fn center(&self) -> Point

Gets the geometric center (centroid) of the bounding box.

§Returns

The center point of the bounding box.

Source

pub fn intersection_area(&self, other: &BoundingBox) -> f32

Computes the area of intersection between this bounding box and another.

§Arguments
  • other - The other bounding box.
§Returns

The area of the intersection. Returns 0.0 if there is no intersection.

Source

pub fn iou(&self, other: &BoundingBox) -> f32

Computes the Intersection over Union (IoU) between this bounding box and another.

§Arguments
  • other - The other bounding box to compute IoU with.
§Returns

The IoU value between 0.0 and 1.0. Returns 0.0 if there is no intersection.

Source

pub fn ioa(&self, other: &BoundingBox) -> f32

Computes the Intersection over Area (IoA) of this bounding box with another.

IoA = intersection_area / self_area

This is useful for determining what fraction of this box is inside another box. For example, to check if a text box is mostly inside a table region.

§Arguments
  • other - The other bounding box to compute IoA with.
§Returns

The IoA value between 0.0 and 1.0. Returns 0.0 if self has zero area or no intersection.

Source

pub fn union(&self, other: &BoundingBox) -> BoundingBox

Computes the union (minimum bounding box) of this bounding box and another.

§Arguments
  • other - The other bounding box to compute the union with.
§Returns

A new BoundingBox that encloses both input bounding boxes.

Source

pub fn is_fully_inside(&self, container: &BoundingBox, tolerance: f32) -> bool

Checks if this bounding box is fully inside another bounding box.

§Arguments
  • container - The bounding box to check if this box is inside.
  • tolerance - Optional tolerance in pixels for boundary checks (default: 0.0).
§Returns

true if this bounding box is fully contained within the container, false otherwise.

Source

pub fn overlaps_with(&self, other: &BoundingBox, threshold: f32) -> bool

Checks if this bounding box overlaps with another bounding box.

Two boxes are considered overlapping if their intersection has both width and height greater than the specified threshold.

This follows standard approach for checking box overlap.

§Arguments
  • other - The other bounding box to check overlap with.
  • threshold - Minimum intersection dimension (default: 3.0 pixels).
§Returns

true if the boxes overlap significantly, false otherwise.

Source

pub fn rotate_back_to_original( &self, rotation_angle: f32, rotated_width: u32, rotated_height: u32, ) -> BoundingBox

Rotates this bounding box to compensate for document orientation correction.

When a document is rotated during preprocessing (e.g., 90°, 180°, 270°), detection boxes are in the rotated image’s coordinate system. This method transforms boxes back to the original image’s coordinate system.

§Arguments
  • rotation_angle - The rotation angle that was applied to correct the image (0°, 90°, 180°, 270°)
  • rotated_width - Width of the image after rotation (i.e., the corrected image width)
  • rotated_height - Height of the image after rotation (i.e., the corrected image height)
§Returns

A new BoundingBox with points transformed back to the original coordinate system.

§Note

The rotation transformations are:

  • 90° correction: boxes rotated 90° clockwise (original was 90° counter-clockwise)
  • 180° correction: boxes rotated 180°
  • 270° correction: boxes rotated 270° clockwise (original was 270° counter-clockwise)

Trait Implementations§

Source§

impl Clone for BoundingBox

Source§

fn clone(&self) -> BoundingBox

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BoundingBox

Source§

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

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

impl<'de> Deserialize<'de> for BoundingBox

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<BoundingBox, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for BoundingBox

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,