yolo_v2_detector.py

# هذا العمل مرخص بموجب ترخيص MIT.
# حقوق النشر (c) 2013-2025 لشركة OpenMV LLC. جميع الحقوق محفوظة.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# مثال TensorFlow Lite YOLO V2
#
# يشغّل هذا المثال نموذج اكتشاف أجسام YOLO V2.
# يرجى الاطلاع على مكتبة النماذج (model zoo) في OpenMV IDE للحصول على نماذج yolo v2 كمثال.
#
# لمزيد من المعلومات حول YOLO V2، يرجى مراجعة:
# https://github.com/STMicroelectronics/stm32ai-modelzoo/tree/main/object_detection/tiny_yolo_v2
#
# ملاحظة: يتطلب هذا المثال كاميرا OpenMV مزودة بوحدة NPU مثل AE3 أو N6 للعمل في الوقت الفعلي.

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

# تهيئة المستشعر.
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)

# تحميل نموذج YOLO V2 من ROM FS.
model = ml.Model("/rom/<model_file_name>", postprocess=YoloV2(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 عبارة عن قائمة من القوائم لكل فئة تحتوي على صفوف (tuples) بالشكل ((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 ""