From 2f1c40b4946b6d1d1a6e44303af6e1e75aedfd81 Mon Sep 17 00:00:00 2001 From: Jules Youngberg Date: Wed, 15 Jun 2022 21:04:08 -0700 Subject: [PATCH] support multiple faces and any number of hands --- examples/face_mesh.rs | 8 +++----- examples/hand_tracking.rs | 8 +++----- src/face_mesh.rs | 11 ++--------- src/hands.rs | 18 +++--------------- 4 files changed, 11 insertions(+), 34 deletions(-) diff --git a/examples/face_mesh.rs b/examples/face_mesh.rs index 8039af9..6ca6b64 100644 --- a/examples/face_mesh.rs +++ b/examples/face_mesh.rs @@ -34,11 +34,9 @@ fn face_mesh() -> Result<()> { highgui::imshow(window, &mut flip_frame)?; - if let Some(fm) = result { - println!( - "LANDMARK: {} {} {}", - fm.data[0].x, fm.data[0].y, fm.data[0].z - ); + if !result.is_empty() { + let landmark = result[0][0]; + println!("LANDMARK: {} {} {}", landmark.x, landmark.y, landmark.z); } } else { println!("WARN: Skip empty frame"); diff --git a/examples/hand_tracking.rs b/examples/hand_tracking.rs index 3f84d0d..38a136f 100644 --- a/examples/hand_tracking.rs +++ b/examples/hand_tracking.rs @@ -34,11 +34,9 @@ pub fn hand_tracking() -> Result<()> { highgui::imshow(window, &mut flip_frame)?; - if let Some(hands) = result { - println!( - "LANDMARK: {} {} {}", - hands[0].data[0].x, hands[0].data[0].y, hands[0].data[0].z - ); + if !result.is_empty() { + let landmark = result[0][0]; + println!("LANDMARK: {} {} {}", landmark.x, landmark.y, landmark.z); } } else { println!("WARN: Skip empty frame"); diff --git a/src/face_mesh.rs b/src/face_mesh.rs index 0e85208..340b029 100644 --- a/src/face_mesh.rs +++ b/src/face_mesh.rs @@ -19,16 +19,9 @@ impl FaceMeshDetector { } /// Processes the input frame, returns a face mesh if detected. - pub fn process(&mut self, input: &Mat) -> Option { + pub fn process(&mut self, input: &Mat) -> Vec> { let landmarks = self.graph.process(input); - - if landmarks[0].is_empty() { - return None; - } - - let mut face_mesh = FaceMesh::default(); - face_mesh.data.copy_from_slice(landmarks[0][0].as_slice()); - Some(face_mesh) + landmarks[0].clone() } } diff --git a/src/hands.rs b/src/hands.rs index 335aa86..79e69d5 100644 --- a/src/hands.rs +++ b/src/hands.rs @@ -43,22 +43,10 @@ impl HandDetector { Self { graph } } - /// Processes the input frame, returns a tuple of hands if detected. - pub fn process(&mut self, input: &Mat) -> Option<[Hand; 2]> { + /// Processes the input frame, returns a list of hands + pub fn process(&mut self, input: &Mat) -> Vec> { let result = self.graph.process(input); - - if result[0].is_empty() { - return None; - } - - let landmarks = &result[0][0]; - - let mut lh = Hand::default(); - let mut rh = Hand::default(); - lh.data.copy_from_slice(&landmarks[0..21]); - rh.data.copy_from_slice(&landmarks[21..42]); - - Some([lh, rh]) + result[0].clone() } }