forked from Smorodov/Multitarget-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrack.h
More file actions
213 lines (185 loc) · 4.39 KB
/
track.h
File metadata and controls
213 lines (185 loc) · 4.39 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
#pragma once
#include <iostream>
#include <vector>
#include <deque>
#include <memory>
#include <array>
#ifdef USE_OCV_KCF
#include <opencv2/tracking.hpp>
#endif
#include "defines.h"
#include "Kalman.h"
// --------------------------------------------------------------------------
///
/// \brief The TrajectoryPoint struct
///
struct TrajectoryPoint
{
///
/// \brief TrajectoryPoint
///
TrajectoryPoint()
: m_hasRaw(false)
{
}
///
/// \brief TrajectoryPoint
/// \param prediction
///
TrajectoryPoint(const Point_t& prediction)
:
m_hasRaw(false),
m_prediction(prediction)
{
}
///
/// \brief TrajectoryPoint
/// \param prediction
/// \param raw
///
TrajectoryPoint(const Point_t& prediction, const Point_t& raw)
:
m_hasRaw(true),
m_prediction(prediction),
m_raw(raw)
{
}
bool m_hasRaw;
Point_t m_prediction;
Point_t m_raw;
};
// --------------------------------------------------------------------------
///
/// \brief The Trace class
///
class Trace
{
public:
///
/// \brief operator []
/// \param i
/// \return
///
const Point_t& operator[](size_t i) const
{
return m_trace[i].m_prediction;
}
///
/// \brief operator []
/// \param i
/// \return
///
Point_t& operator[](size_t i)
{
return m_trace[i].m_prediction;
}
///
/// \brief at
/// \param i
/// \return
///
const TrajectoryPoint& at(size_t i) const
{
return m_trace[i];
}
///
/// \brief size
/// \return
///
size_t size() const
{
return m_trace.size();
}
///
/// \brief push_back
/// \param prediction
///
void push_back(const Point_t& prediction)
{
m_trace.push_back(TrajectoryPoint(prediction));
}
void push_back(const Point_t& prediction, const Point_t& raw)
{
m_trace.push_back(TrajectoryPoint(prediction, raw));
}
///
/// \brief pop_front
/// \param count
///
void pop_front(size_t count)
{
if (count < size())
{
m_trace.erase(m_trace.begin(), m_trace.begin() + count);
}
else
{
m_trace.clear();
}
}
///
/// \brief GetRawCount
/// \param lastPeriod
/// \return
///
size_t GetRawCount(size_t lastPeriod) const
{
size_t res = 0;
size_t i = 0;
if (lastPeriod < m_trace.size())
{
i = m_trace.size() - lastPeriod;
}
for (; i < m_trace.size(); ++i)
{
if (m_trace[i].m_hasRaw)
{
++res;
}
}
return res;
}
private:
std::deque<TrajectoryPoint> m_trace;
};
// --------------------------------------------------------------------------
///
/// \brief The CTrack class
///
class CTrack
{
public:
CTrack(const CRegion& region,
tracking::KalmanType kalmanType,
track_t deltaTime,
track_t accelNoiseMag,
size_t trackID,
bool filterObjectSize,
tracking::LostTrackType externalTrackerForLost);
track_t CalcDist(const Point_t& pt) const;
track_t CalcDist(const cv::Rect& r) const;
track_t CalcDistJaccard(const cv::Rect& r) const;
bool CheckType(const std::string& type) const;
void Update(const CRegion& region, bool dataCorrect, size_t max_trace_length, cv::UMat prevFrame, cv::UMat currFrame);
bool IsRobust(int minTraceSize, float minRawRatio, cv::Size2f sizeRatio) const;
Trace m_trace;
size_t m_trackID;
size_t m_skippedFrames;
CRegion m_lastRegion;
Point_t m_averagePoint; ///< Average point after LocalTracking
cv::Rect m_boundidgRect; ///< Bounding rect after LocalTracking
cv::Rect GetLastRect() const;
private:
Point_t m_predictionPoint;
cv::Rect m_predictionRect;
TKalmanFilter* m_kalman;
bool m_filterObjectSize;
tracking::LostTrackType m_externalTrackerForLost;
#ifdef USE_OCV_KCF
cv::Ptr<cv::Tracker> m_tracker;
#endif
void RectUpdate(const CRegion& region, bool dataCorrect, cv::UMat prevFrame, cv::UMat currFrame);
void CreateExternalTracker();
void PointUpdate(const Point_t& pt, bool dataCorrect, const cv::Size& frameSize);
};
typedef std::vector<std::unique_ptr<CTrack>> tracks_t;