forked from ehendrikd/slBenchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslBenchmark.h
453 lines (341 loc) · 12 KB
/
slBenchmark.h
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/*
* File: slBenchmark.h
*
* Copyright 2016 Evan Dekker
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Description:
*
* This file defines classes slBenchmark and slImplementation. The
* slBenchmark class conducts the structured light scanning tests
* and stores various benchmarking information. The slImplementation
* class allows a custom structured light implementation to be
* tested.
*/
#ifndef SLBENCHMARK_H
#define SLBENCHMARK_H
#include <iostream>
#include <iterator>
#include <fstream>
#include <stdlib.h>
#include <ctime>
#include <sys/stat.h>
#include <opencv2/opencv.hpp>
//Default camera resolution
#define DEFAULT_CAMERA_WIDTH 1920
#define DEFAULT_CAMERA_HEIGHT 1080
//Default camera index
#define DEFAULT_CAMERA_INDEX 0
//Default projection and capture wait (pause) time in milliseconds
#define DEFAULT_WAIT_TIME 1000
using namespace std;
using namespace cv;
//Debug
#ifdef DEBUG_BUILD
#define DB(x) cerr << x << endl;
#else
#define DB(x)
#endif
//Fatal error
#define FATAL(x) cerr << "FATAL: " << x << endl; exit(-1);
//Cross platform OS separator
#ifdef _WIN32
#define OS_SEP '\\'
#else
#define OS_SEP '/'
#endif
//Forward declaration
class slExperiment;
//Abstract class that defines a structured light implementation
class slImplementation {
public:
//Create a structured light implementation instance with an identifier (default scale)
slImplementation(string);
//Create a structured light implementation instance with an identifier, specifying a scale
slImplementation(string,double);
//Clean up
virtual ~slImplementation() {};
//Initialise prior to an experiment running
virtual void preExperimentRun() {};
//Initialise after an experiment has run
virtual void postExperimentRun() {};
// Get the width of the pattern and of the capture image.
// Typically this will be the image x-resultion, but this
// allows for the image to be cropped, and to take into account
// patterns with columns.
virtual double getPatternWidth();
virtual double getCaptureWidth();
//Compute the depth from a pair of x coordinates from the projection pattern and the image
virtual double getDisplacement(double,double);
//Get the identifier
string getIdentifier();
//Check if there are any more pattern generation and capture iterations
virtual bool hasMoreIterations();
//Generate the structure light pattern
virtual Mat generatePattern() = 0;
//Process during an interation
virtual void iterationProcess() {};
//Process after the interations
virtual void postIterationsProcess();
//Process the capture(s)
virtual void processCaptures() {};
//Iterate through the captures to solve the correseponce problem
virtual void iterateCorrespondences();
//Solve the correspondence problem
//virtual double solveCorrespondence(int, int) = 0;
virtual double solveCorrespondence(int, int) {return 0;}
//A reference to the current experiment
slExperiment *experiment;
//Get the scale
double getScale();
protected:
//Set the identifier
void setIdentifier(string);
//Set the scale
void setScale(double);
private:
//Initailise this structured light implementation instance
void initialise();
//A string used to identify this implementation
string identifier;
//The scaling factor for the depth.
// This number is multiplied to the calculated depth to
// avoid skewed results.
double zscale;
};
//Abstract infrastruture (projector and camera) class used for the benchmarking
class slInfrastructure {
public:
//Create an infrastructure instance with a benchmark and a name
slInfrastructure(
string,
Size newCameraResolution = Size(DEFAULT_CAMERA_WIDTH, DEFAULT_CAMERA_HEIGHT),
Rect newCroppedArea = Rect(0, 0, DEFAULT_CAMERA_WIDTH, DEFAULT_CAMERA_HEIGHT)
);
//Clean up
virtual ~slInfrastructure() {};
//Set the camera resolution
void setCameraResolution(Size);
//Set the cropped area
void setCroppedArea(Rect);
//Project the structured light implementation pattern and capture it
virtual Mat projectAndCapture(Mat) = 0;
//Return the name of this infrastructure
string getName();
//Get the camera resolution
Size getCameraResolution();
//Get the cropped area
Rect getCroppedArea();
//A reference to the current experiment
slExperiment *experiment;
protected:
//The camera resolution
Size cameraResolution;
//The cropped area
Rect croppedArea;
private:
//The name of this infrastructure
string name;
};
//Virtual infrastructure using open source 3D modelling software Blender (http://www.blender.org)
//NOTE: Ensure the blender executable can be found via the environment PATH variable to use
class slBlenderVirtualInfrastructure : public slInfrastructure {
public:
//Create a blender virtual infrastruture instance
slBlenderVirtualInfrastructure();
//Project the structured light implementation pattern and capture it
Mat projectAndCapture(Mat);
};
//Physical infrastructure using opencv projection and video capture
class slPhysicalInfrastructure : public slInfrastructure {
public:
//Create a physical infrastruture instance
slPhysicalInfrastructure(
Size newProjectorResolution = Size(DEFAULT_CAMERA_WIDTH, DEFAULT_CAMERA_HEIGHT),
Size newCameraResolution = Size(DEFAULT_CAMERA_WIDTH, DEFAULT_CAMERA_HEIGHT),
int newCameraIndex = DEFAULT_CAMERA_INDEX,
int newWaitTime = DEFAULT_WAIT_TIME
);
//Project the structured light implementation pattern and capture it
Mat projectAndCapture(Mat);
private:
//The projector resolution
Size projectorResolution;
//The camera index to use
int cameraIndex;
//The wait (pause) time in milliseconds between each projection and capture
int waitTime;
};
//Abstract class that defines a result from a particular experiment
class slExperimentResult {
public:
//Create an experiment result
slExperimentResult() {};
//Clean up
virtual ~slExperimentResult() {};
};
//Abstract class that defines an experiment that tests a given implementation on a given infrastructure
class slExperiment {
public:
//Get the current session path
static string getSessionPath();
//Create an experiment
slExperiment(slInfrastructure *, slImplementation *);
//Clean up
virtual ~slExperiment();
//Get the current experiment path
string getPath();
//Run this experiment
void run();
//Run before all iterations begin
virtual void runPreIterations() {};
//Run before this iteration begins
virtual void runPreIteration() {};
//Run before a pattern is generated
virtual void runPrePatternGeneration() {};
//Run after a pattern is generated
virtual void runPostPatternGeneration() {};
//Run before pattern is projected and captured
virtual void runPreProjectAndCapture() {};
//Run after pattern is projected and captured
virtual void runPostProjectAndCapture() {};
//Run before the implementation processes this iteration
virtual void runPreIterationProcess() {};
//Run after the implementation processes this iteration
virtual void runPostIterationProcess() {};
//Run after this iteration has completed
virtual void runPostIteration() {};
//Run after all iterations have completed
virtual void runPostIterations() {};
//Run before the implementation processes after all the iterations
virtual void runPreImplementationPostIterationsProcess() {};
//Run after the implementation processes after all the iterations
virtual void runPostImplementationPostIterationsProcess() {};
//Store a result of this experiment
virtual void storeResult(slExperimentResult *) {};
//Get the current infrastructure
slInfrastructure *getInfrastructure();
//Get the current pattern generation and capture iteration index
int getIterationIndex();
//Store the capture
void storeCapture(Mat);
//Get the capture at an index
Mat getCaptureAt(int);
//Get the last capture
Mat getLastCapture();
//Get the number of captures
int getNumberCaptures();
//Get a meaningful identifier of this experiment
string getIdentifier();
protected:
//The infrastructure used for this experiment
slInfrastructure *infrastructure;
//The implementation being tested in this experiement
slImplementation *implementation;
private:
//The current session path
static string sessionPath;
//The current experiment path
string path;
//The current pattern generation and capture iteration index
int iterationIndex;
//The stored captures
vector<Mat> *captures;
};
//Class that defines a kind of experiment that records depth
class slDepthExperiment : public virtual slExperiment {
public:
//Create a depth experiment
slDepthExperiment(slInfrastructure *, slImplementation *);
//Clean up
virtual ~slDepthExperiment();
//Store a result of this experiment
virtual void storeResult(slExperimentResult *);
//Run after the implementation processes after all the iterations
virtual void runPostImplementationPostIterationsProcess();
private:
//Check if the depth data value has been set
bool *depthDataValued;
//The depth data
double *depthData;
};
//Class that defines a depth experiment result with x, y and z coordinates
class slDepthExperimentResult : public slExperimentResult {
public:
//Create a depth experiment result
slDepthExperimentResult(int, int, double);
//The x coordinate
int x;
//The y coordinate
int y;
//The z coordinate
double z;
};
//Class that defines a kind of experiment that records the speed of processing
class slSpeedExperiment : public virtual slExperiment {
public:
//Create a speed experiment
slSpeedExperiment(slInfrastructure *, slImplementation *);
//Run before a pattern is generated
virtual void runPrePatternGeneration();
//Run after a pattern is generated
virtual void runPostPatternGeneration();
//Run before pattern is projected and captured
virtual void runPreProjectAndCapture();
//Run after pattern is projected and captured
virtual void runPostProjectAndCapture();
//Run before the implementation processes this iteration
virtual void runPreIterationProcess();
//Run after the implementation processes this iteration
virtual void runPostIterationProcess();
//Run before the implementation processes after all the iterations
virtual void runPrePostIterationsProcess();
//Run after the implementation processes after all the iterations
virtual void runPostPostIterationsProcess();
//Get the total clock value
clock_t getTotalClock();
private:
//The previous stored clock
clock_t previousClock;
//Total clock taken to run this experiment
long totalClock;
};
//Class that defines a kind of experiment that records the speed of processing and depth
class slSpeedDepthExperiment : public slSpeedExperiment, public slDepthExperiment {
public:
//Create a speed and depth experiment
slSpeedDepthExperiment(slInfrastructure *, slImplementation *);
};
//Abstract structured light benchmarking class that can compare measurable values of experiements
class slBenchmark {
public:
//Create a structured light benchmark
slBenchmark();
//Clean up
~slBenchmark();
//Add an experiment to this benchmark
void addExperiment(slExperiment *);
//Compare the experiments of this benchmark
virtual void compareExperiments() = 0;
protected:
//The experiments to benchmark
vector<slExperiment *> *experiments;
};
//Benchmark that compares the processing speed of each experiment
class slSpeedBenchmark : public slBenchmark {
public:
//Compare the experiments of this benchmark
virtual void compareExperiments();
};
#endif //SLBENCHMARK_H