feat: Added a manual implementation of nms
This commit is contained in:
@@ -51,10 +51,12 @@ pub type Aabb3<T> = AxisAlignedBoundingBox<T, 3>;
|
||||
impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
|
||||
// Panics if max < min
|
||||
pub fn new(min_point: Point<T, D>, max_point: Point<T, D>) -> Self {
|
||||
if max_point < min_point {
|
||||
if max_point >= min_point {
|
||||
Self::from_min_max_vertices(min_point, max_point)
|
||||
} else {
|
||||
dbg!(max_point, min_point);
|
||||
panic!("max_point must be greater than or equal to min_point");
|
||||
}
|
||||
Self::from_min_max_vertices(min_point, max_point)
|
||||
}
|
||||
pub fn try_new(min_point: Point<T, D>, max_point: Point<T, D>) -> Option<Self> {
|
||||
if max_point < min_point {
|
||||
@@ -66,9 +68,9 @@ impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
|
||||
Self { point, size }
|
||||
}
|
||||
|
||||
pub fn from_min_max_vertices(point1: Point<T, D>, point2: Point<T, D>) -> Self {
|
||||
let size = point2 - point1;
|
||||
Self::new_point_size(point1, SVector::from(size))
|
||||
pub fn from_min_max_vertices(min: Point<T, D>, max: Point<T, D>) -> Self {
|
||||
let size = max - min;
|
||||
Self::new_point_size(min, SVector::from(size))
|
||||
}
|
||||
|
||||
/// Only considers the points closest and furthest from origin
|
||||
@@ -301,11 +303,11 @@ impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
|
||||
|
||||
let inter_min = lhs_min.sup(&rhs_min);
|
||||
let inter_max = lhs_max.inf(&rhs_max);
|
||||
if inter_max < inter_min {
|
||||
return T::zero();
|
||||
} else {
|
||||
if inter_max >= inter_min {
|
||||
let intersection = Aabb::new(inter_min, inter_max).measure();
|
||||
intersection / (self.measure() + other.measure() - intersection)
|
||||
} else {
|
||||
return T::zero();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -605,11 +607,8 @@ mod boudning_box_tests {
|
||||
|
||||
#[test]
|
||||
fn test_specific_values() {
|
||||
let res = Vector2::new(1920, 1080).cast();
|
||||
let box1 = Aabb2::from_xywh(0.69482, 0.6716774, 0.07493961, 0.14968264).denormalize(res);
|
||||
let box2 =
|
||||
Aabb2::from_xywh(0.41546485, 0.70290875, 0.06197411, 0.08818436).denormalize(res);
|
||||
dbg!(box1, box2);
|
||||
assert!(box1.iou(&box2) > 0.0);
|
||||
let box1 = Aabb2::from_xywh(0.69482, 0.6716774, 0.07493961, 0.14968264);
|
||||
let box2 = Aabb2::from_xywh(0.41546485, 0.70290875, 0.06197411, 0.08818436);
|
||||
assert!(box1.iou(&box2) >= 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user