-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSingleLineImplementation.cpp
240 lines (167 loc) · 7.03 KB
/
SingleLineImplementation.cpp
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
#include "SingleLineImplementation.h"
SingleLineImplementation::SingleLineImplementation(int newNumberColumns): slImplementation(string("SingleLineImplementation")), numberColumns(newNumberColumns) {
}
bool SingleLineImplementation::hasMoreIterations() {
return experiment->getIterationIndex() < numberColumns;
}
double SingleLineImplementation::getPatternWidth() {
return (double)numberColumns;
}
Mat SingleLineImplementation::generatePattern() {
Size projectorResolution = experiment->getInfrastructure()->getProjectorResolution();
double columnWidth = (double)projectorResolution.width / (double)numberColumns;
int columnOffset = (int)((double)experiment->getIterationIndex() * columnWidth);
int projectorWidth = (int)projectorResolution.width;
int projectorHeight = (int)projectorResolution.height;
Mat pattern(projectorHeight, projectorWidth, CV_8UC3, Scalar(SINGLE_LINE_BLACK_VAL, SINGLE_LINE_BLACK_VAL, SINGLE_LINE_BLACK_VAL));
Scalar colour(SINGLE_LINE_WHITE_VAL, SINGLE_LINE_WHITE_VAL, SINGLE_LINE_WHITE_VAL);
//rectangle(pattern, Point(columnOffset, 0), Point((columnOffset + ((int)columnWidth - 1)), projectorHeight), colour, FILLED);
rectangle(pattern, Point(columnOffset, 0), Point(columnOffset, projectorHeight), colour, FILLED);
return pattern;
}
/*
void SingleLineImplementation::processCapture(Mat captureMat) {
Size cameraResolution = experiment->getInfrastructure()->getCameraResolution();
Size projectorResolution = experiment->getInfrastructure()->getProjectorResolution();
int xPattern = experiment->getIterationIndex();
for (int y = 0; y < cameraResolution.height; y++) {
int columnMax = 0;
// int foundColumn = -1;
int xColumn = -1;
double xCamera = -1.0;
for (int column = 0; column < cameraResolution.width; column++) {
Vec3b pixelBGR = captureMat.at<Vec3b>(y, column);
int colourTotal = pixelBGR[0] + pixelBGR[1] + pixelBGR[2];
if (colourTotal > columnMax) {
columnMax = colourTotal;
xColumn = column;
}
// if (colourTotal >= SINGLE_LINE_BLACK_THRESHOLD && colourTotal > columnMax) {
// columnMax = colourTotal;
// double prevColourTotal = 0.0;
// double nextColourTotal = 0.0;
// if (column > 0) {
// Vec3b prevPixelBGR = captureMat.at<Vec3b>(y, column - 1);
// prevColourTotal = (double)(prevPixelBGR[0] + prevPixelBGR[1] + prevPixelBGR[2]);
// }
// if (column < (cameraResolution.width - 1)) {
// Vec3b nextPixelBGR = captureMat.at<Vec3b>(y, column + 1);
// nextColourTotal = (double)(nextPixelBGR[0] + nextPixelBGR[1] + nextPixelBGR[2]);
// }
// xCamera = (double)column;
// if (y == 360) {
// DB("xPattern: " << xPattern << " column: " << column << " p: " << prevColourTotal << " c: " << colourTotal << " n: " << nextColourTotal)
// }
// break;
// }
}
if (columnMax >= SINGLE_LINE_BLACK_THRESHOLD) {
xCamera = (double)xColumn;
int prevColourTotal = 0;
int nextColourTotal = 0;
if (xColumn > 0) {
Vec3b prevPixelBGR = captureMat.at<Vec3b>(y, xColumn - 1);
prevColourTotal = prevPixelBGR[0] + prevPixelBGR[1] + prevPixelBGR[2];
}
if (xColumn < (cameraResolution.width - 1)) {
Vec3b nextPixelBGR = captureMat.at<Vec3b>(y, xColumn + 1);
nextColourTotal = nextPixelBGR[0] + nextPixelBGR[1] + nextPixelBGR[2];
}
//xCamera = (double)xColumn;
if (prevColourTotal != 0 && nextColourTotal != 0) {
int sidesTotal = prevColourTotal + nextColourTotal;
xCamera -= 0.5 + ((double)nextColourTotal / (double)sidesTotal);
// double offset = (double)nextColourTotal / (double)sidesTotal;
// if (fabs(0.5 - offset) <= SINGLE_LINE_PIXEL_THRESHOLD) {
// xCamera = (double)xColumn;
// }
}
// if (y == 360) {
//DB("xPattern: " << xPattern << " xCamera: " << xCamera << " p: " << prevColourTotal << " c: " << columnMax << " n: " << nextColourTotal)
// DB("xPattern," << xPattern << "," << xCamera)
// }
}
if (!isnan(xCamera) && xCamera != -1) {
double displacement = experiment->getDisplacement(xPattern, xCamera);
int xProjector = (int)(experiment->getImplementation()->getPatternXOffsetFactor(xPattern) * projectorResolution.width);
if (!isinf(displacement)) {
slDepthExperimentResult result(xProjector, y, displacement);
experiment->storeResult(&result);
}
}
}
}
*/
void SingleLineImplementation::processCapture(Mat captureMat) {
Size cameraResolution = experiment->getInfrastructure()->getCameraResolution();
Size projectorResolution = experiment->getInfrastructure()->getProjectorResolution();
int xPattern = experiment->getIterationIndex();
for (int y = 0; y < cameraResolution.height; y++) {
int columnMax = 0;
// int foundColumn = -1;
int xColumn = -1;
double xCamera = -1.0;
for (int column = 0; column < cameraResolution.width; column++) {
Vec3b pixelBGR = captureMat.at<Vec3b>(y, column);
int colourTotal = pixelBGR[0] + pixelBGR[1] + pixelBGR[2];
if (colourTotal > columnMax) {
columnMax = colourTotal;
xColumn = column;
}
}
if (columnMax >= SINGLE_LINE_BLACK_THRESHOLD) {
double lineTotal = 0;
double aTotal = 0;
if (xColumn > 1 && xColumn < cameraResolution.width - 3) {
for (int column = xColumn - 2; column <= xColumn + 2; column++) {
Vec3b pixelBGR = captureMat.at<Vec3b>(y, column);
double colourTotal = (double)(pixelBGR[0] + pixelBGR[1] + pixelBGR[2]);
lineTotal += colourTotal;
aTotal += ((double)column * colourTotal);
}
//xCamera = (aTotal / lineTotal) + 0.5;
xCamera = aTotal / lineTotal;
}
if (!isnan(xCamera) && xCamera != -1) {
double displacement = experiment->getDisplacement(xPattern, xCamera);
int xProjector = (int)(experiment->getImplementation()->getPatternXOffsetFactor(xPattern) * projectorResolution.width);
if (!isinf(displacement)) {
slDepthExperimentResult result(xProjector, y, displacement);
experiment->storeResult(&result);
}
}
}
}
}
/*
double SingleLineImplementation::solveCorrespondence(int xProjector, int y) {
Mat lineMat = experiment->getCaptureAt(xProjector);
int cameraWidth = experiment->getInfrastructure()->getCameraResolution().width;
double columnMax = 0.0;
int foundColumn = -1;
for (int column = 0; column < cameraWidth; column++) {
Vec3b pixelBGR = lineMat.at<Vec3b>(y, column);
double colourTotal = (double)(pixelBGR[0] + pixelBGR[1] + pixelBGR[2]);
if (colourTotal >= SINGLE_LINE_BLACK_THRESHOLD && colourTotal > columnMax) {
columnMax = colourTotal;
foundColumn = column;
}
}
return (double)foundColumn;
}
*/
/*
double SingleLineImplementation::solveCorrespondence(int xProjector, int y) {
Mat lineMat = experiment->getCaptureAt(xProjector);
int cameraWidth = experiment->getInfrastructure()->getCameraResolution().width;
double lineTotal = 0.0;
double aTotal = 0.0;
for (int column = 0; column < cameraWidth; column++) {
Vec3b pixelBGR = lineMat.at<Vec3b>(y, column);
double colourTotal = (double)(pixelBGR[0] + pixelBGR[1] + pixelBGR[2]);
lineTotal += colourTotal;
aTotal += ((double)column * colourTotal);
}
return aTotal / lineTotal;
}
*/