From fface403af6fa0cc2a937873c8d16ea2ca097ae2 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Wed, 27 Sep 2023 19:41:56 -0500 Subject: [PATCH] :construction: wip: add a hand tracking experiment I left un-finished --- src/hand_tracking.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 ++ 2 files changed, 68 insertions(+) create mode 100644 src/hand_tracking.rs diff --git a/src/hand_tracking.rs b/src/hand_tracking.rs new file mode 100644 index 0000000..869d41a --- /dev/null +++ b/src/hand_tracking.rs @@ -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 (); + } +} diff --git a/src/main.rs b/src/main.rs index 37f38a6..568a61e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"), }