-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathKinectTrackAveAtADepth
63 lines (55 loc) · 1.44 KB
/
KinectTrackAveAtADepth
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
import SimpleOpenNI.*;
//you have to install SimpleOpenNI Library
//on a mac only works with old kinect and 1414 firmware
SimpleOpenNI context;
int aveX;
int aveY;
int threshold = 700;
void setup() {
// startup the kinnect
size(640, 480);
context = new SimpleOpenNI(this);
context.enableDepth();
}
void draw() {
background(255);
loadPixels();
//listne to the kinect
context.update();
int[ ] allDepths = new int[640*480];
context.depthMap(allDepths );
//what is the x y of the closes pixel to the camera
int pointsWithInThreshold = 0;
int sumX = 0;
int sumY = 0;
for (int row = 0; row < 480; row++) {
for (int col = 0; col < 640; col++) {
int placeInBigArray = row*640 + col;
if (allDepths[placeInBigArray] < threshold && allDepths[placeInBigArray] != 0 ) {
sumX = sumX + col;
sumY = sumY + row;
pointsWithInThreshold++;
//mark all the qualifying pixels with black
//adjust threshold until only the ones you want are black
pixels[placeInBigArray] = color(0,0,0);
}
}
}
// PImage myImg = context.depthImage();
//image(myImg, 0, 0);
if (pointsWithInThreshold > 0){
aveX = sumX/pointsWithInThreshold;
aveY = sumY/pointsWithInThreshold;
updatePixels();
fill(255, 0, 0);
ellipse(aveX, aveY, 20, 20);
}
}
void keyPressed(){
if (key == 't'){
threshold--;
}else if (key == 'T'){
threshold++;
}
println("Threshold " + threshold);
}