broken(retinaface): Added drawing for bounding box

This commit is contained in:
uttarayan21
2025-08-05 02:10:14 +05:30
parent 9fd0993cc3
commit 74c603dc37
4 changed files with 26 additions and 20 deletions

2
Cargo.lock generated
View File

@@ -211,7 +211,7 @@ dependencies = [
"bitflags 2.9.1", "bitflags 2.9.1",
"cexpr", "cexpr",
"clang-sys", "clang-sys",
"itertools 0.13.0", "itertools 0.12.1",
"log", "log",
"prettyplease", "prettyplease",
"proc-macro2", "proc-macro2",

View File

@@ -6,14 +6,14 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[patch."https://github.com/uttarayan21/mnn-rs"] [patch."https://github.com/uttarayan21/mnn-rs"]
mnn = { path = "/Users/fs0c131y/Projects/aftershoot/mnn-rs" } mnn = { path = "/home/servius/Projects/mnn-rs" }
[workspace.dependencies] [workspace.dependencies]
ndarray-image = { path = "ndarray-image" } ndarray-image = { path = "ndarray-image" }
ndarray-resize = { path = "ndarray-resize" } ndarray-resize = { path = "ndarray-resize" }
mnn = { git = "https://github.com/uttarayan21/mnn-rs", version = "0.2.0", features = [ mnn = { git = "https://github.com/uttarayan21/mnn-rs", version = "0.2.0", features = [
"metal", # "metal",
"coreml", # "coreml",
"tracing", "tracing",
], branch = "restructure-tensor-type" } ], branch = "restructure-tensor-type" }
mnn-bridge = { git = "https://github.com/uttarayan21/mnn-rs", version = "0.1.0", features = [ mnn-bridge = { git = "https://github.com/uttarayan21/mnn-rs", version = "0.1.0", features = [

View File

@@ -45,21 +45,26 @@ impl Drawable<ArrayViewMut3<'_, u8>> for Aabb2<usize> {
impl Drawable<Array3<u8>> for Aabb2<usize> { impl Drawable<Array3<u8>> for Aabb2<usize> {
fn draw(&self, canvas: &mut Array3<u8>, color: color::Rgba8, thickness: usize) { fn draw(&self, canvas: &mut Array3<u8>, color: color::Rgba8, thickness: usize) {
use itertools::Itertools;
// let (height, width, channels) = canvas.dim();
let color = Array1::from_vec(vec![color.r, color.g, color.b, color.a]); let color = Array1::from_vec(vec![color.r, color.g, color.b, color.a]);
let pixel_size = canvas.dim().2; let pixel_size = canvas.dim().2;
let color = color.slice(ndarray::s![..pixel_size]); let color = color.slice(ndarray::s![..pixel_size]);
let [x1y1, x2y1, x1y2, x2y2] = self.corners(); let [x1y1, x2y1, x1y2, x2y2] = self.corners();
let right = Aabb2::from_x1y1x2y2(x1y1.x, x1y1.y, x2y1.x, x2y1.y + thickness); dbg!(self.corners());
dbg!(right); let top = Aabb2::from_x1y1x2y2(x1y1.x, x1y1.y, x2y1.x, x2y1.y + thickness);
let bottom = Aabb2::from_x1y1x2y2(x2y2.x, x2y2.y, x1y2.x, x1y2.y + thickness);
let left = Aabb2::from_x1y1x2y2(x1y1.x, x1y1.y, x1y2.x + thickness, x1y2.y);
// let right = Aabb2::from_x1y1x2y2(x2y2.x, x2y2.y, x2y1.x + thickness, x2y1.y);
let lines = [top, bottom, left /* right */];
lines.into_iter().for_each(|line| {
dbg!(line);
canvas canvas
.roi_mut(right) .roi_mut(line)
.expect("Failed to get ROI") .expect("Failed to get Roi")
.lanes_mut(ndarray::Axis(2)) .lanes_mut(ndarray::Axis(2))
.into_iter() .into_iter()
.for_each(|mut pixel| { .for_each(|mut pixel| {
pixel.assign(&color); pixel.assign(&color);
}); });
});
} }
} }

View File

@@ -235,12 +235,13 @@ impl<T: Num, const D: usize> AxisAlignedBoundingBox<T, D> {
} }
impl<T: Num> Aabb2<T> { impl<T: Num> Aabb2<T> {
pub fn from_x1y1x2y2(x1: T, x2: T, y1: T, y2: T) -> Self pub fn from_x1y1x2y2(x1: T, y1: T, x2: T, y2: T) -> Self
where where
T: core::ops::SubAssign, T: core::ops::SubAssign,
{ {
let point1 = Point2::new(x1, y1); let point1 = Point2::new(x1, y1);
let point2 = Point2::new(x2, y2); let point2 = Point2::new(x2, y2);
dbg!(point1, point2);
Self::from_min_max_vertices(point1, point2) Self::from_min_max_vertices(point1, point2)
} }
pub fn new_2d(point1: Point2<T>, point2: Point2<T>) -> Self pub fn new_2d(point1: Point2<T>, point2: Point2<T>) -> Self