-
Notifications
You must be signed in to change notification settings - Fork 0
/
KinectUtil.pde
101 lines (88 loc) · 1.88 KB
/
KinectUtil.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
int getLoc(float x, float y, int w) {
return int(x) + int(y) * w;
}
color getColor(color[] px, float x, float y, int w) {
return px[getLoc(x, y, w)];
}
float getZ(color[] px, float x, float y, int w) {
return red(px[getLoc(x, y, w)]) * 2;
}
PVector getPos(PVector[] points, float x, float y, int w) {
return points[getLoc(x, y, w)];
}
float rawDepthToMeters(int depthValue) {
if (depthValue < 2047) {
return (float)(1.0 / ((double)(depthValue) * -0.0030711016 + 3.3309495161));
}
return 0.0;
}
int depth2rgb(short depth) {
int r,g,b;
float v = depth / 2047f;
v = (float) Math.pow(v, 3)* 6;
v = v*6*256;
int pval = Math.round(v);
int lb = pval & 0xff;
switch (pval>>8) {
case 0:
b = 255;
g = 255-lb;
r = 255-lb;
break;
case 1:
b = 255;
g = lb;
r = 0;
break;
case 2:
b = 255-lb;
g = 255;
r = 0;
break;
case 3:
b = 0;
g = 255;
r = lb;
break;
case 4:
b = 0;
g = 255-lb;
r = 255;
break;
case 5:
b = 0;
g = 0;
r = 255-lb;
break;
default:
r = 0;
g = 0;
b = 0;
break;
}
int pixel = (0xFF) << 24
| (b & 0xFF) << 16
| (g & 0xFF) << 8
| (r & 0xFF) << 0;
return pixel;
}
int depth2intensity(short depth) {
int d = Math.round((1 - (depth / 2047f)) * 255f);
int pixel = (0xFF) << 24
| (d & 0xFF) << 16
| (d & 0xFF) << 8
| (d & 0xFF) << 0;
return pixel;
}
double fx_d = 1.0 / 5.9421434211923247e+02;
double fy_d = 1.0 / 5.9104053696870778e+02;
double cx_d = 3.3930780975300314e+02;
double cy_d = 2.4273913761751615e+02;
PVector depthToWorld(int x, int y, float [] depthLookUp, int depthValue) {
PVector result = new PVector();
double depth = depthLookUp[depthValue];
result.x = (float)((x - cx_d) * depth * fx_d);
result.y = (float)((y - cy_d) * depth * fy_d);
result.z = (float)(depth);
return result;
}