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:
parent
faccc3d20b
commit
2347158093
|
@ -1,9 +1,31 @@
|
||||||
|
use clap::Parser;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use thermaldecoder::{Header, HDR_SIZE};
|
use thermaldecoder::{Header, HDR_SIZE};
|
||||||
use v4l::video::Output;
|
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<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
|
let args = Args::parse();
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
let device = match std::env::var("THERMALCAM_IFACE=enp1s0f0") {
|
let device = match std::env::var("THERMALCAM_IFACE=enp1s0f0") {
|
||||||
Ok(d) => {
|
Ok(d) => {
|
||||||
|
@ -21,9 +43,7 @@ fn main() -> anyhow::Result<()> {
|
||||||
// get the default Device
|
// get the default Device
|
||||||
|
|
||||||
println!("Using device {}", device.name);
|
println!("Using device {}", device.name);
|
||||||
let output = std::env::args()
|
let output = args.device;
|
||||||
.nth(1)
|
|
||||||
.expect("required output file argument");
|
|
||||||
println!("Using output v4l2loopback device {}", output);
|
println!("Using output v4l2loopback device {}", output);
|
||||||
|
|
||||||
const WIDTH: usize = 288;
|
const WIDTH: usize = 288;
|
||||||
|
@ -73,8 +93,12 @@ fn main() -> anyhow::Result<()> {
|
||||||
// possibly limitation of current v4l2loopback or v4l rust wrapper or libv4l2
|
// possibly limitation of current v4l2loopback or v4l rust wrapper or libv4l2
|
||||||
let mut swapped = [0u8; FRAME_LEN];
|
let mut swapped = [0u8; FRAME_LEN];
|
||||||
for i in 0..FRAME_LEN / 2 {
|
for i in 0..FRAME_LEN / 2 {
|
||||||
swapped[i * 2] = frame[i * 2 + 1];
|
let mut pixel = u16::from_be_bytes([frame[i * 2], frame[i * 2 + 1]]);
|
||||||
swapped[i * 2 + 1] = frame[i * 2];
|
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[..])?;
|
out.write_all(&swapped[..])?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,4 @@ TARGET=./target/release/examples/live
|
||||||
# setcap does not work yet (EPERM on socket AF_PACKET)
|
# setcap does not work yet (EPERM on socket AF_PACKET)
|
||||||
# sudo setcap cap_net_raw,cap_net_admin=eip $TARGET
|
# sudo setcap cap_net_raw,cap_net_admin=eip $TARGET
|
||||||
#sudo strace -f -o live.strace $TARGET /dev/video0
|
#sudo strace -f -o live.strace $TARGET /dev/video0
|
||||||
sudo $TARGET /dev/video0
|
sudo RUST_BACKTRACE=full $TARGET "$@"
|
||||||
|
|
13
run_live_debug.sh
Executable file
13
run_live_debug.sh
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
cd $(dirname $0)
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Python works but stutters
|
||||||
|
#sudo ./venv/bin/python ./decode.py --live
|
||||||
|
cargo build --example live
|
||||||
|
TARGET=./target/debug/examples/live
|
||||||
|
# setcap does not work yet (EPERM on socket AF_PACKET)
|
||||||
|
# sudo setcap cap_net_raw,cap_net_admin=eip $TARGET
|
||||||
|
#sudo strace -f -o live.strace $TARGET /dev/video0
|
||||||
|
sudo RUST_BACKTRACE=full $TARGET "$@"
|
Loading…
Reference in New Issue
Block a user