forked from Smorodov/Multitarget-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackerSettings.h
More file actions
297 lines (251 loc) · 7.1 KB
/
TrackerSettings.h
File metadata and controls
297 lines (251 loc) · 7.1 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#pragma once
#include <vector>
#include <array>
#include <numeric>
#include "defines.h"
///
/// \brief The TrackerSettings struct
///
struct TrackerSettings
{
///
/// Tracker settings
///
///
tracking::TrackerTemplate m_tracker = tracking::UniversalTracker;
tracking::KalmanType m_kalmanType = tracking::KalmanLinear;
tracking::FilterGoal m_filterGoal = tracking::FilterCenter;
tracking::LostTrackType m_lostTrackType = tracking::TrackKCF; // Used if m_filterGoal == tracking::FilterRect
tracking::MatchType m_matchType = tracking::MatchLAPJV;
std::array<track_t, tracking::DistsCount> m_distType;
///
/// \brief m_dt
/// Time step for Kalman
///
track_t m_dt = 1.0f;
///
/// \brief m_accelNoiseMag
/// Noise magnitude for Kalman
///
track_t m_accelNoiseMag = 0.1f;
///
/// \brief m_useAcceleration
/// Constant velocity or constant acceleration motion model
///
bool m_useAcceleration = false;
///
/// \brief m_distThres
/// Distance threshold for Assignment problem: from 0 to 1
///
track_t m_distThres = 0.8f;
///
/// \brief m_minAreaRadius
/// Minimal area radius in pixels for objects centers
///
track_t m_minAreaRadiusPix = 20.f;
///
/// \brief m_minAreaRadius
/// Minimal area radius in ration for object size. Used if m_minAreaRadiusPix < 0
///
track_t m_minAreaRadiusK = 0.5f;
///
/// \brief m_maximumAllowedLostTime
/// If the object don't assignment more than this time in seconds then it will be removed
///
double m_maximumAllowedLostTime = 1.;
///
/// \brief m_maxTraceLength
/// The maximum trajectory length in seconds
///
double m_maxTraceLength = 2.f;
///
/// \brief m_useAbandonedDetection
/// Detection abandoned objects
///
bool m_useAbandonedDetection = false;
///
/// \brief m_minStaticTime
/// After this time (in seconds) the object is considered abandoned
///
int m_minStaticTime = 5;
///
/// \brief m_maxStaticTime
/// After this time (in seconds) the abandoned object will be removed
///
int m_maxStaticTime = 25;
///
/// \brief m_maxSpeedForStatic
/// Speed in meters
/// If speed of object is more that this value than object is non static
///
track_t m_maxSpeedForStatic = 0.5f;
///
/// \brief m_nearTypes
/// Object types that can be matched while tracking
///
std::map<objtype_t, std::set<objtype_t>> m_nearTypes;
///
/// \brief struct ByteTrackSettings
/// Settings only for m_tracker = tracking::ByteTrack
///
struct ByteTrackSettings
{
int m_trackBuffer = 30;
float m_trackThresh = 0.5f;
float m_highThresh = 0.5f;
float m_matchThresh = 0.8f;
};
ByteTrackSettings m_byteTrackSettings;
///
/// Detector settings
///
///
std::string m_nnWeights = "data/yolov4-tiny_best.weights";
///
std::string m_nnConfig = "data/yolov4-tiny.cfg";
///
std::string m_classNames = "data/traffic.names";
///
std::deque<std::string> m_whiteList;
///
float m_confidenceThreshold = 0.5f;
///
float m_maxCropRatio = -1.f;
///
int m_maxBatch = 1;
///
int m_gpuId = 0;
///
/// \brief Neural network input size
cv::Size m_inputSize{ 0, 0 };
///
/// YOLOV2
/// YOLOV3
/// YOLOV4
/// YOLOV4_TINY
/// YOLOV5
std::string m_netType = "YOLOV4";
///
/// INT8
/// FP16
/// FP32
std::string m_inferencePrecision = "FP16";
// opencv_dnn = 6
// tensorrt = 5
int m_detectorBackend = 5;
// DNN_TARGET_CPU
// DNN_TARGET_OPENCL
// DNN_TARGET_OPENCL_FP16
// DNN_TARGET_MYRIAD
// DNN_TARGET_CUDA
// DNN_TARGET_CUDA_FP16
std::string m_dnnTarget = "DNN_TARGET_CPU";
// DNN_BACKEND_DEFAULT
// DNN_BACKEND_HALIDE
// DNN_BACKEND_INFERENCE_ENGINE
// DNN_BACKEND_OPENCV
// DNN_BACKEND_VKCOM
// DNN_BACKEND_CUDA
// DNN_BACKEND_INFERENCE_ENGINE_NGRAPH
// DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019
std::string m_dnnBackend = "DNN_BACKEND_OPENCV";
// For TensorRT optimization, bytes
size_t m_maxVideoMemory = 0;
///
struct EmbeddingParams
{
///
/// \brief m_embeddingCfgName
/// Neural network config file for embeddings
///
std::string m_embeddingCfgName;
///
/// \brief m_embeddingWeightsName
/// Neural network weights file for embeddings
///
std::string m_embeddingWeightsName;
///
cv::Size m_inputLayer{128, 256};
///
std::vector<objtype_t> m_objectTypes;
EmbeddingParams(const std::string& embeddingCfgName, const std::string& embeddingWeightsName,
const cv::Size& inputLayer, const std::vector<objtype_t>& objectTypes)
: m_embeddingCfgName(embeddingCfgName),
m_embeddingWeightsName(embeddingWeightsName),
m_inputLayer(inputLayer),
m_objectTypes(objectTypes)
{
assert(!m_objectTypes.empty());
}
};
///
std::vector<EmbeddingParams> m_embeddings;
///
TrackerSettings()
{
m_distType[tracking::DistCenters] = static_cast<track_t>(0.0);
m_distType[tracking::DistRects] = static_cast<track_t>(0.0);
m_distType[tracking::DistJaccard] = static_cast<track_t>(0.5);
m_distType[tracking::DistHist] = static_cast<track_t>(0.5);
m_distType[tracking::DistFeatureCos] = static_cast<track_t>(0.0);
m_distType[tracking::DistMahalanobis] = static_cast<track_t>(0.0);
assert(CheckDistance());
}
///
bool CheckDistance() const
{
track_t sum = std::accumulate(m_distType.begin(), m_distType.end(), static_cast<track_t>(0.0));
track_t maxOne = std::max(static_cast<track_t>(1.0), std::fabs(sum));
//std::cout << "CheckDistance: " << sum << " - " << (std::numeric_limits<track_t>::epsilon() * maxOne) << ", " << std::fabs(sum - 1.0f) << std::endl;
return std::fabs(sum - static_cast<track_t>(1.0)) <= std::numeric_limits<track_t>::epsilon() * maxOne;
}
///
bool SetDistances(std::array<track_t, tracking::DistsCount> distType)
{
bool res = true;
auto oldDists = m_distType;
m_distType = distType;
if (!CheckDistance())
{
m_distType = oldDists;
res = false;
}
return res;
}
///
bool SetDistance(tracking::DistType distType)
{
std::fill(m_distType.begin(), m_distType.end(), 0.0f);
m_distType[distType] = 1.f;
return true;
}
///
void AddNearTypes(objtype_t type1, objtype_t type2, bool sym)
{
auto AddOne = [&](objtype_t type1, objtype_t type2)
{
auto it = m_nearTypes.find(type1);
if (it == std::end(m_nearTypes))
m_nearTypes[type1] = std::set<objtype_t>{ type2 };
else
it->second.insert(type2);
};
AddOne(type1, type2);
if (sym)
AddOne(type2, type1);
}
///
bool CheckType(objtype_t type1, objtype_t type2) const
{
bool res = (type1 == bad_type) || (type2 == bad_type) || (type1 == type2);
if (!res)
{
auto it = m_nearTypes.find(type1);
if (it != std::end(m_nearTypes))
res = it->second.find(type2) != std::end(it->second);
}
return res;
}
};
///
bool ParseTrackerSettings(const std::string& settingsFile, TrackerSettings& trackerSettings);