-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTrackingAlgorithm.h
More file actions
268 lines (213 loc) · 6.44 KB
/
TrackingAlgorithm.h
File metadata and controls
268 lines (213 loc) · 6.44 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
#ifndef TrackingAlgorithm_H
#define TrackingAlgorithm_H
#include <vector>
#include <memory>
#include <set>
#include <boost/optional.hpp>
#include <opencv2/opencv.hpp>
#include <QWidget>
#include <QMouseEvent>
#include "settings/Messages.h"
#include "settings/ParamNames.h"
#include "serialization/TrackedObject.h"
class Settings;
namespace Algorithm {
typedef uint8_t Type;
}
class ProxyMat {
public:
ProxyMat(cv::Mat const &mat)
: m_originalMat(mat) {
}
ProxyMat(const ProxyMat &) = delete;
ProxyMat &operator=(const ProxyMat &) = delete;
cv::Mat &getMat() {
if (!isModified()) {
m_modifiedMat = m_originalMat.clone();
}
return m_modifiedMat.get();
}
void setMat(cv::Mat mat) {
m_modifiedMat = mat;
}
bool isModified() const {
return m_modifiedMat.is_initialized();
}
private:
cv::Mat const &m_originalMat;
boost::optional<cv::Mat> m_modifiedMat;
};
class TrackingAlgorithm : public QObject {
Q_OBJECT
public:
TrackingAlgorithm(Settings &settings);
virtual ~TrackingAlgorithm() override = default;
struct View {
std::string name;
};
static const View OriginalView;
/**
* This function tracks the provided object list within the provided frame.
*/
virtual void track(ulong frameNumber, const cv::Mat &frame) = 0;
/**
* paint will be called by "VideoViews" paintEvent method
* so any picture manipulation stuff goes in here.
* QPainter paints stuff onto "VideoViews" current picture
* without touching it
*/
virtual void paint(ProxyMat &, View const & = OriginalView) {}
virtual void paintOverlay(QPainter *, View const & = OriginalView) {}
/**
* getToolsFrame() will be called once at start up
* to create a widget for gui with all
* buttons needed for interaction
*/
virtual std::shared_ptr<QWidget> getToolsWidget();
/**
* @brief grabbedKeys() has to return a set of all keys that the
* algorithms needs access to. All KeyEvents with keys in the set will
* be forwarded to the algorithm
* @return const reference to the set of keys
*/
virtual std::set<Qt::Key> const &grabbedKeys() const;
/**
* @brief prepareSave() is called once before the serialization of
* m_trackedObjects. It should store or discard all temporary values
* that are related to tracked Objects.
*/
virtual void prepareSave() {}
/**
* @brief postLoad() is called once after the tracked objects are
* loaded from serialized data. It should do any postprocessing required.
*/
virtual void postLoad() {}
/**
* @brief postConnect() is called once after the tracking algorithm has
* been initialized and the signals have been connected. It can be used
* to emit signals that only need to be emitted during object initialization.
*/
virtual void postConnect() {}
void loadObjects(std::vector<TrackedObject> const &objects);
void loadObjects(std::vector<TrackedObject> &&objects);
std::vector<TrackedObject> const &getObjects();
boost::optional<Algorithm::Type> getType() const {
return m_type;
}
void setType(Algorithm::Type type) {
m_type = type;
}
int getCurrentFrameNumber() const {
return m_currentFrameNumber;
}
int getMaxFrameNumber() const {
return m_maxFrameNumber;
}
float getCurrentZoomLevel() const {
return m_currentZoomLevel;
}
public Q_SLOTS:
/**
* receive Signal to set current frame number
*/
void setCurrentFrameNumber(int frameNumber) {
m_currentFrameNumber = frameNumber;
}
/**
* receive Signal to set maximum frame number
*/
void setmaxFrameNumber(int maxFrameNumber) {
m_maxFrameNumber = maxFrameNumber;
}
/**
* receive current zoom level from VideoView
*/
void setZoomLevel(float zLevel) {
m_currentZoomLevel = zLevel;
}
/**
* receive current image from TrackingThread
*/
void setCurrentImage(cv::Mat img) {
m_currentImage = img;
}
/**
* receive current video mode from gui
*/
void setCurrentVideoMode(GUIPARAM::VideoMode videoMode) {
m_videoMode = videoMode;
}
void setVideoFps(const size_t fps) {
m_videoFps = fps;
}
Q_SIGNALS:
/**
* send a message to the GUI.
*/
void notifyGUI(std::string message,
MSGS::MTYPE type = MSGS::MTYPE::NOTIFICATION);
/**
* send signal to VideoView and update display
*/
void update();
cv::Mat requestCurrentScreen();
void forceTracking();
void registerViews(const std::vector<View> views);
/**
* start/pause playback
*/
void pausePlayback(bool paused);
/**
* seek in framesequence
* @param framenumber where you want to jump to
*/
void jumpToFrame(int framenumber);
protected:
Settings &m_settings;
std::vector<TrackedObject> m_trackedObjects;
GUIPARAM::VideoMode getVideoMode() {
return m_videoMode;
}
bool event(QEvent *event) override;
/**
* @return either a copy of the current frame image, wrapped in a
* boost::optional, or a unintialized boost::optional, if there is no
* frame yet
*/
boost::optional<cv::Mat> getCurrentImageCopy() const;
/**
* will receive QMouseEvent as soon
* as mouse is getting moved in video view
*/
virtual void mouseMoveEvent(QMouseEvent * /* e */) {}
/**
* will receive QMouseEvent as soon
* as any mouse button is pressed in video view
*/
virtual void mousePressEvent(QMouseEvent * /* e */) {}
/**
* will receive QMouseEvent as soon
* as any mouse button is released in video view
*/
virtual void mouseReleaseEvent(QMouseEvent * /* e */) {}
/**
* will receive QMouseEvent as soond
* as mouse wheel is activated in video view
*/
virtual void mouseWheelEvent(QWheelEvent * /* e */) {}
/**
* will receive QKeyEvent as soon
* as any keyboard key from 'grabbedKeys()' is pressed in video view
*/
virtual void keyPressEvent(QKeyEvent * /* e */) {}
protected:
size_t m_videoFps = -1;
private:
int m_currentFrameNumber;
int m_maxFrameNumber;
float m_currentZoomLevel;
boost::optional<Algorithm::Type> m_type;
boost::optional<cv::Mat> m_currentImage;
GUIPARAM::VideoMode m_videoMode;
};
#endif // !TrackingAlgorithm_H