feat: show throttled live face detection rectangles
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -104,6 +104,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
);
|
||||
let mut sequence = capture::Sequence::default();
|
||||
let mut last_detection = Instant::now() - palm::DETECTION_INTERVAL;
|
||||
let mut last_faces = Instant::now() - faces::PREVIEW_INTERVAL;
|
||||
let mut live_faces = Vec::new();
|
||||
while worker_running.load(Ordering::Relaxed) {
|
||||
if !camera_log.run(|| cam.read(&mut frame))? || frame.empty() {
|
||||
eprintln!("Camera stopped providing frames");
|
||||
@@ -117,6 +119,18 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
let _ = detection_tx.try_send(frame.try_clone()?);
|
||||
last_detection = now;
|
||||
}
|
||||
// Run face analysis at most twice per second on the clean selfie frame.
|
||||
// Cache rectangles between samples; replace them even on empty results.
|
||||
if now.duration_since(last_faces) >= faces::PREVIEW_INTERVAL {
|
||||
live_faces = match face_detector.detect(&frame, false) {
|
||||
Ok(faces) => faces,
|
||||
Err(error) => {
|
||||
eprintln!("[faces ERROR] Live detection failed: {error}");
|
||||
Vec::new()
|
||||
}
|
||||
};
|
||||
last_faces = Instant::now();
|
||||
}
|
||||
let mut tracker_guard = tracker.lock().unwrap();
|
||||
let hand_detected = tracker_guard.has_palm(now);
|
||||
let take_picture = sequence.tick(tracker_guard.complete(now), hand_detected, now);
|
||||
@@ -132,6 +146,9 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
tracker_guard.draw(&mut frame, now)?;
|
||||
}
|
||||
drop(tracker_guard);
|
||||
// Draw only after capture and palm sampling so printed photos and
|
||||
// detector inputs never contain debug rectangles.
|
||||
faces::draw(&mut frame, &live_faces)?;
|
||||
let preview = PreviewFrame {
|
||||
buffer: frame_to_buffer(&frame)?,
|
||||
hand_detected,
|
||||
|
||||
Reference in New Issue
Block a user