We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello Guys, I am wondering how can i get the x position of the average point tracking on openkinect lib so as to control servos on a arduino. I am using processing 3, i didn't find any tuto about it, and i'm a novice at it. Here's the code // 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.*;
// The kinect stuff is happening in another class
KinectTracker tracker;
Kinect kinect;
void setup() {
size(640, 520);
kinect = new Kinect(this);
tracker = new KinectTracker();
}
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);
// Display some info
int t = tracker.getThreshold();
fill(0);
text("threshold: " + t + " " + "framerate: " + int(frameRate) + " " +
"UP increase threshold, DOWN decrease threshold", 10, 500);
}
// 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);
}
}
}
In a second time i definitely need your help to link processing and arduino. Cheers guys !
Answers
You miss the most important file, is the one called KinectTracker.
` // 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/
class KinectTracker {
// Depth threshold int threshold = 745;
// Raw location PVector loc;
// Interpolated location PVector lerpedLoc;
// Depth data int[] depth;
// What we'll show the user PImage display;
KinectTracker() { // This is an awkard use of a global variable here // But doing it this way for simplicity kinect.initDepth(); //kinect.enableMirror(true); // Make a blank image display = createImage(kinect.width, kinect.height, RGB); // Set up the vectors loc = new PVector(0, 0); lerpedLoc = new PVector(0, 0); }
void track() { // Get the raw depth as array of integers depth = kinect.getRawDepth();
}
PVector getLerpedPos() { return lerpedLoc; }
PVector getPos() { return loc; }
void display() { PImage img = kinect.getDepthImage();
}
int getThreshold() { return threshold; }
void setThreshold(int t) { threshold = t; } }`
Here is the most important part.