flir_rs/lib.rs
1//! Library to process flir_rs images from FLIR cameras.
2//!
3//! This crate provides two functionalities:
4//!
5//! 1. Compute [temperature] from raw sensor values and
6//! ambient parameters (typically stored as metadata in the
7//! image). The code is a port of the [Thermimage R
8//! library] and its [python port][read_thermal.py].
9//!
10//! 2. [Parse parameters](image::ThermalImage) and raw
11//! sensor values from image metadata. Supports [parsing
12//! R-JPEGs][parsing-rjpeg] with FFF encoding of Flir
13//! parameters, and [parsing ExifTool][parsing-exiftool]
14//! generated JSON (output from `exiftool -b -j`).
15//!
16//! # Usage
17//!
18//! Obtaining pixel-wise temperature values involves (1)
19//! extracting the raw sensor values, and the conversion
20//! parameters from image metadata; and (2) converting the
21//! raw values to temperature values.
22//!
23//! ## Extracting values and parameters
24//!
25//! The crate can directly parse radiometric R-JPEGs from
26//! Flir cameras. This is an (incomplete) port of the
27//! relevant parts of the excellent [ExifTool] by Phil
28//! Harvey and currently supports R-JPEGs with FFF encoded
29//! data. Refer
30//! [`try_from_rjpeg_path`][ThermalImage::try_from_rjpeg_path]
31//! for more info.
32//!
33//! ```rust
34//! # fn test_compile() -> anyhow::Result<()> {
35//! use flir_rs::ThermalImage;
36//! let image = ThermalImage::try_from_rjpeg_path("image.jpg")?;
37//! # Ok(())
38//! # }
39//! ```
40//!
41//! The crate can also parse the JSON output from ExifTool
42//! via `exiftool -b -j` via [`ThermalExiftoolJson`] and
43//! [`serde_json`]. This can then be converted to a
44//! `ThermalImage`.
45//!
46//! ```rust
47//! # fn test_compile() -> anyhow::Result<()> {
48//! use std::{convert::TryInto, fs::File, io::BufReader};
49//! use flir_rs::{ThermalExiftoolJson, ThermalImage};
50//!
51//! let json: ThermalExiftoolJson = serde_json::from_reader(
52//! BufReader::new(File::open("metadata.json")?)
53//! )?;
54//! let image: ThermalImage = json.try_into()?;
55//! # Ok(())
56//! # }
57//! ```
58//!
59//! ## Converting sensor values to temperatures
60//!
61//! The raw sensor values in [`ThermalImage::image`] can be
62//! converted to temperature in celicius using
63//! [`raw_to_temp`][crate::temperature::ThermalSettings::raw_to_temp]
64//! method on [`ThermalImage::settings`]. This is a port of
65//! the [Thermimage R library] and its [python
66//! port][read_thermal.py].
67//!
68//! [read_thermal.py]: //github.com/Nervengift/read_thermal.py/blob/master/flir_image_extractor.py
69//! [Thermimage R library]: //github.com/gtatters/Thermimage/blob/master/R/raw2temp.R
70//! [ExifTool]: //exiftool.org
71//! [parsing-rjpeg]: crate::image::ThermalImage::try_from_rjpeg
72//! [parsing-exiftool]: crate::image::ThermalExiftoolJson
73
74#[macro_use]
75pub mod parse;
76pub mod flir;
77
78pub mod image;
79pub mod temperature;
80
81pub mod stats;
82
83pub use crate::image::ThermalExiftoolJson;
84pub use crate::image::ThermalImage;
85pub mod cli;