fix: move capture inference and print hook off camera thread

This commit is contained in:
2026-11-10 15:10:19 +01:00
parent 838becdd70
commit 898ceb5726
4 changed files with 170 additions and 14 deletions

View File

@@ -166,11 +166,17 @@ pub struct LivePreview {
impl LivePreview {
pub fn new() -> opencv::Result<Self> {
use std::sync::{Arc, Mutex, mpsc};
let mut detector = Detector::new()?;
let (sender, receiver) = mpsc::sync_channel::<Mat>(0);
let result = Arc::new(Mutex::new((Instant::now(), Vec::new())));
let worker_result = Arc::clone(&result);
let worker = std::thread::spawn(move || {
let mut detector = match Detector::new() {
Ok(detector) => detector,
Err(error) => {
eprintln!("[faces ERROR] Could not load debug face model: {error}");
return;
}
};
while let Ok(frame) = receiver.recv() {
let started = Instant::now();
let faces = detector.detect(&frame, false).unwrap_or_else(|error| {