support multiple faces and any number of hands

This commit is contained in:
Jules Youngberg 2022-06-15 21:04:08 -07:00
parent b82a7ff370
commit 2f1c40b494
4 changed files with 11 additions and 34 deletions

View File

@ -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");

View File

@ -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");

View File

@ -19,16 +19,9 @@ impl FaceMeshDetector {
}
/// Processes the input frame, returns a face mesh if detected.
pub fn process(&mut self, input: &Mat) -> Option<FaceMesh> {
pub fn process(&mut self, input: &Mat) -> Vec<Vec<Landmark>> {
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()
}
}

View File

@ -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<Vec<Landmark>> {
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()
}
}