pure_thermal.py

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

import csi
import image
import time
import display
import math
import tfp410


# عتبات تتبع اللون (الحد الأدنى لتدرج الرمادي، الحد الأقصى لتدرج الرمادي)
threshold_list = [(200, 255)]

# قم بتعيين نطاق درجة الحرارة المستهدف هنا
min_temp_in_celsius = 20.0
max_temp_in_celsius = 40.0

csi0 = csi.CSI(cid=csi.OV5640)
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.WVGA)
time.sleep_ms(50)

csi1 = csi.CSI(cid=csi.LEPTON)
csi1.reset(hard=False)
csi1.pixformat(csi.GRAYSCALE)
csi1.framesize(csi.QQVGA)

# يفعّل قياسات درجة الحرارة الدقيقة من مستشعر flir lepton.
# يقوم المعامل الثاني بتفعيل وضع الكسب العالي (high gain) لقراءة درجات الحرارة المرتفعة.
csi1.ioctl(csi.IOCTL_LEPTON_SET_MODE, True, False)
csi1.ioctl(
    csi.IOCTL_LEPTON_SET_RANGE, min_temp_in_celsius, max_temp_in_celsius
)

print(
    "Lepton Res (%dx%d)"
    % (
        csi1.ioctl(csi.IOCTL_LEPTON_GET_WIDTH),
        csi1.ioctl(csi.IOCTL_LEPTON_GET_HEIGHT),
    )
)

print(
    "Radiometry Available: "
    + ("Yes" if csi1.ioctl(csi.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
)

fir_img = image.Image(csi1.width(), csi1.height(), image.GRAYSCALE)
time.sleep_ms(50)

lcd = display.RGBDisplay(framesize=display.FWVGA, refresh=60)
lcd.backlight(True)
hdmi = tfp410.TFP410()
time.sleep_ms(50)

alpha_pal = image.Image(256, 1, image.GRAYSCALE)
for i in range(256):
    alpha_pal[i] = int(math.pow((i / 255), 2) * 255)

to_min = None
to_max = None


def map_g_to_temp(g):
    return (
        (g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0
    ) + min_temp_in_celsius


# بدء تشغيل التقاط الكاميرا الحرارية.
csi1.snapshot(blocking=True, image=fir_img)

while True:
    img = csi0.snapshot()

    # التقاط الصورة الحرارية دون إعاقة (blocking).
    csi1.snapshot(blocking=False, image=fir_img)

    fir_img_size = fir_img.width() * fir_img.height()

    # العثور على كتل الأشعة تحت الحمراء (IR Blobs)
    blobs = fir_img.find_blobs(threshold_list,
                               pixels_threshold=(fir_img_size // 100),
                               area_threshold=(fir_img_size // 100),
                               merge=True)

    # جمع الإحصائيات في قائمة من tuples
    blob_stats = []
    for b in blobs:
        blob_stats.append(
            (b.rect, map_g_to_temp(fir_img.get_statistics(
                thresholds=threshold_list, roi=b.rect
            ).mean))
        )

    x_scale = img.width() / fir_img.width()
    y_scale = img.height() / fir_img.height()
    img.draw_image(fir_img, 0, 0, x_scale=x_scale, y_scale=y_scale,
                   color_palette=image.PALETTE_IRONBOW,
                   alpha_palette=alpha_pal,
                   hint=image.BICUBIC)

    # ارسم عناصر على الصورة الملونة
    for b in blobs:
        img.draw_rectangle((int(b.rect[0] * x_scale),
                            int(b.rect[1] * y_scale),
                            int(b.rect[2] * x_scale),
                            int(b.rect[3] * y_scale)))
        img.draw_cross((int(b.cx * x_scale), int(b.cy * y_scale)))

    for blob_stat in blob_stats:
        img.draw_string((int((blob_stat[0][0] * x_scale) + 4),
                         int((blob_stat[0][1] * y_scale) + 1)),
                        '%.2f C' % blob_stat[1], mono_space=False, scale=2)

    lcd.write(img, hint=(
        image.BILINEAR | image.CENTER | image.SCALE_ASPECT_KEEP
    ))

results matching ""

    No results matching ""