blazeface_detector.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2025 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 此示例展示了Google的MediaPipe人脸检测模型。

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 ""