The problem in the coding is the kinect camera size was different with the screen resolution. The kinect camera only support 480 x 640 screen resolution and i couldn't do anythings with adjusting the resolution. Any figure above this size will crashing the processing application.
In the total of 6 hour tutorial session on monday,
We had take an option to decrease the project resolution size to make the application wont crash in the middle. Another problem i had solve today is linking the openkinect code, average track point to the gradient preview.
inorder not crashing the processing i had change the size of the pixel to "ssizew & ssizeH" to represent the hight and width of the screen.
void setup() {
size(ssizeW, ssizeH);
kinect = new Kinect(this);
tracker = new KinectTracker();
g = new Gradient();
g.addColor(color(0, 0, 0));
g.addColor(color(102, 0, 102));
g.addColor(color(0, 144, 255));
g.addColor(color(0, 255, 207));
g.addColor(color(51, 204, 102));
g.addColor(color(111, 255, 0));
g.addColor(color(191, 255, 0));
g.addColor(color(255, 240, 0));
g.addColor(color(255, 153, 102));
g.addColor(color(204, 51, 0));
g.addColor(color(153, 0, 0));
What i do to link the gradient with the openkinet is changing the library
apply_heat(mouseX, mouseY, 15, -.25);
to
apply_heat(x, y, 15, -.25);
that represent the kinect tracking space to triggle it.
Beside, i had done the calculation for the color for threshold in kinect for length calibration.
int t = tracker.getThreshold();
fill(255);
text("threshold: " + t + " " + "framerate: " + (int)frameRate + " " + "UP increase threshold, DOWN decrease threshold",10,470);
}
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);
}
}
}
Beside, i also come out with the calculation that can make the visual more smooth
float calc_pixel(int i, int j)
{
float total = 0.0;
int count = 0;
for(int ii = -1; ii < 2; ii++)
{
for(int jj = -1; jj < 2; jj++)
{
if(i + ii < 0 || i + ii >= width || j + jj < 0 || j + jj >= height)
continue;
count++;
total += heatmap[index][i + ii][j + jj];
}
}
return total / count;
}
void apply_heat(int i, int j, int r, float delta)
{
for(int ii = -(r / 2); ii < (r / 2); ii++)
{
for(int jj = -(r / 2); jj < (r / 2); jj++)
{
if(i + ii < 0 || i + ii >= width || j + jj < 0 || j + jj >= height)
continue;
heatmap[index][i + ii][j + jj] += delta;
heatmap[index][i + ii][j + jj] = constrain(heatmap[index][i + ii][j + jj], 0.0, 20.0);
}
}
}