Mapping pixel value to temperature value on a thermal image

女生的网名这么多〃 提交于 2020-08-08 06:36:29

问题


I have a thermal image (with a color bar) from an IR camera. My goal is to get the temperature of any point by clicking on it.

I have already written a script that retrieves the RBG values of any pixel by right-clicking on it.

I figure that using the max and min temperatures of the color bar, I can map pixel values to temperature values.

Is this possible or is there a better way to approach this?

Thank you very much.

from PIL import Image
import cv2
from win32api import GetSystemMetrics

counter = 0
max_value = input('Max Temp Value: ')
min_value = input('Min Temp Value: ')

def mouse_callback(event, x, y, flags, params): # Tracks the pixel the mouse it hovering on. When right click it prints the pixel location and its RBG values.                                     
    global counter
    if event == 2:
        counter += 1
        r, g, b = rgb_img.getpixel((x, y))
        print(f'{counter}: {[x, y]} value {r} {g} {b}')
    else:
        print([x, y], end='\t\r', flush=True)

path_image = 'colors.jpg'
img = cv2.imread(path_image)
im = Image.open(path_image)
rgb_img = im.convert('RGB')

width = GetSystemMetrics(0)
height = GetSystemMetrics(1)

scale_width = width / im.size[0]
scale_height = height / im.size[1]
scale = min(scale_width, scale_height)
window_width = int((im.size[0] * scale) * 0.5)
window_height = int((im.size[1] * scale) * 0.5)

cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.resizeWindow('image', window_width, window_height)

cv2.setMouseCallback('image', mouse_callback)

cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

来源:https://stackoverflow.com/questions/62107454/mapping-pixel-value-to-temperature-value-on-a-thermal-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!