scripts/examples: Fix blazeface detector.

This commit is contained in:
Kwabena W. Agyeman 2025-10-10 21:40:41 -07:00
parent 8ca4269957
commit 55ffe44008

View File

@ -2,12 +2,12 @@
# Copyright (c) 2013-2025 OpenMV LLC. All rights reserved. # Copyright (c) 2013-2025 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE # 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 csi
import time import time
import ml import ml
from ml.postprocessing import mediapipe_face_detection_postprocess from ml.postprocessing.mediapipe import BlazeFace
# Initialize the sensor. # Initialize the sensor.
csi0 = csi.CSI() csi0 = csi.CSI()
@ -22,7 +22,12 @@ print(model)
# Create the face detection post-processor. This post-processor dynamically # Create the face detection post-processor. This post-processor dynamically
# generates anchors for the model input size which should only be done once. # 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() clock = time.clock()
while True: while True:
@ -35,7 +40,8 @@ while True:
# Draw bounding boxes around the detected faces and keypoints. # Draw bounding boxes around the detected faces and keypoints.
if faces: if faces:
for r, score, keypoints in faces[0]: 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) # keypoints is a ndarray of shape (6, 2)
# 0 - right eye (x, y) # 0 - right eye (x, y)
# 1 - left eye (x, y) # 1 - left eye (x, y)
@ -43,7 +49,6 @@ while True:
# 3 - mouth (x, y) # 3 - mouth (x, y)
# 4 - right ear (x, y) # 4 - right ear (x, y)
# 5 - left ear (x, y) # 5 - left ear (x, y)
for kp in keypoints.tolist(): ml.utils.draw_keypoints(img, keypoints, color=keypoint_color)
img.draw_circle(int(kp[0]), int(kp[1]), 4, color=(255, 0, 0))
print(clock.fps(), "fps") print(clock.fps(), "fps")