From 74c603dc37bfdce1f8cbcd05998c204c17e3e313 Mon Sep 17 00:00:00 2001 From: uttarayan21 Date: Tue, 5 Aug 2025 02:10:14 +0530 Subject: [PATCH] broken(retinaface): Added drawing for bounding box --- Cargo.lock | 2 +- Cargo.toml | 12 ++++++------ bounding-box/src/draw.rs | 29 +++++++++++++++++------------ bounding-box/src/lib.rs | 3 ++- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12effd0..88537b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,7 +211,7 @@ dependencies = [ "bitflags 2.9.1", "cexpr", "clang-sys", - "itertools 0.13.0", + "itertools 0.12.1", "log", "prettyplease", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index a38bc79..8000e7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,21 +6,21 @@ version = "0.1.0" edition = "2024" [patch."https://github.com/uttarayan21/mnn-rs"] -mnn = { path = "/Users/fs0c131y/Projects/aftershoot/mnn-rs" } +mnn = { path = "/home/servius/Projects/mnn-rs" } [workspace.dependencies] ndarray-image = { path = "ndarray-image" } ndarray-resize = { path = "ndarray-resize" } mnn = { git = "https://github.com/uttarayan21/mnn-rs", version = "0.2.0", features = [ - "metal", - "coreml", - "tracing", + # "metal", + # "coreml", + "tracing", ], branch = "restructure-tensor-type" } mnn-bridge = { git = "https://github.com/uttarayan21/mnn-rs", version = "0.1.0", features = [ - "ndarray", + "ndarray", ], branch = "restructure-tensor-type" } mnn-sync = { git = "https://github.com/uttarayan21/mnn-rs", version = "0.1.0", features = [ - "tracing", + "tracing", ], branch = "restructure-tensor-type" } [package] diff --git a/bounding-box/src/draw.rs b/bounding-box/src/draw.rs index 1fa0b0e..3216599 100644 --- a/bounding-box/src/draw.rs +++ b/bounding-box/src/draw.rs @@ -45,21 +45,26 @@ impl Drawable> for Aabb2 { impl Drawable> for Aabb2 { fn draw(&self, canvas: &mut Array3, 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 pixel_size = canvas.dim().2; let color = color.slice(ndarray::s![..pixel_size]); let [x1y1, x2y1, x1y2, x2y2] = self.corners(); - let right = Aabb2::from_x1y1x2y2(x1y1.x, x1y1.y, x2y1.x, x2y1.y + thickness); - dbg!(right); - canvas - .roi_mut(right) - .expect("Failed to get ROI") - .lanes_mut(ndarray::Axis(2)) - .into_iter() - .for_each(|mut pixel| { - pixel.assign(&color); - }); + dbg!(self.corners()); + 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 + .roi_mut(line) + .expect("Failed to get Roi") + .lanes_mut(ndarray::Axis(2)) + .into_iter() + .for_each(|mut pixel| { + pixel.assign(&color); + }); + }); } } diff --git a/bounding-box/src/lib.rs b/bounding-box/src/lib.rs index ffa0bf2..cc04732 100644 --- a/bounding-box/src/lib.rs +++ b/bounding-box/src/lib.rs @@ -235,12 +235,13 @@ impl AxisAlignedBoundingBox { } impl Aabb2 { - 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 T: core::ops::SubAssign, { let point1 = Point2::new(x1, y1); let point2 = Point2::new(x2, y2); + dbg!(point1, point2); Self::from_min_max_vertices(point1, point2) } pub fn new_2d(point1: Point2, point2: Point2) -> Self