yolo_v8_detector.py

# この作品はMITライセンスの下で提供されています。
# Copyright (c) 2013-2025 OpenMV LLC. 全著作権所有。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# TensorFlow Lite YOLO V8の例
#
# この例は、YOLO V8人物検出モデルを実行します。
#
# 注記:この例をリアルタイムで実行するには、AE3やN6のようなNPU搭載のOpenMV Camが必要です。

import csi
import time
import ml
from ml.postprocessing.ultralytics import YoloV8

# センサーを初期化します。
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)

# ROM FSからYOLO V8モデルをロードします。
model = ml.Model("/rom/yolov8n_192.tflite", postprocess=YoloV8(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 ""