yolo_lc_person_detector.py

# Эта работа лицензирована по лицензии MIT.
# Copyright (c) 2013-2025 OpenMV LLC. Все права защищены.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Пример детектора людей TensorFlow Lite YOLO LC
#
# YOLO LC — это вариант YOLOV2, достаточно быстрый для работы на камерах OpenMV без NPU.

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