Struct object_detector_rust::bbox::BBox
source · pub struct BBox {
pub x: i32,
pub y: i32,
pub width: u32,
pub height: u32,
}Expand description
Struct for representing a bounding box
Fields§
§x: i32X coordinate of the top-left corner of the bounding box
y: i32Y coordinate of the top-left corner of the bounding box
width: u32Width of the bounding box
height: u32Height of the bounding box
Implementations§
source§impl BBox
impl BBox
sourcepub fn new(x: i32, y: i32, width: u32, height: u32) -> BBox
pub fn new(x: i32, y: i32, width: u32, height: u32) -> BBox
Creates a new bounding box with the specified coordinates and dimensions
sourcepub fn intersect_width(&self, other: &BBox) -> u32
pub fn intersect_width(&self, other: &BBox) -> u32
Calculates the width of the intersection between two bounding boxes
Examples
use object_detector_rust::bbox::BBox;
let bbox1 = BBox {
x: 0,
y: 0,
width: 100,
height: 100,
};
let bbox2 = BBox {
x: 50,
y: 0,
width: 100,
height: 100,
};
let bbox3 = BBox {
x: 150,
y: 0,
width: 100,
height: 100,
};
let bbox4 = BBox {
x: -50,
y: 0,
width: 100,
height: 100,
};
assert_eq!(bbox1.intersect_width(&bbox2), 50);
assert_eq!(bbox1.intersect_width(&bbox3), 0);
assert_eq!(bbox1.intersect_width(&bbox4), 50);
assert_eq!(bbox2.intersect_width(&bbox3), 0);
assert_eq!(bbox2.intersect_width(&bbox4), 0);
assert_eq!(bbox3.intersect_width(&bbox4), 0);sourcepub fn intersect_height(&self, other: &BBox) -> u32
pub fn intersect_height(&self, other: &BBox) -> u32
Calculates the height of the intersection between two bounding boxes
Examples
use object_detector_rust::bbox::BBox;
let bbox1 = BBox {
x: 0,
y: 0,
width: 100,
height: 100,
};
let bbox2 = BBox {
x: 0,
y: 50,
width: 100,
height: 100,
};
let bbox3 = BBox {
x: 0,
y: 150,
width: 100,
height: 100,
};
let bbox4 = BBox {
x: 0,
y: -50,
width: 100,
height: 100,
};
assert_eq!(bbox1.intersect_height(&bbox2), 50);
assert_eq!(bbox1.intersect_height(&bbox3), 0);
assert_eq!(bbox1.intersect_height(&bbox4), 50);
assert_eq!(bbox2.intersect_height(&bbox3), 0);
assert_eq!(bbox2.intersect_height(&bbox4), 0);
assert_eq!(bbox3.intersect_height(&bbox4), 0);sourcepub fn intersect_area(&self, other: &BBox) -> u32
pub fn intersect_area(&self, other: &BBox) -> u32
Calculates the area of the intersection between two bounding boxes
Examples
use object_detector_rust::bbox::BBox;
let bbox1 = BBox {
x: 0,
y: 0,
width: 100,
height: 100,
};
let bbox2 = BBox {
x: 50,
y: 50,
width: 100,
height: 100,
};
let bbox3 = BBox {
x: 150,
y: 150,
width: 100,
height: 100,
};
assert_eq!(bbox1.intersect_area(&bbox2), 2500);
assert_eq!(bbox1.intersect_area(&bbox3), 0);
assert_eq!(bbox2.intersect_area(&bbox3), 0);sourcepub fn self_area(&self) -> u32
pub fn self_area(&self) -> u32
Calculates the area of the bounding box
Examples
use object_detector_rust::bbox::BBox;
let bbox = BBox {
x: 0,
y: 0,
width: 100,
height: 100,
};
assert_eq!(bbox.self_area(), 10000);sourcepub fn union_area(&self, other: &BBox) -> u32
pub fn union_area(&self, other: &BBox) -> u32
Calculates the area of the union between two bounding boxes
Examples
use object_detector_rust::bbox::BBox;
let bbox1 = BBox {
x: 0,
y: 0,
width: 100,
height: 100,
};
let bbox2 = BBox {
x: 50,
y: 50,
width: 100,
height: 100,
};
assert_eq!(bbox1.union_area(&bbox2), 17500);sourcepub fn overlap(&self, other: &BBox) -> f32
pub fn overlap(&self, other: &BBox) -> f32
Calculates the overlap between two bounding boxes as the ratio of their intersecting area to their union area
Examples
use object_detector_rust::bbox::BBox;
let bbox1 = BBox {
x: 0,
y: 0,
width: 100,
height: 100,
};
let bbox2 = BBox {
x: 50,
y: 50,
width: 100,
height: 100,
};
let bbox3 = BBox {
x: 150,
y: 150,
width: 100,
height: 100,
};
assert!(bbox1.overlap(&bbox2) > 0.14);
assert_eq!(bbox1.overlap(&bbox3), 0.0);
assert_eq!(bbox2.overlap(&bbox3), 0.0);sourcepub fn merge(&self, other: &BBox) -> BBox
pub fn merge(&self, other: &BBox) -> BBox
Merges two bounding boxes into a single bounding box that encloses both
Examples
use object_detector_rust::bbox::BBox;
let bbox1 = BBox {
x: 0,
y: 0,
width: 100,
height: 100,
};
let bbox2 = BBox {
x: 50,
y: 50,
width: 100,
height: 100,
};
let bbox3 = BBox {
x: -50,
y: -50,
width: 100,
height: 100,
};
assert_eq!(bbox1.merge(&bbox2), BBox {
x: 0,
y: 0,
width: 150,
height: 150,
});
assert_eq!(bbox1.merge(&bbox3), BBox {
x: -50,
y: -50,
width: 150,
height: 150,
});Trait Implementations§
source§impl PartialEq<BBox> for BBox
impl PartialEq<BBox> for BBox
impl Copy for BBox
impl StructuralPartialEq for BBox
Auto Trait Implementations§
impl RefUnwindSafe for BBox
impl Send for BBox
impl Sync for BBox
impl Unpin for BBox
impl UnwindSafe for BBox
Blanket Implementations§
§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere Scheme: ApproxScheme,
§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,
§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
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<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
§impl<T> ConvUtil for T
impl<T> ConvUtil for T
§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, DefaultApprox>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where Self: Sized + ApproxInto<Dst, DefaultApprox>,
§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.