Compare commits

...

2 Commits

Author SHA1 Message Date
Kwabena W. Agyeman
1cae05de5b scripts/examples: Fix fomo example. 2025-10-19 15:48:56 +04:00
Kwabena W. Agyeman
cbbf8ee7bc scripts/examples: Fix blazeface detector. 2025-10-19 15:48:55 +04:00
2 changed files with 14 additions and 14 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()
@ -17,12 +17,13 @@ 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)
# Visualization parameters.
face_labels = ["face"]
face_colors = [(0, 0, 255)]
kp_color = (255, 0, 0)
clock = time.clock()
while True:
@ -30,12 +31,13 @@ while True:
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_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 +45,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=kp_color)
print(clock.fps(), "fps")

View File

@ -9,7 +9,7 @@
import sensor
import time
import ml
from ml.postprocessing import fomo_postprocess
from ml.postprocessing.edgeimpulse import Fomo
import math
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.
# 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)
# 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()
while True:
clock.tick()
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:
continue # background class
if len(detection_list) == 0: