support multiple faces and any number of hands
This commit is contained in:
parent
b82a7ff370
commit
2f1c40b494
|
@ -34,11 +34,9 @@ fn face_mesh() -> Result<()> {
|
||||||
|
|
||||||
highgui::imshow(window, &mut flip_frame)?;
|
highgui::imshow(window, &mut flip_frame)?;
|
||||||
|
|
||||||
if let Some(fm) = result {
|
if !result.is_empty() {
|
||||||
println!(
|
let landmark = result[0][0];
|
||||||
"LANDMARK: {} {} {}",
|
println!("LANDMARK: {} {} {}", landmark.x, landmark.y, landmark.z);
|
||||||
fm.data[0].x, fm.data[0].y, fm.data[0].z
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("WARN: Skip empty frame");
|
println!("WARN: Skip empty frame");
|
||||||
|
|
|
@ -34,11 +34,9 @@ pub fn hand_tracking() -> Result<()> {
|
||||||
|
|
||||||
highgui::imshow(window, &mut flip_frame)?;
|
highgui::imshow(window, &mut flip_frame)?;
|
||||||
|
|
||||||
if let Some(hands) = result {
|
if !result.is_empty() {
|
||||||
println!(
|
let landmark = result[0][0];
|
||||||
"LANDMARK: {} {} {}",
|
println!("LANDMARK: {} {} {}", landmark.x, landmark.y, landmark.z);
|
||||||
hands[0].data[0].x, hands[0].data[0].y, hands[0].data[0].z
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("WARN: Skip empty frame");
|
println!("WARN: Skip empty frame");
|
||||||
|
|
|
@ -19,16 +19,9 @@ impl FaceMeshDetector {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes the input frame, returns a face mesh if detected.
|
/// 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);
|
let landmarks = self.graph.process(input);
|
||||||
|
landmarks[0].clone()
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
src/hands.rs
18
src/hands.rs
|
@ -43,22 +43,10 @@ impl HandDetector {
|
||||||
Self { graph }
|
Self { graph }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Processes the input frame, returns a tuple of hands if detected.
|
/// Processes the input frame, returns a list of hands
|
||||||
pub fn process(&mut self, input: &Mat) -> Option<[Hand; 2]> {
|
pub fn process(&mut self, input: &Mat) -> Vec<Vec<Landmark>> {
|
||||||
let result = self.graph.process(input);
|
let result = self.graph.process(input);
|
||||||
|
result[0].clone()
|
||||||
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])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user