add command line options and temperature calibration
without temperature calibration 0.3% with ~5% model name : Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
This commit is contained in:
@@ -1,9 +1,31 @@
|
||||
use clap::Parser;
|
||||
use dotenv::dotenv;
|
||||
use std::io::Write;
|
||||
use thermaldecoder::{Header, HDR_SIZE};
|
||||
use v4l::video::Output;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
temperature: bool,
|
||||
#[arg(short, long, default_value = "/dev/video0")]
|
||||
device: String,
|
||||
}
|
||||
|
||||
fn pixel_to_celcius(x: u16) -> u16 {
|
||||
let x: f64 = x.into();
|
||||
let x = x / 256.0;
|
||||
let t = (-1.665884e-08) * x.powf(4.)
|
||||
+ (1.347094e-05) * x.powf(3.)
|
||||
+ (-4.396264e-03) * x.powf(2.)
|
||||
+ (9.506939e-01) * x
|
||||
+ (-6.353247e+01);
|
||||
(t * 256.0) as u16
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let args = Args::parse();
|
||||
dotenv().ok();
|
||||
let device = match std::env::var("THERMALCAM_IFACE=enp1s0f0") {
|
||||
Ok(d) => {
|
||||
@@ -21,9 +43,7 @@ fn main() -> anyhow::Result<()> {
|
||||
// get the default Device
|
||||
|
||||
println!("Using device {}", device.name);
|
||||
let output = std::env::args()
|
||||
.nth(1)
|
||||
.expect("required output file argument");
|
||||
let output = args.device;
|
||||
println!("Using output v4l2loopback device {}", output);
|
||||
|
||||
const WIDTH: usize = 288;
|
||||
@@ -73,8 +93,12 @@ fn main() -> anyhow::Result<()> {
|
||||
// possibly limitation of current v4l2loopback or v4l rust wrapper or libv4l2
|
||||
let mut swapped = [0u8; FRAME_LEN];
|
||||
for i in 0..FRAME_LEN / 2 {
|
||||
swapped[i * 2] = frame[i * 2 + 1];
|
||||
swapped[i * 2 + 1] = frame[i * 2];
|
||||
let mut pixel = u16::from_be_bytes([frame[i * 2], frame[i * 2 + 1]]);
|
||||
if args.temperature {
|
||||
pixel = pixel_to_celcius(pixel);
|
||||
}
|
||||
let pixel_swapped = pixel.to_le_bytes();
|
||||
swapped[i * 2..i * 2 + 2].copy_from_slice(&pixel_swapped);
|
||||
}
|
||||
out.write_all(&swapped[..])?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user