I am using an existing script from github to calculate pixel temperatures from the flir camera. The original project can be found here https://github.com/Nervengift/read_thermal.py/blob/master/flir_image_extractor.py I am trying to automate the script to run for all images within a given folder. The script works for most files but I run into an issue from time to time which makes the script break. The official error I am getting is as such:
Traceback (most recent call last):
File ".\flir_image_extractor.py", line 288, in <module>
fie.process_image(args.input)
File ".\flir_image_extractor.py", line 63, in process_image
self.thermal_image_np = self.extract_thermal_image()
File ".\flir_image_extractor.py", line 150, in extract_thermal_image
thermal_np = raw2tempfunc(thermal_np)
File "C:\Users\sai.peri\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\lib\function_base.py", line 2091, in __call__
return self._vectorize_call(func=func, args=vargs)
File "C:\Users\sai.peri\AppData\Local\Programs\Python\Python37-32\lib\site-packages\numpy\lib\function_base.py", line 2167, in _vectorize_call
outputs = ufunc(*inputs)
File ".\flir_image_extractor.py", line 149, in <lambda>
PO=meta['PlanckO'], PR2=meta['PlanckR2']))
File ".\flir_image_extractor.py", line 196, in raw2temp
print("PB: {} LOG: {}".format(PB, log(PR1 / (PR2 * (raw_obj + PO)) + PF) - 273.15))
ValueError: math domain error
Following the trace I added variables to print out PB and the log function since these are what are used to calculate the temperature (The line to calculate temperature is as such temp_celcius = PB / log(PR1 / (PR2 * (raw_obj + PO)) + PF) - 273.15
I am working with averages so I can choose to ignore some pixels (although this will have effects on my results, though could be minor). I have printed out values of PB and LOG until the exception hits:
PB: 1428 LOG: -263.82261856683573
PB: 1428 LOG: -260.9464780172497
PB: 1428 LOG: -262.7915360578767
PB: 1428 LOG: -262.7915360578767
PB: 1428 LOG: -263.09963560725936
PB: 1428 LOG: -262.7915360578767
PB: 1428 LOG: -262.90511447579644
PB: 1428 LOG: -261.8717079609195
I am assuming the last entry is the last successful calculation and that on the next one it fails. What exactly is happening and how can I try to fix this to retain the actual legit value? I have tried reaching out to the owner of the project but with no luck. I would like to thank you in advance for your help.
EDIT: I have printed out the values of the variables that go into the log function. With these values I went to wolfram alpha and came up with the value of -273.39416898307 so the calculation then becomes 1428/-273.39416898307 = -5.223227 as the actual temperature value. I am not sure why I am getting this error because all of the prevous LOG functions have been negative with the -273 subtraction. The values used to cause the error and that I checked with wolfram are as such: PB: 1428 PR1: 17096.453 PR2: 0.062614508 raw_obj + PO: -1260325.936342655 PF: 1
with the equation:temp_celcius = PB / log(PR1 / (PR2 * (raw_obj + PO)) + PF) - 273.15