-
Notifications
You must be signed in to change notification settings - Fork 0
/
KinecTrakin.pde
122 lines (105 loc) · 2.81 KB
/
KinecTrakin.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
// Daniel Shiffman
// Tracking the average location beyond a given depth threshold
// Thanks to Dan O'Sullivan
// https://github.com/shiffman/OpenKinect-for-Processing
// http://shiffman.net/p5/kinect/
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
//objetos
PWindow win;
PWindow win2;
KinectTracker tracker;
Kinect kinect;
float z;
int cellsize = 2; // Dimensions of each cell in the grid
int columns, rows;
PImage img;
boolean flag = false;
void settings() {
size(640, 480,P3D);
}
void setup() {
background(255);
// size(640, 520);
win = new PWindow("hola.jpg");
win2= new PWindow("hola.jpg");
kinect = new Kinect(this);
tracker = new KinectTracker();
img = loadImage("hola.jpg");
columns = img.width / cellsize; // Calculate # of columns
rows = img.height / cellsize; // Calculate # of rows
win.setTraker(tracker);
win2.setTraker(tracker);
win.setDireccion(-100,-100);
win2.setDireccion(-100,100);
}
void draw() {
if(flag==true){
background(1);
tracker.display();
}else{
// Run the tracking analysis
tracker.track();
// background(0);
PVector v1 = tracker.getPos();
fill(0);
noStroke();
ellipse(v1.x, v1.y, 10, 10);
// Let's draw the "lerped" location
PVector v2 = tracker.getLerpedPos();
fill(0);
noStroke();
ellipse(v2.x, v2.y, 10, 10);
// Display some info
int t = tracker.getThreshold();
fill(0);
/*
background(img);
float xt = tracker.positionX();
float yt= tracker.positionY();
win.comunication(yt,xt);
win2.comunication(-yt,-xt);
tracker.track();
//image(img, 0, 0, width, height);
// Begin loop for columns
for ( int i = 0; i < columns; i++) {
// Begin loop for rows
for ( int j = 0; j < rows; j++) {
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*img.width; // Pixel array location
color c = img.pixels[loc]; // Grab the color
// Calculate a z position as a function of mouseX and pixel brightness
float z = (xt / float(width)) * brightness(img.pixels[loc]) - 20.0;
// Translate to the location, set fill and stroke, and draw the rect
pushMatrix();
translate(x, y, z);
fill(c, 204);
noStroke();
rectMode(CENTER);
rect(0, 0, cellsize, cellsize);
popMatrix();
}
}*/
//fin
}
}
// Adjust the threshold with key presses
void keyPressed() {
int t = tracker.getThreshold();
if (key == CODED) {
if (keyCode == UP) {
t += 5;
tracker.setThreshold(t);
} else if (keyCode == DOWN) {
t -= 5;
tracker.setThreshold(t);
} else {
if (keyCode == RIGHT) {
flag = true;
} else {
flag = false;
}
}
}
}