Monday, January 27, 2014

Appointment with Yee xiang on 26th at bandar sunway

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);
    }
  }
}

Tuesday, January 21, 2014

Appointment with Yee siang on monday

During the appointment on monday, we had successfully link the openkinect code with the gradient to archived the very similar effect. But another accident happened again, after the tutorial section i was being robe at ss15 after finished the tutorial session.
My kinect camera, macbook had being robe. All the file i had done is gone and i need to start all over with sketch. I am a little bit lucky because Yee Xiang having the previous 2 week backup file so the things i need is to rush back the 2 week progress. 



So luckily am i, After i brought a new computer and kinect camera.
Yee Xiang arrange an additional tutorial session on 26th Jan in order for keeping me on the track.

Saturday, January 18, 2014

Appointment with Yee Xiang tutorial session

Everythings seems so smooth until i have another incident occure, my company lorry that being hijacked last month been found in Selangor, i need to attend police station and the court to reclaim back my lorry. So i sent a request to my guest lecturer to replacing my tutorial session on monday 20th Jan 2014.


Wednesday, January 15, 2014

During the study break

During the study break, i had found a tutorial that using processing gradient to make the whole visual came out,

Reference:
http://forum.processing.org/two/discussion/150/gradient-color-effect/p1

PImage gradientMap; // This PImage object will hold the gradient
float progress = 0; // The progress variable, a float from 0.0 to 1.0
 
// Initiate sketch
void setup() {
 
    // Set screen size and renderer
    size(200, 720, P2D);
    noStroke();
 
    // Define as much colors as you like
    color[] colors = new color[] { color(255, 0, 0), color(255, 255, 0), color(0, 255, 0), color(0, 0, 255) };
 
    // Create gradient map from the given colors
    gradientMap = createImage(1, colors.length, RGB);
    gradientMap.loadPixels();
    for(int n = 0; n < colors.length; n++)
    gradientMap.pixels[n] = colors[n];
    gradientMap.updatePixels();
 
}
 
// Render sketch
void draw() {
 
    // Fill background
    background(#d1d1d1);
 
    // Calculate progress
    progress += 0.002;
    if(progress > 1)
        progress = 1;
 
    // Calculate gradient position
    float y = height - height * progress;
    float u = gradientMap.height * progress;
 
    // Render gradient
    beginShape(QUADS);
    texture(gradientMap);
    vertex(70, y, 0, u);
    vertex(120, y, 1, u);
    vertex(120, height, 0, 0);
    vertex(70, height, 1, 0);
    endShape();

}


I decided to make my own gradient according the code above with different variation of color. therefore i come out with my own code and adjusting the color according the hue color code i get from photoshop

The gradient i had done with another .pde file that can linked with the open kinect to generate the color



 class Gradient { ArrayList colors; Gradient() { colors = new ArrayList(); } void addColor(color c) { colors.add(c); } color getGradient(float value) { if(colors.size() == 0) return #000000; if(value <= 0.0) return (color)(Integer) colors.get(0); if(value >= colors.size() - 1) return (color)(Integer) colors.get(colors.size() - 1); int color_index = (int)value; color c1 = (color)(Integer) colors.get(color_index); color c2 = (color)(Integer) colors.get(color_index + 1); return lerpColor(c1, c2, value - color_index); } }