You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Lepton 3.5辐射热像仪提取温度最值及均值

从Lepton 3.5辐射热像仪提取掩膜区域温度并计算统计值

已成功读取掩膜矩形区域的像素值数组,现有实现代码如下:

heatmap_gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
heatmap = cv2.applyColorMap(heatmap_gray, cv2.COLORMAP_HOT)

# Binary threshold
_, binary_thresh = cv2.threshold(heatmap_gray, threshold, 255, cv2.THRESH_BINARY)

# Image opening: Erosion followed by dilation
kernel = np.ones((3, 3), np.uint8)
image_erosion = cv2.erode(binary_thresh, kernel, iterations=1)
image_opening = cv2.dilate(image_erosion, kernel, iterations=1)

# Get contours from the image obtained by opening operation
contours, _ = cv2.findContours(image_opening, 1, 2) 

image_with_rectangles = np.copy(frame)

for contour in contours:
    # rectangle over each contour
    x, y, w, h = cv2.boundingRect(contour)

    # Pass if the area of rectangle is not large enough
    if (w) * (h) < area_of_box:
        continue

    # Mask is boolean type of matrix.
    mask = np.zeros_like(heatmap_gray)
    cv2.drawContours(mask, contour, -1, 255, -1)
    max = convert_to_temperature(np.amax(heatmap_gray+mask))
    print(heatmap_gray+mask)

当前已获取到掩膜区域的像素值数组,需要提取该区域的温度值并计算最大值、最小值和均值。


解决方案

  1. 正确提取掩膜区域像素:原代码中heatmap_gray + mask的方式错误,应通过布尔索引筛选掩膜覆盖的有效像素:
    # 提取掩膜区域内的像素值
    masked_pixels = heatmap_gray[mask == 255]
    
  2. 批量转换为温度值:将筛选出的像素值批量转换为温度(确保convert_to_temperature支持数组输入,若不支持可结合np.vectorize包装):
    # 转换为温度数组
    temperature_values = convert_to_temperature(masked_pixels)
    
  3. 计算统计值:直接对温度数组计算最大值、最小值和均值:
    # 计算统计值
    temp_max = np.max(temperature_values)
    temp_min = np.min(temperature_values)
    temp_mean = np.mean(temperature_values)
    

修改后的完整循环代码

替换原循环内的逻辑为:

for contour in contours:
    x, y, w, h = cv2.boundingRect(contour)
    if (w) * (h) < area_of_box:
        continue

    mask = np.zeros_like(heatmap_gray)
    cv2.drawContours(mask, contour, -1, 255, -1)
    
    # 提取有效像素并转换为温度
    masked_pixels = heatmap_gray[mask == 255]
    temperature_values = convert_to_temperature(masked_pixels)
    
    # 计算并输出统计值
    temp_max = np.max(temperature_values)
    temp_min = np.min(temperature_values)
    temp_mean = np.mean(temperature_values)
    
    print(f"区域温度最大值: {temp_max}, 最小值: {temp_min}, 均值: {temp_mean}")

注意事项

  • 确保convert_to_temperature函数正确匹配Lepton 3.5的像素-温度转换规则:若你将原始16位热图转为了8位灰度图,需确认转换时的缩放系数,避免温度计算偏差。
  • 若convert_to_temperature仅支持单个值输入,可使用np.vectorize(convert_to_temperature)包装后处理数组。

内容的提问来源于stack exchange,提问作者RChristan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 04:06:26