mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge 55ffe44008 into c03964b8af
This commit is contained in:
commit
7d59020d1a
@ -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")
|
||||||
@ -195,3 +195,27 @@ def draw_predictions(
|
|||||||
color=box_color,
|
color=box_color,
|
||||||
)
|
)
|
||||||
image.draw_string(x, y - font_height, label.upper(), text_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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user