-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathGreenScreenV2
59 lines (48 loc) · 1.36 KB
/
GreenScreenV2
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
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
Kinect2 kinect;
int threshold = 1400;
PImage foreGround;
void setup() {
size(500, 500 );
kinect = new Kinect2(this);
kinect.initVideo();
kinect.initDepth();
kinect.initRegistered();
kinect.initDevice();
foreGround = new PImage(kinect.depthWidth, kinect.depthHeight, ARGB);
}
void draw() {
//if the kinect has not warmed up yet bail, bug?
background(0);
PImage colorPicture = kinect.getRegisteredImage(); //kinect.getVideoImage();
//ask kinect for an array of depth pixels
int[] depth = kinect.getRawDepth();
if (depth == null) return;
foreGround.loadPixels();
for (int row = 0; row < kinect.depthHeight; row++) {
for (int col = 0; col< kinect.depthWidth; col++) {
int offset = col + row*kinect.depthWidth;
// Grabbing the raw depth
int rawDepth = depth[offset];
if (rawDepth > 0 && rawDepth < threshold) {
foreGround .pixels[offset] = colorPicture.pixels[offset];
} else {
foreGround .pixels[offset] = color(0, 0, 0, 0);
}
}
}
//paint the color image on the screen
foreGround.updatePixels();
image(foreGround, 0, 0);
}
// Adjust the threshold with key presses
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
threshold++;
} else if (keyCode == DOWN) {
threshold--;
}
}
}