tf_object_detection.py

# هذا العمل مرخص بموجب ترخيص MIT.
# حقوق النشر (c) 2013-2024 OpenMV LLC. جميع الحقوق محفوظة.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# مثال اكتشاف الأجسام باستخدام TensorFlow Lite
#
# يستخدم هذا المثال نموذج FOMO المدمج لاكتشاف الوجوه.

import csi
import time
import ml
from ml.postprocessing.edgeimpulse import Fomo
import math
csi0 = csi.CSI()
csi0.reset()  # إعادة ضبط المستشعر وتهيئته.
csi0.pixformat(csi.RGB565)  # تعيين تنسيق البكسل إلى RGB565 (أو GRAYSCALE)
csi0.framesize(csi.QVGA)  # تعيين حجم الإطار إلى QVGA (320x240)
csi0.window((240, 240))  # تعيين نافذة بحجم 240x240.
csi0.snapshot(time=2000)  # دع الكاميرا تتكيف.

# تحميل نموذج اكتشاف الوجوه المدمج FOMO
model = ml.Model("/rom/fomo_face_detection.tflite", postprocess=Fomo(threshold=0.4))
print(model)

# بدلاً من ذلك، يمكن تحميل النماذج من تخزين نظام الملفات.
# model = ml.Model('<object_detection_modelwork>.tflite', load_to_fb=True)
# labels = [line.rstrip('\n') for line in open("labels.txt")]

colors = [  # أضف المزيد من الألوان إذا كنت تكتشف أكثر من 7 أنواع من الأصناف في نفس الوقت.
    (255, 0, 0),
    (0, 255, 0),
    (255, 255, 0),
    (0, 0, 255),
    (255, 0, 255),
    (0, 255, 255),
    (255, 255, 255),
]

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

    for i, detection_list in enumerate(model.predict([img])):
        if i == 0:
            continue  # صنف الخلفية
        if len(detection_list) == 0:
            continue  # لا توجد اكتشافات لهذا الصنف؟

        print("********** %s **********" % model.labels[i])
        for (x, y, w, h), score in detection_list:
            center_x = math.floor(x + (w / 2))
            center_y = math.floor(y + (h / 2))
            print(f"x {center_x}\ty {center_y}\tscore {score}")
            img.draw_circle((center_x, center_y, 12), color=colors[i])

    print(clock.fps(), "fps", end="\n")

results matching ""

    No results matching ""