pub struct DetectionBox {
pub x1: f64,
pub y1: f64,
pub x2: f64,
pub y2: f64,
pub confidence: f64,
pub class_id: usize,
pub class_name: Option<String>,
}Expand description
A bounding box for object detection, stored as (x1, y1, x2, y2) corner format.
All coordinates use f64 precision. The box additionally carries optional
confidence, class id, and class name fields used throughout detection pipelines.
Fields§
§x1: f64Top-left x coordinate
y1: f64Top-left y coordinate
x2: f64Bottom-right x coordinate
y2: f64Bottom-right y coordinate
confidence: f64Detection confidence score in [0, 1]
class_id: usizeClass identifier (0-indexed)
class_name: Option<String>Optional human-readable class name
Implementations§
Source§impl DetectionBox
impl DetectionBox
Sourcepub fn new(x1: f64, y1: f64, x2: f64, y2: f64) -> Self
pub fn new(x1: f64, y1: f64, x2: f64, y2: f64) -> Self
Create a new detection box from corner coordinates.
Coordinates are normalised so that x1 <= x2 and y1 <= y2.
Sourcepub fn from_center(cx: f64, cy: f64, w: f64, h: f64) -> Self
pub fn from_center(cx: f64, cy: f64, w: f64, h: f64) -> Self
Create a detection box from centre coordinates and dimensions.
§Arguments
cx- Centre xcy- Centre yw- Width (must be non-negative)h- Height (must be non-negative)
Sourcepub fn with_confidence(self, confidence: f64) -> Self
pub fn with_confidence(self, confidence: f64) -> Self
Builder: set confidence score.
Sourcepub fn with_class(self, class_id: usize, class_name: Option<String>) -> Self
pub fn with_class(self, class_id: usize, class_name: Option<String>) -> Self
Builder: set class id and optional name.
Sourcepub fn aspect_ratio(&self) -> f64
pub fn aspect_ratio(&self) -> f64
Aspect ratio (width / height). Returns 0.0 if height is zero.
Sourcepub fn intersection_area(&self, other: &DetectionBox) -> f64
pub fn intersection_area(&self, other: &DetectionBox) -> f64
Intersection area with another box.
Sourcepub fn union_area(&self, other: &DetectionBox) -> f64
pub fn union_area(&self, other: &DetectionBox) -> f64
Union area with another box.
Sourcepub fn iou(&self, other: &DetectionBox) -> f64
pub fn iou(&self, other: &DetectionBox) -> f64
Intersection over Union (IoU).
Returns 0.0 when the union area is zero.
Sourcepub fn giou(&self, other: &DetectionBox) -> f64
pub fn giou(&self, other: &DetectionBox) -> f64
Generalized Intersection over Union (GIoU).
GIoU = IoU - |C \ (A union B)| / |C| where C is the smallest enclosing box. Range: [-1, 1]
Sourcepub fn diou(&self, other: &DetectionBox) -> f64
pub fn diou(&self, other: &DetectionBox) -> f64
Distance-IoU (DIoU).
DIoU = IoU - d^2 / c^2 where d is the Euclidean distance between centres and c is the diagonal length of the smallest enclosing box.
Sourcepub fn ciou(&self, other: &DetectionBox) -> f64
pub fn ciou(&self, other: &DetectionBox) -> f64
Complete-IoU (CIoU).
CIoU = IoU - d^2/c^2 - alpha * v where v measures aspect-ratio consistency and alpha is a trade-off parameter.
Sourcepub fn contains_point(&self, px: f64, py: f64) -> bool
pub fn contains_point(&self, px: f64, py: f64) -> bool
Check whether a point (px, py) lies inside this box (inclusive).
Trait Implementations§
Source§impl Clone for DetectionBox
impl Clone for DetectionBox
Source§fn clone(&self) -> DetectionBox
fn clone(&self) -> DetectionBox
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DetectionBox
impl Debug for DetectionBox
Source§impl PartialEq for DetectionBox
impl PartialEq for DetectionBox
impl StructuralPartialEq for DetectionBox
Auto Trait Implementations§
impl Freeze for DetectionBox
impl RefUnwindSafe for DetectionBox
impl Send for DetectionBox
impl Sync for DetectionBox
impl Unpin for DetectionBox
impl UnsafeUnpin for DetectionBox
impl UnwindSafe for DetectionBox
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> 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.