Kinect with processing Trying to use SimpleOpenNI and my code for use with a mouse cursor application
in
Integration and Hardware
•
1 year ago
Hi guys, im using the kinect with SimpleOpenNI through processing, ive managed to get all the skeleton tracking and hand tracking, but my concept is trying to use the hand data as a mouse cursor.
Below is my code, im using a drawSkeleton Class attached to the sketch, this simpy uses a custom regonition/ calibration that ive saved, it pretty much instantly recgonises me and my hand, using a sketch i wrote to save the gesture as a .skel, it works with my much larger house mate aswell. The eclipse is just to show it tracking my hand.
The problem is i cant figure out how to convert the "convertedRightHand.x, convertedRightHand.y" for use with the mouseX, mouseY commands the "convertedRight.." is an int, while mouseX is a float, i cant figure a way to convert the two.
The other is, once achived how would i interactive with the compter as a mouse?
Your Help is apreacited! thank you!
Main sketch
Below is my code, im using a drawSkeleton Class attached to the sketch, this simpy uses a custom regonition/ calibration that ive saved, it pretty much instantly recgonises me and my hand, using a sketch i wrote to save the gesture as a .skel, it works with my much larger house mate aswell. The eclipse is just to show it tracking my hand.
The problem is i cant figure out how to convert the "convertedRightHand.x, convertedRightHand.y" for use with the mouseX, mouseY commands the "convertedRight.." is an int, while mouseX is a float, i cant figure a way to convert the two.
The other is, once achived how would i interactive with the compter as a mouse?
Your Help is apreacited! thank you!
Main sketch
- import SimpleOpenNI.*;
SimpleOpenNI kinect;
int calibratedUserID = 0;
void setup(){
frameRate(30);
size(640, 480);
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
//enable skeleton generation for all joints
kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL);
}
void draw(){
kinect.update();
PImage depth = kinect.depthImage();
image(kinect.depthImage(), 0, 0);
- IntVector userList = new IntVector();
if (kinect.isTrackingSkeleton(calibratedUserID));
drawHands();
// println(frameRate);
}
void onNewUser(int userId) {
println("start pose detection");
if (kinect.loadCalibrationDataSkeleton(userId, "calibration.skel")) {
println("calibration succeeded");
calibratedUserID = userId;
kinect.startTrackingSkeleton(calibratedUserID);
}else{
println("calibration failed!");
}
}
void drawHands(){
int userId = calibratedUserID;
//make a vector to store the left hand
PVector rightHand = new PVector();
//put the position of the left hand into the vector
float confidence = kinect.getJointPositionSkeleton(userId,- SimpleOpenNI.SKEL_LEFT_HAND, rightHand);
//convert the detected hand postion, to projective co-ords, that match the depth image
PVector convertedRightHand = new PVector();
kinect.convertRealWorldToProjective(rightHand, convertedRightHand);
//display it
fill(255,0,0);
ellipse(convertedRightHand.x, convertedRightHand.y, 10, 10);
}
DrawSkeleton Class
- class DrawSkeleton {
SimpleOpenNI context;
void drawSkeleton(int userId){
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_HEAD,
SimpleOpenNI.SKEL_NECK);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_NECK,
SimpleOpenNI.SKEL_LEFT_SHOULDER);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_LEFT_SHOULDER,
SimpleOpenNI.SKEL_LEFT_ELBOW);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_LEFT_ELBOW,
SimpleOpenNI.SKEL_LEFT_HAND);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_NECK,
SimpleOpenNI.SKEL_RIGHT_SHOULDER);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_RIGHT_SHOULDER,
SimpleOpenNI.SKEL_RIGHT_ELBOW);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_RIGHT_ELBOW,
SimpleOpenNI.SKEL_RIGHT_HAND);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_LEFT_SHOULDER,
SimpleOpenNI.SKEL_TORSO);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_RIGHT_SHOULDER,
SimpleOpenNI.SKEL_TORSO);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_TORSO,
SimpleOpenNI.SKEL_LEFT_HIP);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_LEFT_HIP,
SimpleOpenNI.SKEL_LEFT_KNEE);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_LEFT_KNEE,
SimpleOpenNI.SKEL_LEFT_FOOT);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_TORSO,
SimpleOpenNI.SKEL_RIGHT_HIP);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_RIGHT_HIP,
SimpleOpenNI.SKEL_RIGHT_KNEE);
kinect.drawLimb(userId,
SimpleOpenNI.SKEL_RIGHT_KNEE,
SimpleOpenNI.SKEL_RIGHT_FOOT);
}
}
1