forked from aclapes/segmenthreetion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModalityData.hpp
348 lines (271 loc) · 8.13 KB
/
ModalityData.hpp
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
//
// ModalityData.h
// segmenthreetion
//
// Created by Albert Clapés on 01/03/14.
//
//
#ifndef __segmenthreetion__ModalityData__
#define __segmenthreetion__ModalityData__
#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
class ModalityData
{
public:
ModalityData() {}
ModalityData(vector<cv::Mat> frames, vector<cv::Mat> masks, vector<cv::Mat> predictedMasks, vector< vector<cv::Rect> > rects, vector< vector<int> > tags) : m_Frames(frames), m_GroundTruthMasks(masks), m_PredictedMasks(predictedMasks), m_PredictedBoundingRects(rects), m_Tags(tags) {}
// Getters
string getModality()
{
return m_ModalityName;
}
cv::Mat getFrame(int k)
{
return m_Frames[k];
}
cv::Mat getPredictedMask(int k)
{
return m_PredictedMasks[k];
}
cv::Mat getPredictedMask(int k, unsigned char subjectId)
{
return (m_PredictedMasks[k] == (m_MasksOffset + subjectId));
}
cv::Mat getGroundTruthMask(int k)
{
return m_GroundTruthMasks[k];
}
cv::Mat getGroundTruthMask(int k, unsigned char subjectId)
{
return (m_GroundTruthMasks[k] == (m_MasksOffset + subjectId));
}
vector<cv::Mat> *getPredictedMasksInScene(int s)
{
vector<cv::Mat> *sceneMasks = new vector<cv::Mat>;
for(int k = m_SceneLimits[s].first; k <= (m_SceneLimits[s].second); k++ )
{
sceneMasks->push_back(m_PredictedMasks[k]);
}
return sceneMasks;
}
cv::Mat getPredictedMaskInScene(int s, int k)
{
return m_PredictedMasks[m_SceneLimits[s].first + k];
}
cv::Mat getPredictedMaskInScene(int s, int k, unsigned char subjectId)
{
return (m_PredictedMasks[m_SceneLimits[s].first + k] == (m_MasksOffset + subjectId));
}
vector<cv::Mat> *getFramesInScene(int s)
{
vector<cv::Mat> *sceneFrames = new vector<cv::Mat>;
for(int k = m_SceneLimits[s].first; k <= (m_SceneLimits[s].second); k++ )
{
sceneFrames->push_back(m_Frames[k]);
}
return sceneFrames;
}
cv::Mat getFrameInScene(int s, int k)
{
return m_Frames[m_SceneLimits[s].first + k];
}
cv::Mat getRegFrameInScene(int s, int k)
{
return m_RegFrames[m_SceneLimits[s].first + k];
}
vector<cv::Mat> *getGroundTruthMasksInScene(int s)
{
vector<cv::Mat> *gtMasks = new vector<cv::Mat>;
for(int k = m_SceneLimits[s].first; k <= (m_SceneLimits[s].second); k++ )
{
gtMasks->push_back(m_GroundTruthMasks[k]);
}
return gtMasks;
}
cv::Mat getGroundTruthMaskInScene(int s, int k)
{
return m_GroundTruthMasks[m_SceneLimits[s].first + k];
}
vector<cv::Rect> getPredictedBoundingRectsInFrame(int k)
{
return m_PredictedBoundingRects[k];
}
vector<vector<cv::Rect> > *getPredictedBoundingRectsInScene(int s)
{
vector<vector<cv::Rect> > *bbScene = new vector<vector<cv::Rect> >;
for(int k = m_SceneLimits[s].first; k <= (m_SceneLimits[s].second); k++ )
{
bbScene->push_back(m_PredictedBoundingRects[k]);
}
return bbScene;
}
vector<cv::Rect> getGroundTruthBoundingRectsInFrame(int k)
{
return m_GroundTruthBoundingRects[k];
}
int getNumScenes()
{
return m_SceneLimits.size();
}
int getSceneSize(int s)
{
return m_SceneLimits[s].second - m_SceneLimits[s].first + 1;
}
vector<int> getTagsInFrame(int k)
{
return m_Tags[k];
}
vector<vector<int> > *getTagsInScene(int s)
{
vector<vector<int> > *tagsScene = new vector<vector<int> >;
for(int k = m_SceneLimits[s].first; k <= (m_SceneLimits[s].second); k++ )
{
tagsScene->push_back(m_Tags[k]);
}
return tagsScene;
}
vector<cv::Mat>& getFrames()
{
return m_Frames;
}
vector<cv::Mat>& getRegFrames()
{
return m_RegFrames;
}
vector<cv::Mat>& getPredictedMasks()
{
return m_PredictedMasks;
}
/*
vector<int>& getFrameIDs()
{
return m_FrameIDs;
}
*/
vector<cv::Mat>& getGroundTruthMasks()
{
return m_GroundTruthMasks;
}
vector< vector<cv::Rect> >& getPredictedBoundingRects()
{
return m_PredictedBoundingRects;
}
vector< vector<cv::Rect> >& getGroundTruthBoundingRects()
{
return m_GroundTruthBoundingRects;
}
vector< vector<int> >& getTags()
{
return m_Tags;
}
unsigned char getMasksOffset()
{
return m_MasksOffset;
}
vector<string>& getCalibVarsDirs()
{
return m_CalibVarsDirs;
}
vector<string>& getFramesIndices()
{
return m_FramesIndices;
}
vector<string> *getFramesIndicesInScene(int s)
{
vector<string> *indices = new vector<string>;
for(int k = m_SceneLimits[s].first; k <= (m_SceneLimits[s].second); k++ )
{
indices->push_back(m_FramesIndices[k]);
}
return indices;
}
bool isFilled()
{
return m_Frames.size() > 0 && m_GroundTruthMasks.size() > 0 && m_PredictedMasks.size() > 0
&& m_FramesIndices.size() > 0 && m_PredictedBoundingRects.size() > 0 && m_Tags.size() > 0;
}
// Setters
void setModality(string name)
{
m_ModalityName = name;
}
void setFrames(vector<cv::Mat> frames)
{
m_Frames = frames;
m_FramesResolutions.create(m_Frames.size(), 2, cv::DataType<int>::type);
for (int i = 0; i < m_Frames.size(); i++)
{
m_FramesResolutions.at<int>(i,0) = m_Frames[i].cols; // inverted
m_FramesResolutions.at<int>(i,1) = m_Frames[i].rows;
}
}
void setRegFrames(vector<cv::Mat> regFrames)
{
m_RegFrames = regFrames;
}
void setGroundTruthMasks(vector<cv::Mat> masks)
{
m_GroundTruthMasks = masks;
}
void setPredictedMasks(vector<cv::Mat> masks)
{
m_PredictedMasks = masks;
}
/*
void setFrameIDs(vector<int> frameids)
{
m_FrameIDs = frameids;
}
*/
void setPredictedBoundingRects(vector< vector<cv::Rect> > rects)
{
m_PredictedBoundingRects = rects;
}
void setGroundTruthBoundingRects(vector< vector<cv::Rect> > groundTruthBoundingRects)
{
m_GroundTruthBoundingRects = groundTruthBoundingRects;
}
void setTags(vector< vector<int> > tags)
{
m_Tags = tags;
}
void setMasksOffset(unsigned char masksOffset)
{
m_MasksOffset = masksOffset;
}
void setCalibVarsDirs(vector<string> calibVarsDirs)
{
m_CalibVarsDirs = calibVarsDirs;
}
void setFramesIndices(vector<string> framesIndices)
{
m_FramesIndices = framesIndices;
}
void setSceneLimits(vector< pair<int, int> > sceneLimits)
{
m_SceneLimits = sceneLimits;
}
private:
string m_ModalityName;
// Load data from disk: frames, masks, and rectangular bounding boxes
vector<cv::Mat> m_Frames;
vector<cv::Mat> m_RegFrames;
//vector<cv::Mat> m_Masks; // groundtruth masks
vector<cv::Mat> m_PredictedMasks; // bs predicted masks
//vector<int> m_FrameIDs;
//vector<cv::Mat> m_Masks;
vector<cv::Mat> m_GroundTruthMasks;
vector<string> m_FramesIndices;
vector< vector<cv::Rect> > m_PredictedBoundingRects;
vector< vector<cv::Rect> > m_GroundTruthBoundingRects;
vector< vector<int> > m_Tags;
vector<string> m_CalibVarsDirs;
cv::Mat m_FramesResolutions;
vector< pair<int, int> > m_SceneLimits;
unsigned char m_MasksOffset;
};
#endif /* defined(__segmenthreetion__ModalityData__) */