From 55ffe44008d938e5da69ecbd290dbfe2003a6dac Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Fri, 10 Oct 2025 21:40:41 -0700 Subject: [PATCH] scripts/examples: Fix blazeface detector. --- ...e_face_detector.py => blazeface_detector.py} | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) rename scripts/examples/03-Machine-Learning/00-TensorFlow/{blazeface_face_detector.py => blazeface_detector.py} (73%) diff --git a/scripts/examples/03-Machine-Learning/00-TensorFlow/blazeface_face_detector.py b/scripts/examples/03-Machine-Learning/00-TensorFlow/blazeface_detector.py similarity index 73% rename from scripts/examples/03-Machine-Learning/00-TensorFlow/blazeface_face_detector.py rename to scripts/examples/03-Machine-Learning/00-TensorFlow/blazeface_detector.py index f44bb01b5..d859dc4db 100644 --- a/scripts/examples/03-Machine-Learning/00-TensorFlow/blazeface_face_detector.py +++ b/scripts/examples/03-Machine-Learning/00-TensorFlow/blazeface_detector.py @@ -2,12 +2,12 @@ # Copyright (c) 2013-2025 OpenMV LLC. All rights reserved. # https://github.com/openmv/openmv/blob/master/LICENSE # -# This example shows off Google's MediaPipe BlazeFace face detection model. +# This example shows off Google's MediaPipe Face Detection model. import csi import time import ml -from ml.postprocessing import mediapipe_face_detection_postprocess +from ml.postprocessing.mediapipe import BlazeFace # Initialize the sensor. csi0 = csi.CSI() @@ -22,7 +22,12 @@ print(model) # Create the face detection post-processor. This post-processor dynamically # generates anchors for the model input size which should only be done once. -face_detection_postprocess = mediapipe_face_detection_postprocess(threshold=0.6) +face_detection_postprocess = BlazeFace(threshold=0.6) + +# Visualization parameters. +face_labels = ["face"] +face_colors = [(0, 0, 255)] +keypoint_color = (255, 0, 0) clock = time.clock() while True: @@ -35,7 +40,8 @@ while True: # Draw bounding boxes around the detected faces and keypoints. if faces: for r, score, keypoints in faces[0]: - ml.utils.draw_predictions(img, [r], ["face"], [(0, 0, 255)], format=None) + ml.utils.draw_predictions(img, [r], face_labels, face_colors, format=None) + # keypoints is a ndarray of shape (6, 2) # 0 - right eye (x, y) # 1 - left eye (x, y) @@ -43,7 +49,6 @@ while True: # 3 - mouth (x, y) # 4 - right ear (x, y) # 5 - left ear (x, y) - for kp in keypoints.tolist(): - img.draw_circle(int(kp[0]), int(kp[1]), 4, color=(255, 0, 0)) + ml.utils.draw_keypoints(img, keypoints, color=keypoint_color) print(clock.fps(), "fps")