-
Notifications
You must be signed in to change notification settings - Fork 651
/
BaseDetector.cpp
106 lines (89 loc) · 3 KB
/
BaseDetector.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "BaseDetector.h"
#include "MotionDetector.h"
#include "FaceDetector.h"
#include "PedestrianDetector.h"
#include "OCVDNNDetector.h"
#ifdef BUILD_YOLO_LIB
#include "YoloDarknetDetector.h"
#endif
#ifdef BUILD_YOLO_TENSORRT
#include "YoloTensorRTDetector.h"
#endif
///
/// \brief CreateDetector
/// \param detectorType
/// \param gray
/// \return
///
std::unique_ptr<BaseDetector> BaseDetector::CreateDetector(tracking::Detectors detectorType,
const config_t& config,
const cv::UMat& frame)
{
std::unique_ptr<BaseDetector> detector;
switch (detectorType)
{
case tracking::Motion_VIBE:
detector = std::make_unique<MotionDetector>(BackgroundSubtract::BGFG_ALGS::ALG_VIBE, frame);
break;
case tracking::Motion_MOG:
detector = std::make_unique<MotionDetector>(BackgroundSubtract::BGFG_ALGS::ALG_MOG, frame);
break;
case tracking::Motion_GMG:
detector = std::make_unique<MotionDetector>(BackgroundSubtract::BGFG_ALGS::ALG_GMG, frame);
break;
case tracking::Motion_CNT:
detector = std::make_unique<MotionDetector>(BackgroundSubtract::BGFG_ALGS::ALG_CNT, frame);
break;
case tracking::Motion_SuBSENSE:
detector = std::make_unique<MotionDetector>(BackgroundSubtract::BGFG_ALGS::ALG_SuBSENSE, frame);
break;
case tracking::Motion_LOBSTER:
detector = std::make_unique<MotionDetector>(BackgroundSubtract::BGFG_ALGS::ALG_LOBSTER, frame);
break;
case tracking::Motion_MOG2:
detector = std::make_unique<MotionDetector>(BackgroundSubtract::BGFG_ALGS::ALG_MOG2, frame);
break;
case tracking::Face_HAAR:
detector = std::make_unique<FaceDetector>(frame);
break;
case tracking::Pedestrian_HOG:
case tracking::Pedestrian_C4:
detector = std::make_unique<PedestrianDetector>(frame);
break;
#ifdef USE_OCV_DNN
case tracking::DNN_OCV:
detector = std::make_unique<OCVDNNDetector>(frame);
break;
#endif
case tracking::Yolo_Darknet:
#ifdef BUILD_YOLO_LIB
detector = std::make_unique<YoloDarknetDetector>(frame);
#else
std::cerr << "Darknet inference engine was not configured in CMake" << std::endl;
#endif
break;
case tracking::Yolo_TensorRT:
#ifdef BUILD_YOLO_TENSORRT
detector = std::make_unique<YoloTensorRTDetector>(frame);
#else
std::cerr << "TensorRT inference engine was not configured in CMake" << std::endl;
#endif
break;
default:
break;
}
if (!detector->Init(config))
detector.reset();
return detector;
}
///
std::unique_ptr<BaseDetector> BaseDetector::CreateDetectorKV(tracking::Detectors detectorType, const KeyVal& config, const cv::Mat& gray)
{
config_t mconfig;
for (auto kv : config.m_config)
{
mconfig.emplace(kv.first, kv.second);
}
cv::UMat uframe = gray.getUMat(cv::ACCESS_READ);
return CreateDetector(detectorType, mconfig, uframe);
}