🚧 wip: add a hand tracking experiment I left un-finished

main
_ 2023-09-27 19:41:56 -05:00
parent 97df0bcb53
commit fface403af
2 changed files with 68 additions and 0 deletions

66
src/hand_tracking.rs Normal file
View File

@ -0,0 +1,66 @@
use std::{
fs,
time::Instant,
};
pub fn main () {
let src_width = 1280usize;
let src_height = 720usize;
let src_stride = 3 * src_width;
let path = "untracked/input.jpg";
let jpeg_buf = fs::read (path).unwrap ();
let rgb = {
let start = Instant::now ();
let mut decoder = zune_jpeg::JpegDecoder::new_with_options (&jpeg_buf, zune_core::options::DecoderOptions::new_fast().jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::RGB));
decoder.decode_headers().unwrap ();
let info = decoder.info ().unwrap ();
assert_eq! (src_width, usize::try_from (info.width).unwrap ());
assert_eq! (src_height, usize::try_from (info.height).unwrap ());
let mut rgb = vec! [0u8; decoder.output_buffer_size ().unwrap ()];
assert_eq! (rgb.len (), src_stride * src_height);
decoder.decode_into (&mut rgb).unwrap ();
let stop = Instant::now ();
println! ("Decoded in {} ms", (stop - start).as_millis ());
rgb
};
let dst_width = src_width / 8;
let dst_height = src_height / 8;
let dst_stride = dst_width;
{
let start = Instant::now ();
let mut buf = vec! [0u8; dst_width * dst_height];
for y in 0..dst_height {
for x in 0..dst_width {
let dst_i = y * dst_stride + x;
let src_i = y * 8 * src_stride + x * 8 * 3;
let r = rgb [src_i + 0];
let g = rgb [src_i + 1];
let b = rgb [src_i + 2];
let x =
r
.saturating_sub (g)
.saturating_add (r)
.saturating_sub (b);
buf [dst_i] = x;
}
}
let stop = Instant::now ();
println! ("Shrank and filtered in {} ms", (stop - start).as_millis ());
fs::write ("untracked/skin_filter.data", &buf).unwrap ();
}
}

View File

@ -16,6 +16,7 @@ use tokio::sync::
mod capture;
mod controller;
mod driver;
mod hand_tracking;
use driver::
{
@ -52,6 +53,7 @@ fn main() -> Result <(), Error>
println! ("{} ms", (stop - start).as_millis ());
},
Some ("hand-tracking") => hand_tracking::main (),
Some ("network") => main_network (),
Some (_) => eprintln! ("Unknown subcommand"),
}