fix: move capture inference and print hook off camera thread
This commit is contained in:
@@ -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| {
|
||||
|
||||
Reference in New Issue
Block a user