automatic_rgb565_color_tracking.py

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

import csi
import time

print("Letting auto algorithms run. Don't put anything in front of the camera!")

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)
csi0.snapshot(time=2000)
csi0.auto_gain(False)  # يجب إيقافه من أجل تتبع الألوان
csi0.auto_whitebal(False)  # يجب إيقافه من أجل تتبع الألوان
clock = time.clock()

# التقاط عتبات اللون لأي شيء كان في مركز الصورة.
r = [(320 // 2) - (50 // 2), (240 // 2) - (50 // 2), 50, 50]  # مركز 50x50 من دقة QVGA.

print(
    "Auto algorithms done. Hold the object you want to track in front of the camera in the box."
)
print(
    "MAKE SURE THE COLOR OF THE OBJECT YOU WANT TO TRACK IS FULLY ENCLOSED BY THE BOX!"
)
for i in range(60):
    img = csi0.snapshot()
    img.draw_rectangle(r)

print("Learning thresholds...")
threshold = [50, 50, 0, 0, 0, 0]  # قيم L وA وB الوسطى.
for i in range(60):
    img = csi0.snapshot()
    hist = img.get_histogram(roi=r)
    lo = hist.get_percentile(
        0.01
    )  # الحصول على الدالة التراكمية (CDF) للمدرج التكراري عند نطاق 1% (اضبطها حسب الحاجة)!
    hi = hist.get_percentile(
        0.99
    )  # الحصول على الدالة التراكمية (CDF) للمدرج التكراري عند نطاق 99% (اضبطها حسب الحاجة)!
    # المتوسط في قيم المئينات.
    threshold[0] = (threshold[0] + lo.l_value) // 2
    threshold[1] = (threshold[1] + hi.l_value) // 2
    threshold[2] = (threshold[2] + lo.a_value) // 2
    threshold[3] = (threshold[3] + hi.a_value) // 2
    threshold[4] = (threshold[4] + lo.b_value) // 2
    threshold[5] = (threshold[5] + hi.b_value) // 2
    for blob in img.find_blobs(
        [threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10
    ):
        img.draw_detection(blob)
        img.draw_rectangle(r)

print("Thresholds learned...")
print("Tracking colors...")

while True:
    clock.tick()
    img = csi0.snapshot()
    for blob in img.find_blobs(
        [threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10
    ):
        img.draw_detection(blob)
    print(clock.fps())

results matching ""

    No results matching ""