blazeface_detector.py

# Эта работа лицензирована по лицензии MIT.
# Copyright (c) 2013-2025 OpenMV LLC. Все права защищены.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Этот пример демонстрирует модель Google MediaPipe для обнаружения лиц (Face Detection).

import csi
import time
import ml
from ml.postprocessing.mediapipe import BlazeFace

# Инициализация датчика.
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)

# Для наилучшего результата BlazeFace требует квадратное изображение.
csi0.window((400, 400))

# Загрузить встроенную модель обнаружения лица
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 — это список кортежей ((x, y, w, h), score, keypoints)
    for r, score, keypoints in model.predict([img]):
        ml.utils.draw_predictions(img, [r], ("face",), ((0, 0, 255),), format=None)

        # keypoints — это ndarray формы (6, 2)
        # 0 — правый глаз (x, y)
        # 1 — левый глаз (x, y)
        # 2 — нос (x, y)
        # 3 — рот (x, y)
        # 4 — правое ухо (x, y)
        # 5 — левое ухо (x, y)
        ml.utils.draw_keypoints(img, keypoints, color=(255, 0, 0))

    print(clock.fps(), "fps")

results matching ""

    No results matching ""