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
impl BoundingBox
Sourcepub fn new(points: Vec<Point>) -> BoundingBox
pub fn new(points: Vec<Point>) -> BoundingBox
Sourcepub fn from_coords(x1: f32, y1: f32, x2: f32, y2: f32) -> BoundingBox
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.
Sourcepub fn translate(&self, dx: f32, dy: f32) -> BoundingBox
pub fn translate(&self, dx: f32, dy: f32) -> BoundingBox
Returns a new bounding box translated by (dx, dy).
Sourcepub fn from_contour(contour: &Contour<u32>) -> BoundingBox
pub fn from_contour(contour: &Contour<u32>) -> BoundingBox
Sourcepub fn area(&self) -> f32
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.
Sourcepub fn x_min(&self) -> f32
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.
Sourcepub fn y_min(&self) -> f32
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.
Sourcepub fn get_min_area_rect(&self) -> MinAreaRect
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.
Sourcepub fn approx_poly_dp(&self, epsilon: f32) -> BoundingBox
pub fn approx_poly_dp(&self, epsilon: f32) -> BoundingBox
Sourcepub fn x_max(&self) -> f32
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.
Sourcepub fn y_max(&self) -> f32
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.
Sourcepub fn center(&self) -> Point
pub fn center(&self) -> Point
Gets the geometric center (centroid) of the bounding box.
§Returns
The center point of the bounding box.
Sourcepub fn intersection_area(&self, other: &BoundingBox) -> f32
pub fn intersection_area(&self, other: &BoundingBox) -> f32
Sourcepub fn iou(&self, other: &BoundingBox) -> f32
pub fn iou(&self, other: &BoundingBox) -> f32
Sourcepub fn ioa(&self, other: &BoundingBox) -> f32
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.
Sourcepub fn union(&self, other: &BoundingBox) -> BoundingBox
pub fn union(&self, other: &BoundingBox) -> BoundingBox
Sourcepub fn is_fully_inside(&self, container: &BoundingBox, tolerance: f32) -> bool
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.
Sourcepub fn overlaps_with(&self, other: &BoundingBox, threshold: f32) -> bool
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.
Sourcepub fn rotate_back_to_original(
&self,
rotation_angle: f32,
rotated_width: u32,
rotated_height: u32,
) -> BoundingBox
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
impl Clone for BoundingBox
Source§fn clone(&self) -> BoundingBox
fn clone(&self) -> BoundingBox
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BoundingBox
impl Debug for BoundingBox
Source§impl<'de> Deserialize<'de> for BoundingBox
impl<'de> Deserialize<'de> for BoundingBox
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<BoundingBox, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<BoundingBox, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for BoundingBox
impl Serialize for BoundingBox
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for BoundingBox
impl RefUnwindSafe for BoundingBox
impl Send for BoundingBox
impl Sync for BoundingBox
impl Unpin for BoundingBox
impl UnwindSafe for BoundingBox
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<T> Pointable for T
impl<T> Pointable 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.