fix: A lot of fixes relating to bounding-boxes

This commit is contained in:
uttarayan21
2025-08-05 14:39:16 +05:30
parent 561fb2a924
commit 42ac210bba
4 changed files with 104 additions and 42 deletions

View File

@@ -62,9 +62,18 @@ pub struct FaceDetectionModelOutput {
pub landmark: ndarray::Array3<f32>,
}
/// Represents the 5 facial landmarks detected by RetinaFace
pub struct FaceLandmarks {
pub left_eye: Point2<f32>,
pub right_eye: Point2<f32>,
pub nose: Point2<f32>,
pub left_mouth: Point2<f32>,
pub right_mouth: Point2<f32>,
}
pub struct FaceDetectionProcessedOutput {
pub bbox: Vec<Aabb2<f32>>,
pub confidence: Vec<f32>,
pub landmarks: Vec<FaceLandmarks>,
}
impl FaceDetectionModelOutput {
@@ -87,10 +96,12 @@ impl FaceDetectionModelOutput {
}
let mut boxes = Vec::new();
let mut scores = Vec::new();
let mut landmarks = Vec::new();
let var0 = config.variance[0];
let var1 = config.variance[1];
let bbox_data = self.bbox;
let conf_data = self.confidence;
let landmark_data = self.landmark;
let num_priors = bbox_data.shape()[1];
for idx in 0..num_priors {
let dx = bbox_data[[0, idx, 0]];
@@ -110,11 +121,35 @@ impl FaceDetectionModelOutput {
if score > config.threshold {
boxes.push(Aabb2::from_x1y1x2y2(x_min, y_min, x_max, y_max));
scores.push(score);
let left_eye_x = landmark_data[[0, idx, 0]] * anchor_w * var0 + anchor_cx;
let left_eye_y = landmark_data[[0, idx, 1]] * anchor_h * var0 + anchor_cy;
let right_eye_x = landmark_data[[0, idx, 2]] * anchor_w * var0 + anchor_cx;
let right_eye_y = landmark_data[[0, idx, 3]] * anchor_h * var0 + anchor_cy;
let nose_x = landmark_data[[0, idx, 4]] * anchor_w * var0 + anchor_cx;
let nose_y = landmark_data[[0, idx, 5]] * anchor_h * var0 + anchor_cy;
let left_mouth_x = landmark_data[[0, idx, 6]] * anchor_w * var0 + anchor_cx;
let left_mouth_y = landmark_data[[0, idx, 7]] * anchor_h * var0 + anchor_cy;
let right_mouth_x = landmark_data[[0, idx, 8]] * anchor_w * var0 + anchor_cx;
let right_mouth_y = landmark_data[[0, idx, 9]] * anchor_h * var0 + anchor_cy;
landmarks.push(FaceLandmarks {
left_eye: Point2::new(left_eye_x, left_eye_y),
right_eye: Point2::new(right_eye_x, right_eye_y),
nose: Point2::new(nose_x, nose_y),
left_mouth: Point2::new(left_mouth_x, left_mouth_y),
right_mouth: Point2::new(right_mouth_x, right_mouth_y),
});
}
}
Ok(FaceDetectionProcessedOutput {
bbox: boxes,
confidence: scores,
landmarks,
})
}
}