|
13 | 13 | /// |
14 | 14 | BaseDetector* CreateDetector( |
15 | 15 | tracking::Detectors detectorType, |
| 16 | + const BaseDetector::config_t& config, |
16 | 17 | bool collectPoints, |
17 | 18 | cv::UMat& gray |
18 | 19 | ) |
19 | 20 | { |
| 21 | + BaseDetector* detector = nullptr; |
| 22 | + |
20 | 23 | switch (detectorType) |
21 | 24 | { |
22 | 25 | case tracking::Motion_VIBE: |
23 | | - { |
24 | | - MotionDetector* detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_VIBE, collectPoints, gray); |
25 | | - BaseDetector::config_t config; |
26 | | - if (!detector->Init(config)) |
27 | | - { |
28 | | - delete detector; |
29 | | - detector = nullptr; |
30 | | - } |
31 | | - return detector; |
32 | | - } |
| 26 | + detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_VIBE, collectPoints, gray); |
| 27 | + break; |
33 | 28 |
|
34 | 29 | case tracking::Motion_MOG: |
35 | | - { |
36 | | - MotionDetector* detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_MOG, collectPoints, gray); |
37 | | - BaseDetector::config_t config; |
38 | | - if (!detector->Init(config)) |
39 | | - { |
40 | | - delete detector; |
41 | | - detector = nullptr; |
42 | | - } |
43 | | - return detector; |
44 | | - } |
| 30 | + detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_MOG, collectPoints, gray); |
| 31 | + break; |
45 | 32 |
|
46 | 33 | case tracking::Motion_GMG: |
47 | | - { |
48 | | - MotionDetector* detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_GMG, collectPoints, gray); |
49 | | - BaseDetector::config_t config; |
50 | | - if (!detector->Init(config)) |
51 | | - { |
52 | | - delete detector; |
53 | | - detector = nullptr; |
54 | | - } |
55 | | - return detector; |
56 | | - } |
| 34 | + detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_GMG, collectPoints, gray); |
| 35 | + break; |
57 | 36 |
|
58 | 37 | case tracking::Motion_CNT: |
59 | | - { |
60 | | - MotionDetector* detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_CNT, collectPoints, gray); |
61 | | - BaseDetector::config_t config; |
62 | | - if (!detector->Init(config)) |
63 | | - { |
64 | | - delete detector; |
65 | | - detector = nullptr; |
66 | | - } |
67 | | - return detector; |
68 | | - } |
| 38 | + detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_CNT, collectPoints, gray); |
| 39 | + break; |
69 | 40 |
|
70 | 41 | case tracking::Motion_SuBSENSE: |
71 | | - { |
72 | | - MotionDetector* detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_SuBSENSE, collectPoints, gray); |
73 | | - BaseDetector::config_t config; |
74 | | - if (!detector->Init(config)) |
75 | | - { |
76 | | - delete detector; |
77 | | - detector = nullptr; |
78 | | - } |
79 | | - return detector; |
80 | | - } |
| 42 | + detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_SuBSENSE, collectPoints, gray); |
| 43 | + break; |
81 | 44 |
|
82 | 45 | case tracking::Motion_LOBSTER: |
83 | | - { |
84 | | - MotionDetector* detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_LOBSTER, collectPoints, gray); |
85 | | - BaseDetector::config_t config; |
86 | | - if (!detector->Init(config)) |
87 | | - { |
88 | | - delete detector; |
89 | | - detector = nullptr; |
90 | | - } |
91 | | - return detector; |
92 | | - } |
| 46 | + detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_LOBSTER, collectPoints, gray); |
| 47 | + break; |
93 | 48 |
|
94 | 49 | case tracking::Motion_MOG2: |
95 | | - { |
96 | | - MotionDetector* detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_MOG2, collectPoints, gray); |
97 | | - BaseDetector::config_t config; |
98 | | - if (!detector->Init(config)) |
99 | | - { |
100 | | - delete detector; |
101 | | - detector = nullptr; |
102 | | - } |
103 | | - return detector; |
104 | | - } |
| 50 | + detector = new MotionDetector(BackgroundSubtract::BGFG_ALGS::ALG_MOG2, collectPoints, gray); |
| 51 | + break; |
105 | 52 |
|
106 | 53 | case tracking::Face_HAAR: |
107 | | - { |
108 | | - FaceDetector* detector = new FaceDetector(collectPoints, gray); |
109 | | - BaseDetector::config_t config; |
110 | | - config["cascadeFileName"] = "../data/haarcascade_frontalface_alt2.xml"; |
111 | | - if (!detector->Init(config)) |
112 | | - { |
113 | | - delete detector; |
114 | | - detector = nullptr; |
115 | | - } |
116 | | - return detector; |
117 | | - } |
| 54 | + detector = new FaceDetector(collectPoints, gray); |
| 55 | + break; |
118 | 56 |
|
119 | 57 | case tracking::Pedestrian_HOG: |
120 | 58 | case tracking::Pedestrian_C4: |
121 | | - { |
122 | | - PedestrianDetector* detector = new PedestrianDetector(collectPoints, gray); |
123 | | - BaseDetector::config_t config; |
124 | | - config["detectorType"] = (detectorType == tracking::Pedestrian_HOG) ? |
125 | | - std::to_string(PedestrianDetector::HOG) : std::to_string(PedestrianDetector::C4); |
126 | | - config["cascadeFileName1"] = "../data/combined.txt.model"; |
127 | | - config["cascadeFileName2"] = "../data/combined.txt.model_"; |
128 | | - if (!detector->Init(config)) |
129 | | - { |
130 | | - delete detector; |
131 | | - detector = nullptr; |
132 | | - } |
133 | | - return detector; |
134 | | - } |
| 59 | + detector = new PedestrianDetector(collectPoints, gray); |
| 60 | + break; |
135 | 61 |
|
136 | 62 | case tracking::DNN: |
137 | | - { |
138 | | - DNNDetector* detector = new DNNDetector(collectPoints, gray); |
139 | | - BaseDetector::config_t config; |
140 | | - config["modelConfiguration"] = "../data/MobileNetSSD_deploy.prototxt"; |
141 | | - config["modelBinary"] = "../data/MobileNetSSD_deploy.caffemodel"; |
142 | | - config["confidenceThreshold"] = "0.2"; |
143 | | - if (!detector->Init(config)) |
144 | | - { |
145 | | - delete detector; |
146 | | - detector = nullptr; |
147 | | - } |
148 | | - return detector; |
149 | | - } |
150 | | - |
| 63 | + detector = new DNNDetector(collectPoints, gray); |
| 64 | + break; |
151 | 65 |
|
152 | 66 | default: |
153 | | - return nullptr; |
| 67 | + break; |
| 68 | + } |
| 69 | + |
| 70 | + if (!detector->Init(config)) |
| 71 | + { |
| 72 | + delete detector; |
| 73 | + detector = nullptr; |
154 | 74 | } |
155 | | - return nullptr; |
| 75 | + return detector; |
156 | 76 | } |
0 commit comments