Created
January 20, 2014 23:33
-
-
Save kitschpatrol/8531530 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; | |
| int v1lastTime; | |
| PVector v1lastPosition; | |
| float velocity; | |
| void setup() { | |
| size(640,520); | |
| kinect = new Kinect(this); | |
| tracker = new KinectTracker(); | |
| // Initialize... | |
| v1lastTime = 0; | |
| velocity = 0; | |
| v1lastPosition = PVector(0, 0, 0); | |
| } | |
| 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); | |
| // NEW | |
| // Calculate velocity | |
| if (v1LastTime != 0) { | |
| int elapsedTime = millis() - v1LastTime; | |
| // Velocity is distance over time... | |
| velocity = PVector.dist(v1, v1lastPosition) / elapsedTime; | |
| println("Velocity: " + velocity); | |
| } | |
| // Save for next frame | |
| v1LastTime = millis(); | |
| v1lastPosition = v1.get(); | |
| // Let's draw the "lerped" location | |
| PVector v2 = tracker.getLerpedPos(); | |
| fill(100,250,50,200); | |
| noStroke(); | |
| ellipse(v2.x,v2.y,20,20); | |
| // 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(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment