yolo_v5_detector.py

# この作品はMITライセンスの下で提供されています。
# Copyright (c) 2013-2025 OpenMV LLC. 全著作権所有。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# TensorFlow Lite YOLO V5の例
#
# この例は、YOLO V5物体検出モデルを実行します。
# YOLO V5モデルの例については、OpenMV IDEのモデルズーを参照してください。
#
# Edge Impulseを使用して、独自のカスタムYOLOV5モデルを学習させることができます:
# https://github.com/edgeimpulse/ml-block-yolov5
#
# 注記:この例をリアルタイムで実行するには、AE3やN6のようなNPU搭載のOpenMV Camが必要です。

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

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

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