mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
scripts/examples: Fix blazeface detector.
This commit is contained in:
parent
7cbdb927da
commit
74faef3a8e
@ -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()
|
||||
@ -17,25 +17,22 @@ csi0.framesize(csi.VGA)
|
||||
csi0.window((400, 400))
|
||||
|
||||
# Load built-in face detection model
|
||||
model = ml.Model("/rom/blazeface_front_128.tflite")
|
||||
model = ml.Model("/rom/blazeface_front_128.tflite", postprocess=BlazeFace(threshold=0.4))
|
||||
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)
|
||||
|
||||
clock = time.clock()
|
||||
while True:
|
||||
clock.tick()
|
||||
img = csi0.snapshot()
|
||||
|
||||
# faces is a list of ((x, y, w, h), score, keypoints) tuples
|
||||
faces = model.predict([img], callback=face_detection_postprocess)
|
||||
faces = model.predict([img])
|
||||
|
||||
# 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",), ((0, 0, 255),), format=None)
|
||||
|
||||
# keypoints is a ndarray of shape (6, 2)
|
||||
# 0 - right eye (x, y)
|
||||
# 1 - left eye (x, y)
|
||||
@ -43,7 +40,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=(255, 0, 0))
|
||||
|
||||
print(clock.fps(), "fps")
|
||||
Loading…
Reference in New Issue
Block a user