Compare commits

...

3 Commits

Author SHA1 Message Date
Kwabena W Agyeman
7d59020d1a
Merge 55ffe44008 into c03964b8af 2025-10-11 04:46:33 +00:00
Kwabena W. Agyeman
55ffe44008 scripts/examples: Fix blazeface detector. 2025-10-10 21:41:12 -07:00
Kwabena W. Agyeman
8ca4269957 scripts/libraries: Add draw_keypoints() utils. 2025-10-10 21:41:12 -07:00
2 changed files with 35 additions and 6 deletions

View File

@ -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")

View File

@ -195,3 +195,27 @@ def draw_predictions(
color=box_color,
)
image.draw_string(x, y - font_height, label.upper(), text_color)
def draw_keypoints(
image,
keypoints,
radius=4,
color=(255, 0, 0),
thickness=1,
fill=False,
):
for kp in keypoints:
image.draw_circle(int(kp[0]), int(kp[1]), radius, color=color, thickness=thickness, fill=fill)
def draw_keypoint_lines(
image,
keypoints,
lines,
color=(0, 255, 0),
thickness=1,
):
for line in lines:
image.draw_line(int(keypoints[line[0]][0]), int(keypoints[line[0]][1]),
int(keypoints[line[1]][0]), int(keypoints[line[1]][1]), color=color, thickness=thickness)