blazeface_detector.py
# Dieses Werk ist unter der MIT-Lizenz lizenziert.
# Copyright (c) 2013-2025 OpenMV LLC. Alle Rechte vorbehalten.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Dieses Beispiel demonstriert Googles MediaPipe-Gesichtserkennungsmodell.
import csi
import time
import ml
from ml.postprocessing.mediapipe import BlazeFace
# Sensor initialisieren.
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)
# BlazeFace benötigt für die besten Ergebnisse ein quadratisches Bild.
csi0.window((400, 400))
# Eingebautes Gesichtserkennungsmodell laden
model = ml.Model("/rom/blazeface_front_128.tflite", postprocess=BlazeFace(threshold=0.4))
print(model)
clock = time.clock()
while True:
clock.tick()
img = csi0.snapshot()
# faces ist eine Liste von ((x, y, w, h), score, keypoints)-Tupeln
for r, score, keypoints in model.predict([img]):
ml.utils.draw_predictions(img, [r], ("face",), ((0, 0, 255),), format=None)
# keypoints ist ein ndarray der Form (6, 2)
# 0 - rechtes Auge (x, y)
# 1 - linkes Auge (x, y)
# 2 - Nase (x, y)
# 3 - Mund (x, y)
# 4 - rechtes Ohr (x, y)
# 5 - linkes Ohr (x, y)
ml.utils.draw_keypoints(img, keypoints, color=(255, 0, 0))
print(clock.fps(), "fps")