-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathKinectRecord
More file actions
76 lines (65 loc) · 1.91 KB
/
KinectRecord
File metadata and controls
76 lines (65 loc) · 1.91 KB
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
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
Kinect2 kinect;
int depthThreshold = 1400;
boolean recording = false;
float recordingThreshold = .2;
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;
float qualifyingPixelCount = 0;
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 < depthThreshold ) {
qualifyingPixelCount++;
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);
float percentQualifying = qualifyingPixelCount/depth.length;
if (recording || percentQualifying > recordingThreshold) {
println("Recording" + random(0,1));
saveFrame("line-######.png");
}
}
void mousePressed(){
recording = ! recording;
}
// Adjust the threshold with key presses
void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
depthThreshold ++;
} else if (keyCode == DOWN) {
depthThreshold --;
}
}else if( key == 'r'){
recordingThreshold += .1;
}else if (key == 'R'){
recordingThreshold += .1;
}
println(depthThreshold, recordingThreshold );
}