feat: Added postprocessing for retinaface

This commit is contained in:
uttarayan21
2025-08-04 19:27:45 +05:30
parent f55f0ab089
commit df5584d797
8 changed files with 235 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
pub mod draw;
pub mod nms;
pub mod roi;
use nalgebra::{Point, Point2, Point3, SVector};
pub trait Num: num::Num + Copy + core::fmt::Debug + 'static {}
@@ -31,6 +32,8 @@ impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
Self::new(point1, SVector::from(size))
}
/// Only considers the points closest and furthest from origin
/// Points which are rotated along in the z axis (in 2d) are not considered
pub fn from_vertices(points: [Point<T, D>; 4]) -> Option<Self>
where
T: core::ops::SubAssign,
@@ -182,9 +185,51 @@ impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
Point::from(max),
))
}
pub fn denormalize(&self, factor: nalgebra::SVector<T, D>) -> Self
where
T: core::ops::MulAssign,
T: core::ops::AddAssign,
// nalgebra::constraint::ShapeConstraint:
// nalgebra::constraint::DimEq<nalgebra::Const<D>, nalgebra::Const<D>>,
{
Self {
point: (self.point.coords.component_mul(&factor)).into(),
size: self.size.component_mul(&factor),
}
}
pub fn cast<T2>(&self) -> Option<Aabb<T2, D>>
where
// T: num::NumCast,
T2: Num + simba::scalar::SubsetOf<T>,
{
Some(Aabb {
point: Point::from(self.point.coords.try_cast::<T2>()?),
size: self.size.try_cast::<T2>()?,
})
}
// pub fn as_<T2>(&self) -> Option<Aabb<T2, D>>
// where
// T2: Num + simba::scalar::SubsetOf<T>,
// {
// Some(Aabb {
// point: Point::from(self.point.coords.as_()),
// size: self.size.as_(),
// })
// }
}
impl<T: Num> Aabb2<T> {
pub fn from_x1y1x2y2(x1: T, x2: T, y1: T, y2: T) -> Self
where
T: core::ops::SubAssign,
{
let point1 = Point2::new(x1, y1);
let point2 = Point2::new(x2, y2);
Self::from_min_max_vertices(point1, point2)
}
pub fn new_2d(point1: Point2<T>, point2: Point2<T>) -> Self
where
T: core::ops::SubAssign,
@@ -217,6 +262,28 @@ impl<T: Num> Aabb2<T> {
Point2::new(self.point.x, self.point.y + self.size.y)
}
pub fn x1(&self) -> T {
self.point.x
}
pub fn y1(&self) -> T {
self.point.y
}
pub fn x2(&self) -> T
where
T: core::ops::AddAssign,
{
self.point.x + self.size.x
}
pub fn y2(&self) -> T
where
T: core::ops::AddAssign,
{
self.point.y + self.size.y
}
pub fn corners(&self) -> [Point2<T>; 4]
where
T: core::ops::AddAssign,