mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Compare commits
2 Commits
b897ec4f16
...
1cae05de5b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cae05de5b | ||
|
|
cbbf8ee7bc |
@ -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()
|
||||||
@ -17,12 +17,13 @@ csi0.framesize(csi.VGA)
|
|||||||
csi0.window((400, 400))
|
csi0.window((400, 400))
|
||||||
|
|
||||||
# Load built-in face detection model
|
# 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)
|
print(model)
|
||||||
|
|
||||||
# Create the face detection post-processor. This post-processor dynamically
|
# Visualization parameters.
|
||||||
# generates anchors for the model input size which should only be done once.
|
face_labels = ["face"]
|
||||||
face_detection_postprocess = mediapipe_face_detection_postprocess(threshold=0.6)
|
face_colors = [(0, 0, 255)]
|
||||||
|
kp_color = (255, 0, 0)
|
||||||
|
|
||||||
clock = time.clock()
|
clock = time.clock()
|
||||||
while True:
|
while True:
|
||||||
@ -30,12 +31,13 @@ while True:
|
|||||||
img = csi0.snapshot()
|
img = csi0.snapshot()
|
||||||
|
|
||||||
# faces is a list of ((x, y, w, h), score, keypoints) tuples
|
# 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.
|
# 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 +45,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=kp_color)
|
||||||
img.draw_circle(int(kp[0]), int(kp[1]), 4, color=(255, 0, 0))
|
|
||||||
|
|
||||||
print(clock.fps(), "fps")
|
print(clock.fps(), "fps")
|
||||||
@ -9,7 +9,7 @@
|
|||||||
import sensor
|
import sensor
|
||||||
import time
|
import time
|
||||||
import ml
|
import ml
|
||||||
from ml.postprocessing import fomo_postprocess
|
from ml.postprocessing.edgeimpulse import Fomo
|
||||||
import math
|
import math
|
||||||
|
|
||||||
sensor.reset() # Reset and initialize the sensor.
|
sensor.reset() # Reset and initialize the sensor.
|
||||||
@ -19,7 +19,7 @@ sensor.set_windowing((240, 240)) # Set 240x240 window.
|
|||||||
sensor.skip_frames(time=2000) # Let the camera adjust.
|
sensor.skip_frames(time=2000) # Let the camera adjust.
|
||||||
|
|
||||||
# Load built-in FOMO face detection model
|
# Load built-in FOMO face detection model
|
||||||
model = ml.Model("/rom/fomo_face_detection.tflite")
|
model = ml.Model("/rom/fomo_face_detection.tflite", postprocess=Fomo(threshold=0.4))
|
||||||
print(model)
|
print(model)
|
||||||
|
|
||||||
# Alternatively, models can be loaded from the filesystem storage.
|
# Alternatively, models can be loaded from the filesystem storage.
|
||||||
@ -39,10 +39,9 @@ colors = [ # Add more colors if you are detecting more than 7 types of classes
|
|||||||
clock = time.clock()
|
clock = time.clock()
|
||||||
while True:
|
while True:
|
||||||
clock.tick()
|
clock.tick()
|
||||||
|
|
||||||
img = sensor.snapshot()
|
img = sensor.snapshot()
|
||||||
|
|
||||||
for i, detection_list in enumerate(model.predict([img], callback=fomo_postprocess())):
|
for i, detection_list in enumerate(model.predict([img])):
|
||||||
if i == 0:
|
if i == 0:
|
||||||
continue # background class
|
continue # background class
|
||||||
if len(detection_list) == 0:
|
if len(detection_list) == 0:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user