Getting temperature data of a rectangle instead of a blob


I have a lepton 3.5 and a open MV Cam h7. As i found it quite difficult to read a specific coordinate temperature reading. I looked into the examples and came across the blob examples. I thought instead of having blobs found I could pass in my own rectangle to get custom readings, however, my readings are all over the place.

First of my method is:

def get_target_temp(x,y,w,h):
    img.draw_cross(int(x+(w/2)), int(y+(h/2)))
    stats = img.get_statistics(thresholds=threshold_list, roi=(x,y,w,h))
    img.draw_string(x, y - 10, "%.2f C" % map_g_to_temp(stats.mean()), mono_space=False)
    print("%.2f C" % map_g_to_temp(stats.mean()))

However, my temperature stays to always lean towards the maximum temperature I set in the code. I don’t understand the correlation between the threshold list, 0-255 and the min and max temp. I’m assuming their is a certain formula to get the threshold values based on the temperature.

But when the threshold is 0,255 and the min temp is -10 and the max is 140, and my face is within the square i get a reading of 61.76 C.

I am very confused and would appreciate any help!

One comment on your code, you should move the drawing after get_statistics.

I don’t understand, what do you mean? Do you mind elaborating a little bit. I apologize I am very knew to this API.

After research, I found that drawing before computing messes with the source image. Well noted, this gave me a way better accurate reading! Now what is the correlation between the min temperature and the min threshold and the max temperature to the max threshold?

The min and max temperatures are scaled to 0-255 because the temps are returned in an image (pixels go from 0->255)… The threshold part is to filter the pixels in that image. I’m guessing that it’s finding objects with temps between 31 and 35 degrees, but I didn’t actually write that example, so I could be wrong. Kwabena will be able to give you a better answer.

Thresholding is done to only select the pixels in the rectangle selected by the ROI which are in the range of the temperature you are trying to read. You don’t need it. However, without it then you will compute the stats on all pixels and not just the ones within the threshold.

Okay, I have my threshold between 0 and 255 and my min at 34 and max at 41. I was asking because within the example lepton_get_object_temp it has the min at 20 and max at 35 where the threshold is 200 to 255. I didn’t understand why it wasn’t 0 to 255. I though there was some correlation depending on min and max temperature values.

It’s probably like that because I pumped the examples out very quickly.

Yes, for proper temp readings it should be 0-255. With 200-255 this selects only the temperature from certain pixels in the area versus all of them.

With a min and max of 34 and 41… then the scaling method is:

t = (g*(41-34)/255)+34

So, 200 is like 39C and 255 is 41C. So, that threshold only select the stats from pixels in that temperature range.

Awesome, Thank you So much!