1
1
use crate :: {
2
2
detection_filter:: TrackerFilter , detector:: visualize_detections, hogdetector:: HogDetectorTrait ,
3
- prelude:: DetectionFilter , HogDetector ,
3
+ prelude:: DetectionFilter ,
4
4
} ;
5
5
6
6
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 } ;
12
8
use web_sys:: ImageData ;
13
9
14
10
#[ derive( Clone ) ]
@@ -27,19 +23,16 @@ impl PartialEq for Pipeline {
27
23
}
28
24
29
25
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 {
38
31
Pipeline {
39
32
id : rand:: random ( ) ,
40
33
video_queue,
41
34
processed_queue,
42
- hog : Arc :: new ( Mutex :: new ( Box :: new ( hog ) ) ) ,
35
+ hog,
43
36
detection_filter : Arc :: new ( Mutex :: new ( TrackerFilter :: new ( 0.2 ) ) ) ,
44
37
}
45
38
}
@@ -70,7 +63,6 @@ impl Pipeline {
70
63
match self . hog . try_lock ( ) {
71
64
Ok ( mut processor_guard) => {
72
65
if let Some ( mut image_data) = self . video_queue . pop ( ) {
73
-
74
66
let processor = processor_guard. as_mut ( ) ;
75
67
let mut image = Pipeline :: to_dynamic_image ( image_data) ;
76
68
let detections = processor. detect ( & mut image) ;
0 commit comments