Wednesday, November 6, 2013

Point Tracking: "YAY! or NAY!" example

///THIS CODE REQUIRES THE KINECT TRACKER CLASS IN A SEPARATE TAB

//upper corner prints "YAAAY!"
// all other corners print "NAAAY!"

// Daniel Shiffman
// Tracking the average location beyond a given depth threshold
// Thanks to Dan O'Sullivan
// http://www.shiffman.net
// https://github.com/shiffman/libfreenect/tree/master/wrappers/java/processing

import org.openkinect.*;
import org.openkinect.processing.*;

// Showing how we can farm all the kinect stuff out to a separate class
KinectTracker tracker;
// Kinect Library object
Kinect kinect;

void setup() {
  size(640, 520);
  kinect = new Kinect(this);
  tracker = new KinectTracker();
  rectMode(CENTER);
}

void draw() {
  background(255);

  // Run the tracking analysis
  tracker.track();
  // Show the image
  tracker.display();

  // Let's draw the raw location
  PVector v1 = tracker.getPos();
  fill(50, 100, 250, 200);
  //noStroke();
  //ellipse(v1.x,v1.y,20,20);

  // Let's draw the "lerped" location
  PVector v2 = tracker.getLerpedPos();
  fill(100, 250, 50, 200);
  //noStroke();
  //ellipse(v2.x,v2.y,20,20);
  stroke(0);
  strokeWeight(5);
  rect(v2.x, v2.y, 30, 30);

  if (v2.x > width/2 && v2.y < height/2) {
   text("YAAAAYYYYYY!", width/2,height/2);
  }else{
    text("NAAAAAAAYYYY!", width/2-100,height/2+100);
  }

  // Display some info
  int t = tracker.getThreshold();
  fill(0);
  text("threshold: " + t + "    " +  "framerate: " + (int)frameRate + "    " + "UP increase threshold, DOWN decrease threshold", 10, 500);
}

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

void stop() {
  tracker.quit();
  super.stop();
}

No comments:

Post a Comment