yolo_lc_person_detector.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2025 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# TensorFlow Lite YOLO LC行人检测器示例
#
# YOLO LC是YOLOV2的一个变体,速度足以在没有NPU的OpenMV摄像头上运行。

import csi
import time
import ml
from ml.postprocessing.darknet import YoloLC

# 初始化传感器。
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)

# 加载内置的行人检测模型
model = ml.Model("/rom/yolo_lc_192.tflite", postprocess=YoloLC(threshold=0.4))
print(model)

# 可视化参数。
n = len(model.labels)
model_class_colors = [(int(255 * i // n), int(255 * (n - i - 1) // n), 255) for i in range(n)]

clock = time.clock()
while True:
    clock.tick()
    img = csi0.snapshot()

    # boxes是按类别组织的列表,每个类别为((x, y, w, h), score)元组的列表
    boxes = model.predict([img])

    # 在检测到的目标周围绘制边界框
    for i, class_detections in enumerate(boxes):
        rects = [r for r, score in class_detections]
        labels = [model.labels[i] for j in range(len(rects))]
        colors = [model_class_colors[i] for j in range(len(rects))]
        ml.utils.draw_predictions(img, rects, labels, colors, format=None)

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

results matching ""

    No results matching ""