Skip to content

Commit 8a2b75e

Browse files
committed
🐛 fix used model in pipeline
1 parent f5eb557 commit 8a2b75e

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn App() -> Html {
2424
Arc::new(Pipeline::new(
2525
(*video_queue).clone(),
2626
(*processed_queue).clone(),
27+
detector.get_model().clone(),
2728
))
2829
});
2930

src/wasm/hogdetector_js.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ impl HogDetectorJS {
4545
let y = y.into_iter().map(|y| y as usize).collect::<Vec<_>>();
4646
hog.fit_class(&x, &y, 1).unwrap();
4747
}
48+
49+
pub fn get_model(&self) -> &Arc<Mutex<Box<dyn HogDetectorTrait<f32, usize>>>> {
50+
&self.hog
51+
}
4852
}
4953

5054
#[wasm_bindgen]

src/wasm/pipeline.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
use crate::{
22
detection_filter::TrackerFilter, detector::visualize_detections, hogdetector::HogDetectorTrait,
3-
prelude::DetectionFilter, HogDetector,
3+
prelude::DetectionFilter,
44
};
55

66
use super::image_queue::ImageQueue;
7-
use object_detector_rust::{classifier::RandomForestClassifier, detector::PersistentDetector};
8-
use std::{
9-
io::Cursor,
10-
sync::{Arc, Mutex, TryLockError},
11-
};
7+
use std::sync::{Arc, Mutex, TryLockError};
128
use web_sys::ImageData;
139

1410
#[derive(Clone)]
@@ -27,19 +23,16 @@ impl PartialEq for Pipeline {
2723
}
2824

2925
impl Pipeline {
30-
pub fn new(video_queue: Arc<ImageQueue>, processed_queue: Arc<ImageQueue>) -> Self {
31-
let hog = {
32-
let mut model: HogDetector<f32, usize, RandomForestClassifier<_, _>, _> =
33-
HogDetector::default();
34-
let file = Cursor::new(include_bytes!("../../res/eyes_random_forest_model.json"));
35-
model.load(file).unwrap();
36-
model
37-
};
26+
pub fn new(
27+
video_queue: Arc<ImageQueue>,
28+
processed_queue: Arc<ImageQueue>,
29+
hog: Arc<Mutex<Box<dyn HogDetectorTrait<f32, usize>>>>,
30+
) -> Self {
3831
Pipeline {
3932
id: rand::random(),
4033
video_queue,
4134
processed_queue,
42-
hog: Arc::new(Mutex::new(Box::new(hog))),
35+
hog,
4336
detection_filter: Arc::new(Mutex::new(TrackerFilter::new(0.2))),
4437
}
4538
}
@@ -70,7 +63,6 @@ impl Pipeline {
7063
match self.hog.try_lock() {
7164
Ok(mut processor_guard) => {
7265
if let Some(mut image_data) = self.video_queue.pop() {
73-
7466
let processor = processor_guard.as_mut();
7567
let mut image = Pipeline::to_dynamic_image(image_data);
7668
let detections = processor.detect(&mut image);

0 commit comments

Comments
 (0)