-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGrayCodedBinaryImplementation.cpp
114 lines (84 loc) · 3.4 KB
/
GrayCodedBinaryImplementation.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
#include "GrayCodedBinaryImplementation.h"
GrayCodedBinaryImplementation::GrayCodedBinaryImplementation(int newNumberColumns) : BinaryImplementation(newNumberColumns) {
setIdentifier(string("GrayCodedBinaryImplementation"));
}
Mat GrayCodedBinaryImplementation::generatePattern() {
Mat pattern;
Scalar colour;
Size projectorResolution = experiment->getInfrastructure()->getProjectorResolution();
int projectorWidth = (int)projectorResolution.width;
int projectorHeight = (int)projectorResolution.height;
generateBackground(pattern,colour);
int columnWidth = projectorWidth / currentNumberColumns;
int doubleColumnWidth = columnWidth * 2;
int xPos = 0;
for (int columnIndex = 0; columnIndex < currentNumberColumns; columnIndex++) {
if (columnIndex % 4 == 1) {
rectangle(pattern, Point(xPos, 0), Point((xPos + doubleColumnWidth) - 1, projectorHeight), colour, FILLED);
}
xPos += columnWidth;
}
return pattern;
}
// Getters and Setters
double GrayCodedBinaryImplementation::getBinaryCode(int xProjector, int y) {
Size cameraResolution = experiment->getInfrastructure()->getCameraResolution();
/*
int binCode = this->binaryCode[(y * cameraResolution.width) + xProjector];
if(binCode == -1) return -1;
return convertGrayCodeToInteger(binCode, numberColumns, getNumberPatterns());
*/
for (int x = 0; x < cameraResolution.width; x++) {
int currentBinaryCode = binaryCode[(y * cameraResolution.width) + x];
if (currentBinaryCode != -1) {
int binaryXProjector = convertGrayCodeToInteger(currentBinaryCode, getNumberPatterns());
if (binaryXProjector == xProjector) {
return (double)x;
}
}
}
return -1;
}
/* FOR ADAPTIVE!!!!
void GrayCodedBinaryImplementation::processCapture(Mat captureMat) {
experiment->stireCapture(captureMat);
if (benchmark->getIterationIndex() % 2 != 0) {
Mat positiveMat = getCaptureAt(getNumberCaptures() - 2);
Mat negativeMat = getLastCapture();
for (int y = 0; y < benchmark->getCameraHeight(); y++) {
int previousColumnEdgeIndex = -1;
for (int x = 0; x < benchmark->getCameraWidth(); x++) {
Vec3b positivePixelBGR = positiveMat.at<Vec3b>(y, x);
Vec3b negativePixelBGR = negativeMat.at<Vec3b>(y, x);
int positiveColourTotal = (int)positivePixelBGR[0] + (int)positivePixelBGR[1] + (int)positivePixelBGR[2];
int negativeColourTotal = (int)negativePixelBGR[0] + (int)negativePixelBGR[1] + (int)negativePixelBGR[2];
int colourDifference = positiveColourTotal - negativeColourTotal;
int arrayOffset = (y * benchmark->getCameraWidth()) + x;
binaryCode[arrayOffset] <<= 1;
if (colourDifference < BLACK_THRESHOLD) {
binaryCode[arrayOffset] += 1;
} else if (colourDifference > WHITE_THRESHOLD) {
binaryCode[arrayOffset] += 0;
} else {
binaryCode[arrayOffset] = -1;
}
if (binaryCode[arrayOffset] != -1) {
int columnEdgeIndex = convertBinaryToInteger(binaryCode[arrayOffset], numberColumns, NUM_PATTERNS);
if (columnEdgeIndex == previousColumnEdgeIndex + 1) {
}
previousColumnEgdeIndex = columnEdgeIndex;
}
}
}
}
}
*/
int GrayCodedBinaryImplementation::convertGrayCodeToInteger(int grayCodeToConvert, int numberPatterns) {
int result = grayCodeToConvert;
for (int iteration = numberColumns; iteration > 0; iteration /= 2) {
if (iteration < numberPatterns) {
result = result ^ (result >> iteration);
}
}
return result;
}