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 は形状 (6, 2) の ndarrayです
        # 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 ""