import sensor, image, time, math from pyb import Pin threshold_list = [(190, 255)] min_temp_in_celsius = 20.0 max_temp_in_celsius = 40.0 pin1 = Pin('P4', Pin.OUT_PP, Pin.PULL_NONE) sensor.reset() sensor.ioctl(sensor.IOCTL_LEPTON_SET_MODE, True, True) sensor.ioctl(sensor.IOCTL_LEPTON_SET_RANGE, min_temp_in_celsius, max_temp_in_celsius) sensor.ioctl(sensor.IOCTL_LEPTON_GET_WIDTH) sensor.ioctl(sensor.IOCTL_LEPTON_GET_HEIGHT) sensor.ioctl(sensor.IOCTL_LEPTON_GET_RADIOMETRY) sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time=5000) clock = time.clock() def map_g_to_temp(g): return ((g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0) + min_temp_in_celsius while(True): clock.tick() img = sensor.snapshot() blob_stats = [] blobs = img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True) # Collect stats into a list of tuples for blob in blobs: blob_stats.append((blob.x(), blob.y(), map_g_to_temp(img.get_statistics(thresholds=threshold_list, roi=blob.rect()).mean()))) img.to_rainbow(color_palette=image.PALETTE_IRONBOW) # color it for blob in blobs: img.draw_rectangle(blob.rect(), color=(0,255,0)) img.draw_cross(blob.cx(), blob.cy(), color=(0,255,0)) for blob_stat in blob_stats: if blob_stat[2] > 38.0: pin1.value(1) img.draw_string(blob_stat[0] + 2, blob_stat[1] + 1, "%.2f C" % blob_stat[2], mono_space=False, color=(0,255,0)) if not blob_stats: pin1.value(0)