Hi,
I am trying to create a program that draws a line by skeleton tracking a user’s right hand, similar to a painting program. I have managed to get this to work with non-skeleton hand tracking, but would like to be able to assign different tasks to each hand, therefore would like to be able to use skeleton tracking instead.
I am trying to use a strategy of currentRightHand, lastRightHand. However, I have had a great amount of trouble figuring out how to identify the first “lastRightHand” coordinates. As the program is now, lastRightHand keeps resetting at (0,0) on each iteration. However, until establishing the variable like this, I kept getting a nullPointerException. Ideally, I would like first instance of lastRightHand to be set at the first location the Kinect reads from the skeleton. I have not been successful in this.
I am sure there is a simple solution to this. I am very new to programming and am still trying to accustom myself to the problem-solving patterns. I would really appreciate any insight that you guys can give me. Code below.
import SimpleOpenNI.*;
import processing.opengl.*;
SimpleOpenNI kinect;
//declare global variables
PVector lastRightHand = new PVector();
void setup(){
size(640, 480, OPENGL);
kinect = new SimpleOpenNI(this);
kinect.setMirror(true);
kinect.enableDepth();
kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL);
//line color and weight
stroke(255, 0, 0);
strokeWeight(30);
background(0);
}
void draw(){
kinect.update();
//tracking
IntVector userList = new IntVector();
kinect.getUsers(userList);
if(userList.size() > 0){
int userId = userList.get(0);
if(kinect.isTrackingSkeleton(userId)){
PVector currentRightHand = new PVector();
float confidence = kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_RIGHT_HAND, currentRightHand);
//track hand and draw line
line(lastRightHand.x, lastRightHand.y, currentRightHand.x,
currentRightHand.y);
lastRightHand = currentRightHand;
}
}
}
//user-tracking callbacks!
void onNewUser(int userId) {
println("start poser detection");
kinect.startPoseDetection("Psi", userId);
}
void onEndCalibration(int userId, boolean successful) {
if (successful) {
println("user calibrated!!!");
kinect.startTrackingSkeleton(userId);
}
else {
println("failed to calibrate user!!!");
kinect.startPoseDetection("Psi", userId);
}
}
void onStartPose(String pose, int userId) {
println("Started pose for user");
kinect.stopPoseDetection(userId);
kinect.requestCalibrationSkeleton(userId, true);
}