From 8a2b75e9ba344f32b423e1228c5be245a79465de Mon Sep 17 00:00:00 2001 From: Christian M Date: Sun, 31 Dec 2023 08:11:05 +0100 Subject: [PATCH] :bug: fix used model in pipeline --- src/main.rs | 1 + src/wasm/hogdetector_js.rs | 4 ++++ src/wasm/pipeline.rs | 24 ++++++++---------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index c4e68f1..ed764b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ pub fn App() -> Html { Arc::new(Pipeline::new( (*video_queue).clone(), (*processed_queue).clone(), + detector.get_model().clone(), )) }); diff --git a/src/wasm/hogdetector_js.rs b/src/wasm/hogdetector_js.rs index 68b78a2..da18ef0 100644 --- a/src/wasm/hogdetector_js.rs +++ b/src/wasm/hogdetector_js.rs @@ -45,6 +45,10 @@ impl HogDetectorJS { let y = y.into_iter().map(|y| y as usize).collect::>(); hog.fit_class(&x, &y, 1).unwrap(); } + + pub fn get_model(&self) -> &Arc>>> { + &self.hog + } } #[wasm_bindgen] diff --git a/src/wasm/pipeline.rs b/src/wasm/pipeline.rs index e4d83b3..e7f0e7b 100644 --- a/src/wasm/pipeline.rs +++ b/src/wasm/pipeline.rs @@ -1,14 +1,10 @@ use crate::{ detection_filter::TrackerFilter, detector::visualize_detections, hogdetector::HogDetectorTrait, - prelude::DetectionFilter, HogDetector, + prelude::DetectionFilter, }; use super::image_queue::ImageQueue; -use object_detector_rust::{classifier::RandomForestClassifier, detector::PersistentDetector}; -use std::{ - io::Cursor, - sync::{Arc, Mutex, TryLockError}, -}; +use std::sync::{Arc, Mutex, TryLockError}; use web_sys::ImageData; #[derive(Clone)] @@ -27,19 +23,16 @@ impl PartialEq for Pipeline { } impl Pipeline { - pub fn new(video_queue: Arc, processed_queue: Arc) -> Self { - let hog = { - let mut model: HogDetector, _> = - HogDetector::default(); - let file = Cursor::new(include_bytes!("../../res/eyes_random_forest_model.json")); - model.load(file).unwrap(); - model - }; + pub fn new( + video_queue: Arc, + processed_queue: Arc, + hog: Arc>>>, + ) -> Self { Pipeline { id: rand::random(), video_queue, processed_queue, - hog: Arc::new(Mutex::new(Box::new(hog))), + hog, detection_filter: Arc::new(Mutex::new(TrackerFilter::new(0.2))), } } @@ -70,7 +63,6 @@ impl Pipeline { match self.hog.try_lock() { Ok(mut processor_guard) => { if let Some(mut image_data) = self.video_queue.pop() { - let processor = processor_guard.as_mut(); let mut image = Pipeline::to_dynamic_image(image_data); let detections = processor.detect(&mut image);