Code Monkey home page Code Monkey logo

read_thermal.py's Introduction

Flir Image Extractor

FLIR® thermal cameras like the FLIR ONE® include both a thermal and a visual light camera. The latter is used to enhance the thermal image using an edge detector.

The resulting image is saved as a jpg image but both the original visual image and the raw thermal sensor data are embedded in the jpg metadata.

This small Python tool/library allows to extract the original photo and thermal sensor values converted to temperatures.

Requirements

This tool relies on exiftool. It should be available in most Linux distributions (e.g. as perl-image-exiftool in Arch Linux or libimage-exiftool-perl in Debian and Ubuntu).

It also needs the Python packages numpy and matplotlib (the latter only if used interactively).

# sudo apt update
# sudo apt install exiftool
# sudo pip install numpy matplotlib

Usage

This module can be used by importing it:

import flir_image_extractor
fir = flir_image_extractor.FlirImageExtractor()
fir.process_image('examples/ax8.jpg')
fir.plot()

Or by calling it as a script:

python flir_image_extractor.py -p -i 'examples/zenmuse_xtr.jpg'
usage: flir_image_extractor.py [-h] -i INPUT [-p] [-exif EXIFTOOL]
                               [-csv EXTRACTCSV] [-d]

Extract and visualize Flir Image data

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        Input image. Ex. img.jpg
  -p, --plot            Generate a plot using matplotlib
  -exif EXIFTOOL, --exiftool EXIFTOOL
                        Custom path to exiftool
  -csv EXTRACTCSV, --extractcsv EXTRACTCSV
                        Export the thermal data per pixel encoded as csv file
  -d, --debug           Set the debug flag

This command will show an interactive plot of the thermal image using matplotlib and create two image files flir_example_thermal.png and flir_example_rgb_image.jpg. Both are RGB images, the original temperature array is available using the get_thermal_np or export_thermal_to_csv functions.

The functions get_rgb_np and get_thermal_np yield numpy arrays and can be called from your own script after importing this lib.

Supported/Tested cameras:

  • Flir One (thermal + RGB)
  • Xenmuse XTR (thermal + thumbnail, set the subject distance to 1 meter)
  • AX8 (thermal + RGB)

Other cameras might need some small tweaks (the embedded raw data can be in multiple image formats)

Credits

Raw value to temperature conversion is ported from this R package: https://github.com/gtatters/Thermimage/blob/master/R/raw2temp.R Original Python code from: https://github.com/Nervengift/read_thermal.py

read_thermal.py's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

read_thermal.py's Issues

No-Visual Output

Hello!

I am struggling to use the software for some reason. I have exiftool installed and many of the dependencies. However, when I execute the program, I do not see a visual image output alongside the thermal image. It is just thermal image alone. I am not sure what I am doing wrong, it seems fairly straight-forward. If you have any tips for this let me know pls!

I am using ubuntu 20.04 and python3

Thank you!

I can't extract the Thermal Image from JPG

Hello, I made this and got this error:

import flir_image_extractor
>>> fir = flir_image_extractor.FlirImageExtractor()
>>> fir.process_image('FLIR0421.jpg')
Warning: [minor] Possibly incorrect maker notes offsets (fix by -42?) - FLIR0421.jpg
Warning: [minor] Possibly incorrect maker notes offsets (fix by -42?) - FLIR0421.jpg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "flir_image_extractor.py", line 66, in process_image
    self.thermal_image_np = self.extract_thermal_image()
  File "flir_image_extractor.py", line 136, in extract_thermal_image
    thermal_img = Image.open(thermal_img_stream)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 3008, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7fd124880d10>

and I cannot plot or export to CSV any data, look:

fir.export_thermal_to_csv('file.csv')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "flir_image_extractor.py", line 270, in export_thermal_to_csv
    x, y = e[0]
ValueError: not enough values to unpack (expected 2, got 0)

and plot...

>>> fir.plot()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wagner/Downloads/flir_image_extractor.py", line 228, in plot
    plt.imshow(thermal_np, cmap='hot')
  File "/home/wagner/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 2695, in imshow
    __ret = gca().imshow(
  File "/home/wagner/.local/lib/python3.10/site-packages/matplotlib/__init__.py", line 1442, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/home/wagner/.local/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 5665, in imshow
    im.set_data(X)
  File "/home/wagner/.local/lib/python3.10/site-packages/matplotlib/image.py", line 701, in set_data
    raise TypeError("Image data of dtype {} cannot be converted to "
TypeError: Image data of dtype object cannot be converted to float

here one of my files...
FLIR0421

Math domain error

Hi,

I'm using this code to process some images from the FLIR i7 camera. I know that theoretically the library doesn't support that camera, but after some handwork with exiftool and images from the camera, I realized that I could use it for extract the thermal_np_array which is enough for me.

Even though I made it work properly for a lot of images, I'm getting a 'math domain error' in the raw2temp module in some cases. Do you know why is this happening? All metadata that raw2temp needs are available so I guess that this shouldn't be happening.

Here you have some examples of the 'troublemakers' :)
Thanks in advance. @Nervengift
IR_2920
IR_2828

Hello! I encountered an error when running the project. What can I do? Tks pro

Traceback (most recent call last):
File "read-thermal.py", line 101, in
thermal_np = extract_thermal(imgpath)
File "read-thermal.py", line 68, in extract_thermal
meta = json.loads(meta_json)[0]
File "/usr/lib/python2.7/json/init.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

array size

whenever I run the cod on one of my flir one thermal images it produces an array of size 640,480, however when I test the example image it produces 320, 230 image

Is there any coordinate relationship between thermal and visible image?

Hi!Thanks for your work. I used your method to produce visible image as follows.The second image is thermal image.I have noticed the first image shape is different whith others and I can't figure out is any coordinate relationship between the first image and the third image.
Looking for your reply.
image

Extracting exif header information

Thanks for this tool. I would have hoped that it also has an option to extract the exif header information of thermal FLIR images. I have tried other option (e.g. pillow) but the FLIR header seems always different from what I get by using the exiftools command line options. I haven´t managed to run exiftools from Python. Hope you can help?

Cheers,
Rene

Working with multiple images and ironbow filter

I am running into an issue with this script when I try to run it on all images within a folder. I initially checked to see that the flir encoded data was in the metadata with exiftool. It is present. When running the code, though, on ironbow filter images I get the following error:
Traceback (most recent call last):
File ".\u_value_module.py", line 438, in
export_temperatures()
File ".\u_value_module.py", line 434, in export_temperatures
flir.process_image(images)
File "C:\Users\sai.peri\Documents\u_value_module\flir_image_extractor.py", line 62, in process_image
self.rgb_image_np = self.extract_embedded_image()
File "C:\Users\sai.peri\Documents\u_value_module\flir_image_extractor.py", line 102, in extract_embedded_image
visual_img = Image.open(visual_img_stream)
File "C:\Users\sai.peri\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PIL\Image.py", line 2822, in open
raise IOError("cannot identify image file %r" % (filename if filename else fp))
OSError: cannot identify image file <_io.BytesIO object at 0x038543C0>

Not sure how to fix it. It occurs at the visual_img = Image.open line.

extract temperature info from flir video

Hi!
Thank you for your works which I could extract thermal info numpy from flir image with 👍

Actually I need to analyze flir video. How can I extract meta data from flir video (.MP4) as you extract meta data from jpg image?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.