-
Notifications
You must be signed in to change notification settings - Fork 0
/
calibration.pde
222 lines (167 loc) · 6.33 KB
/
calibration.pde
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
void calbration(){
if(calibrationPhase == 1){
futhestDepth = getFuthestDepth(futhestDepth,depthImgScaled);
futhestDepth = fillInMissingPixXConvergence(futhestDepth);
calibrationPhase++;
image(futhestDepth,futhestDepth.width*2,0);
}else if(calibrationPhase == 2){
stroke(255,0,0);
image(kinect2.getRegisteredImage(),0,0);
fill(255,100);
rect(0,0,kinect2.depthWidth,tipFocuseAreaTop);
fill(255,100);
rect(0,tipFocuseAreaBottom, kinect2.depthWidth,kinect2.depthHeight-tipFocuseAreaBottom);
//tipTopPoint=200;
//tipBottomPoint =400;
}else if(calibrationPhase == 3){
//if(keyPressed){
// if(key == 'l'){
// leftCrop = mouseX;
// }else if(key == 'r'){
// rightCrop = mouseX;
// }else if(key == 't'){
// offsetTop = mouseY;
// }else if(key == 'b'){
// offsetBottom = height-mouseY;
// }
//}
pushStyle();
stroke(255,0,0);
fill(255);
strokeWeight(4);
rect(leftCrop,offsetTop,rightCrop-leftCrop,height-offsetTop-offsetBottom);
image(kinect2.getRegisteredImage(),50,height-kinect2.getRegisteredImage().height);
popStyle();
}else if(calibrationPhase == 4){
//ellipse(300,300,300,300);
//pointsGraphic=createGraphics(wScreen, hScreen);
//calibrationGraphic=createGraphics(width, height);
displayCalibrationPoint();
//calibrationGraphic.beginDraw();
//calibrationGraphic.beginDraw();
//calibrationGraphic.background(0,255,0);
//calibrationGraphic.ellipse(512/2+100,424/2,50,50);
//calibrationGraphic.endDraw();
image(calibrationGraphic, 0,0,width, height);
//myScreen.display();
//PGraphics testG=createGraphics(512, 424);
//testG.beginDraw();
//testG.fill(255,0,0);
//testG.ellipse(512/2,424/2,50,50);
//testG.beginDraw();
//if(millis()%1000<3){
// println("should draw");
//}
}
}
//compaiers 2 images findes the furthere (brighter point)
//for added relaability I could use some easing or verification of surrounding points so that random noise that apease far away is not calibrated towards
PImage getFuthestDepth(PImage imgA, PImage imgB){
PImage brighterImage = new PImage(imgA.width,imgA.height);
brighterImage.loadPixels();
imgA.loadPixels();
imgB.loadPixels();
//println(imgA.width + ", " + imgA.height + " : " + imgB.width + ", " + imgB.height);
for(int i =0;i<imgA.pixels.length; i++){
if(brightness(imgA.pixels[i])<brightness(imgB.pixels[i])){
brighterImage.pixels[i]=imgB.pixels[i];
}else{
brighterImage.pixels[i]=imgA.pixels[i];
}
}
//image(brighterImage, 512*2, 0);
return brighterImage;
}
PImage getMovingDepth(PImage imgCur, PImage imgBackground, PImage registeredImage){
//println(imgCur.height + " : " + imgBackground.height + " : " + registeredImage.height + " : ");
PImage movingImage = new PImage(imgCur.width,imgBackground.height);
movingImage.loadPixels();
imgCur.loadPixels();
imgBackground.loadPixels();
registeredImage.loadPixels();
float depthDiff;
//image(imgBackground,imgBackground.width,0);
//image(imgCur,imgCur.width,imgCur.height);
for(int i =0;i<imgCur.pixels.length; i++){
depthDiff = brightness(imgBackground.pixels[i])-brightness(imgCur.pixels[i]);
if(depthDiff>deltaDepth ){
movingImage.pixels[i]=registeredImage.pixels[i];
//if(brightness(movingImage.pixels[i])==0){
// movingImage.pixels[i]=color(0,0);
//}
}
//??
//if(brightness(movingImage.pixels[i])<20){
// movingImage.pixels[i]=color(0,0);
//}
}
//image(movingImage,movingImage.width,0);
//textSize(35);
//for(int i =0;i<imgCur.pixels.length; i++){
// if(brightness(movingImage.pixels[i])<20){
// movingImage.pixels[i]=color(0,0);
// }
//}
//image(movingImage,512*1,424);
return movingImage;
}
int calibrationPointSize=15;
void displayCalibrationPoint() {
calibrationGraphic.beginDraw();
calibrationGraphic.strokeWeight(7);
calibrationGraphic.stroke(0,0,255);
calibrationGraphic.fill(0,0,255);
calibrationGraphic.clear();
//calibrationGraphic.background(255,0,0);
//println(calibrationGraphic.width);
//calibrationGraphic.rect(width/2,height/2,50,50);
//calibrationGraphic.stroke(255);
//int xPossition=width-height*calibrationCountW/numCalibrationPointsW-leftCrop;
//int yPossition=(height)*calibrationCountH/numCalibrationPointsH+offsetTop;
int widthDrawArea=rightCrop - leftCrop;
int heightDrawArea=height - offsetTop - offsetBottom;
int xPossition = widthDrawArea*calibrationCountW/(numCalibrationPointsW-1) + leftCrop;
int yPossition=heightDrawArea*calibrationCountH/(numCalibrationPointsH-1)+offsetTop;
calibrationGraphic.ellipse(xPossition, yPossition, 15, 15);
//calibrationGraphic.stroke(0,0,255);
calibrationGraphic.noFill();
calibrationGraphic.ellipse(xPossition, yPossition, calibrationPointSize, calibrationPointSize);
if (calibrationPointSize>15) {
calibrationPointSize-=1;
} else {
calibrationPointSize=150;
}
calibrationGraphic.endDraw();
}
PImage fillInMissingPixXConvergence(PImage image_){
image_.loadPixels();
float congergenceThreshhold=.1;
float congergence = 1000;
PImage snapshot = image_.copy();
snapshot.loadPixels();
while(congergence>congergenceThreshhold){
congergence=0;
//wont fill in deges
for(int i=1;i<image_.width-1;i++){
for(int j=1;j<image_.height-1;j++){
int index = i+j*image_.width;
if(brightness(snapshot.pixels[index])==0){
float brightnessLeft=brightness(image_.pixels[index-1]);
float brightnessRight=brightness(image_.pixels[index+1]);
color newColor;
if( brightnessLeft!=0 && brightnessRight != 0){
newColor=color((brightnessLeft+brightnessRight)/2);
}else if(brightnessLeft!=0 || brightnessRight != 0){
//dont divide by 2;
newColor=color((brightnessLeft+brightnessRight));
}else{
newColor=image_.pixels[index];
}
congergence += abs(brightness(newColor)-brightness(image_.pixels[index]));
image_.pixels[index]=newColor;
}
}
}
}
return image_;
}