Lepton 获取物体温度示例
import csi
import time
import image
threshold_list = [(200, 255)]
min_temp_in_celsius = 20.0
max_temp_in_celsius = 40.0
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.framesize(csi.QQVGA)
csi0.ioctl(csi.IOCTL_LEPTON_SET_MODE, True)
csi0.ioctl(csi.IOCTL_LEPTON_SET_RANGE, min_temp_in_celsius, max_temp_in_celsius)
csi0.snapshot(time=5000)
clock = time.clock()
print("Radiometry: " + "Yes" if csi0.ioctl(csi.IOCTL_LEPTON_GET_RADIOMETRY) else "No")
print("Resolution: %dx%d" % (csi0.ioctl(csi.IOCTL_LEPTON_GET_WIDTH), csi0.ioctl(csi.IOCTL_LEPTON_GET_HEIGHT)))
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 = csi0.snapshot()
blob_stats = []
blobs = img.find_blobs(
threshold_list, pixels_threshold=200, area_threshold=200, merge=True
)
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)
for blob in blobs:
img.draw_detection(blob)
for blob_stat in blob_stats:
img.draw_string(
(blob_stat[0], blob_stat[1] - 10), "%.2f C" % blob_stat[2], mono_space=False
)
print(
"FPS %f - Lepton Temp: %f C"
% (clock.fps(), csi0.ioctl(csi.IOCTL_LEPTON_GET_FPA_TEMP))
)