I have been working with this code for a bit now and have been struggling to find what gives a specific x and y value for the points on joints or hands. I see that joints.getX() or joints.getY() does do this but it seems to get the values of all the joints and not just one.
this is the code /* Thomas Sanchez Lengeling. http://codigogenerativo.com/
KinectPV2, Kinect for Windows v2 library for processing
Skeleton depth tracking example */
import java.util.ArrayList; import KinectPV2.KJoint; import KinectPV2.*;
KinectPV2 kinect; float r;
void setup() { size(512, 424, P3D);
kinect = new KinectPV2(this);
//Enables depth and Body tracking (mask image) kinect.enableDepthMaskImg(true); kinect.enableSkeletonDepthMap(true);
kinect.init(); }
void draw() { float r = 0; r = r+.1; background(0);
image(kinect.getDepthMaskImage(), 0, 0);
//get the skeletons as an Arraylist of KSkeletons ArrayList skeletonArray = kinect.getSkeletonDepthMap();
//individual joints for (int i = 0; i < skeletonArray.size(); i++) { KSkeleton skeleton = (KSkeleton) skeletonArray.get(i); //if the skeleton is being tracked compute the skleton joints if (skeleton.isTracked()) { KJoint[] joints = skeleton.getJoints();
color col = skeleton.getIndexColor();
fill(col);
stroke(col);
drawBody(joints);
drawHandState(joints[KinectPV2.JointType_HandRight]);
drawHandState(joints[KinectPV2.JointType_HandLeft]);
}
}
fill(255, 0, 0); text(frameRate, 50, 50);
}
//draw the body void drawBody(KJoint[] joints) { drawBone(joints, KinectPV2.JointType_Head, KinectPV2.JointType_Neck); drawBone(joints, KinectPV2.JointType_Neck, KinectPV2.JointType_SpineShoulder); drawBone(joints, KinectPV2.JointType_SpineShoulder, KinectPV2.JointType_SpineMid); drawBone(joints, KinectPV2.JointType_SpineMid, KinectPV2.JointType_SpineBase); drawBone(joints, KinectPV2.JointType_SpineShoulder, KinectPV2.JointType_ShoulderRight); drawBone(joints, KinectPV2.JointType_SpineShoulder, KinectPV2.JointType_ShoulderLeft); drawBone(joints, KinectPV2.JointType_SpineBase, KinectPV2.JointType_HipRight); drawBone(joints, KinectPV2.JointType_SpineBase, KinectPV2.JointType_HipLeft);
// Right Arm drawBone(joints, KinectPV2.JointType_ShoulderRight, KinectPV2.JointType_ElbowRight); drawBone(joints, KinectPV2.JointType_ElbowRight, KinectPV2.JointType_WristRight); drawBone(joints, KinectPV2.JointType_WristRight, KinectPV2.JointType_HandRight); drawBone(joints, KinectPV2.JointType_HandRight, KinectPV2.JointType_HandTipRight); drawBone(joints, KinectPV2.JointType_WristRight, KinectPV2.JointType_ThumbRight);
// Left Arm drawBone(joints, KinectPV2.JointType_ShoulderLeft, KinectPV2.JointType_ElbowLeft); drawBone(joints, KinectPV2.JointType_ElbowLeft, KinectPV2.JointType_WristLeft); drawBone(joints, KinectPV2.JointType_WristLeft, KinectPV2.JointType_HandLeft); drawBone(joints, KinectPV2.JointType_HandLeft, KinectPV2.JointType_HandTipLeft); drawBone(joints, KinectPV2.JointType_WristLeft, KinectPV2.JointType_ThumbLeft);
// Right Leg drawBone(joints, KinectPV2.JointType_HipRight, KinectPV2.JointType_KneeRight); drawBone(joints, KinectPV2.JointType_KneeRight, KinectPV2.JointType_AnkleRight); drawBone(joints, KinectPV2.JointType_AnkleRight, KinectPV2.JointType_FootRight);
// Left Leg drawBone(joints, KinectPV2.JointType_HipLeft, KinectPV2.JointType_KneeLeft); drawBone(joints, KinectPV2.JointType_KneeLeft, KinectPV2.JointType_AnkleLeft); drawBone(joints, KinectPV2.JointType_AnkleLeft, KinectPV2.JointType_FootLeft);
//Single joints drawJoint(joints, KinectPV2.JointType_HandTipLeft); drawJoint(joints, KinectPV2.JointType_HandTipRight); drawJoint(joints, KinectPV2.JointType_FootLeft); drawJoint(joints, KinectPV2.JointType_FootRight);
drawJoint(joints, KinectPV2.JointType_ThumbLeft); drawJoint(joints, KinectPV2.JointType_ThumbRight);
drawJoint(joints, KinectPV2.JointType_Head); }
//draw a single joint void drawJoint(KJoint[] joints, int jointType) { pushMatrix(); translate(joints[jointType].getX(), joints[jointType].getY(), joints[jointType].getZ());
ellipse(0, 0, 25, 25); popMatrix(); }
//draw a bone from two joints void drawBone(KJoint[] joints, int jointType1, int jointType2) { pushMatrix(); translate(joints[jointType1].getX(), joints[jointType1].getY(), joints[jointType1].getZ()); //llipse(0, 0, 25, 25); stroke(0); rectMode(CENTER); r = r+.001; rotate(r); fill(0,0,100); // ellipse(0,0,100,100); noStroke(); //ellipse(0,0,joints[jointType1].getY()/2,joints[jointType1].getX()/2); noStroke();
println(joints[jointType1].getX()); popMatrix(); fill(100,100,100); line(joints[jointType1].getX(), joints[jointType1].getY(), joints[jointType1].getZ(), joints[jointType2].getX(), joints[jointType2].getY(), joints[jointType2].getZ()); }
//draw a ellipse depending on the hand state void drawHandState(KJoint joint) { noStroke(); handState(joint.getState()); pushMatrix();
translate(joint.getX(), joint.getY(), joint.getZ()); ellipse(0, 0, 70, 70); popMatrix(); /* pushMatrix();
float x = joint.getX()/4; float y = joint.getY()/4; float x1 = 500; float y1 = 500; fill(x,20,100); rect(0, 0, width2, 0+y); fill(40,x,100); rect(0,0,0+x,height2); fill(100,20,x); rect (0,height,width*2,0-y); fill(200,x,x); rect (width,0,0-x,2000); //fill(x,50,x);
// ellipse(width/2, height/2, x, x); popMatrix(); */ }
/* Different hand state KinectPV2.HandState_Open KinectPV2.HandState_Closed KinectPV2.HandState_Lasso KinectPV2.HandState_NotTracked */
//Depending on the hand state change the color void handState(int handState) { switch(handState) { case KinectPV2.HandState_Open: fill(0, 255, 0); rect(width/2,height/2,300,300); fill(255,100,0); ellipse(width/2,height/2,40,100); ellipse(width/2,height/2,100,40); break; case KinectPV2.HandState_Closed: fill(255, 0, 0); rectMode(CENTER); pushMatrix(); translate(width/2, height/2); rotate(r); rect(0,0,300,100);
popMatrix();
break;
case KinectPV2.HandState_Lasso: fill(0, 0, 255);
break;
case KinectPV2.HandState_NotTracked: fill(0,200,200); rect(width/2,height/2, 300,300); fill(100, 100, 100); rect(width/2,height/2,200,200);
break;
} }