我在处理中运行以下代码,但我只获得了白色背景!!
import processing.opengl.*;
import SimpleOpenNI.*;
SimpleOpenNI kinect;
import saito.objloader.*;
OBJModel model;
void setup() {
size(1028, 768, OPENGL);
model = new OBJModel(this, "kinect.obj", "relative", TRIANGLES);
model.translateToCenter();
// translate the model so its origin
// is at its left side
BoundingBox box = new BoundingBox(this, model);
model.translate(box.getMin());
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
kinect.enableUser();
kinect.setMirror(true);
}
void draw() {
kinect.update();
background(255);
translate(width/2, height/2, 0);
rotateX(radians(180));
IntVector userList = new IntVector();
kinect.getUsers(userList);
if (userList.size() > 0) {
int userId = userList.get(0);
if ( kinect.isTrackingSkeleton(userId)) {
PVector leftHand = new PVector();
kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_LEFT_HAND, leftHand);
PVector rightHand = new PVector();
kinect.getJointPositionSkeleton(userId,
SimpleOpenNI.SKEL_RIGHT_HAND,
rightHand);
// subtract right from left hand
// to turn leftHand into a vector representing
// the difference between them
leftHand.sub(rightHand);
// convert leftHand to a unit vector
leftHand.normalize();
// model is rotated so "up" is the x-axis
PVector modelOrientation = new PVector(1, 0, 0);
// calculate angle and axis
float angle = acos(modelOrientation.dot(leftHand));
PVector axis = modelOrientation.cross(leftHand);
stroke(255, 0, 0);
strokeWeight(5);
drawSkeleton(userId);
pushMatrix();
lights();
stroke(175);
strokeWeight(1);
fill(250);
translate(rightHand.x, rightHand.y, rightHand.z);
// rotate angle amount around axis
rotate(angle, axis.x, axis.y, axis.z);
model.draw();
popMatrix();
}
}
}
void drawSkeleton(int userId) {
drawLimb(userId, SimpleOpenNI.SKEL_HEAD, SimpleOpenNI.SKEL_NECK);
drawLimb(userId, SimpleOpenNI.SKEL_NECK,SimpleOpenNI.SKEL_LEFT_SHOULDER);
drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER,SimpleOpenNI.SKEL_LEFT_ELBOW);
drawLimb(userId, SimpleOpenNI.SKEL_LEFT_ELBOW,
SimpleOpenNI.SKEL_LEFT_HAND);
drawLimb(userId, SimpleOpenNI.SKEL_NECK,
SimpleOpenNI.SKEL_RIGHT_SHOULDER);
drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER,
SimpleOpenNI.SKEL_RIGHT_ELBOW);
drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_ELBOW,
SimpleOpenNI.SKEL_RIGHT_HAND);
drawLimb(userId, SimpleOpenNI.SKEL_LEFT_SHOULDER,SimpleOpenNI.SKEL_TORSO);
drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_SHOULDER,SimpleOpenNI.SKEL_TORSO);
drawLimb(userId, SimpleOpenNI.SKEL_TORSO,SimpleOpenNI.SKEL_LEFT_HIP);
drawLimb(userId, SimpleOpenNI.SKEL_LEFT_HIP,SimpleOpenNI.SKEL_LEFT_KNEE);
drawLimb(userId, SimpleOpenNI.SKEL_LEFT_KNEE,SimpleOpenNI.SKEL_LEFT_FOOT);
drawLimb(userId, SimpleOpenNI.SKEL_TORSO,SimpleOpenNI.SKEL_RIGHT_HIP);
drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP,SimpleOpenNI.SKEL_RIGHT_KNEE);
drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_KNEE,SimpleOpenNI.SKEL_RIGHT_FOOT);
drawLimb(userId, SimpleOpenNI.SKEL_RIGHT_HIP,SimpleOpenNI.SKEL_LEFT_HIP);
}
void drawLimb(int userId, int jointType1, int jointType2)
{
PVector jointPos1 = new PVector();
PVector jointPos2 = new PVector();
float confidence;
// draw the joint position
confidence = kinect.getJointPositionSkeleton(userId, jointType1, jointPos1);
confidence = kinect.getJointPositionSkeleton(userId, jointType2, jointPos2);
line(jointPos1.x, jointPos1.y, jointPos1.z,jointPos2.x, jointPos2.y, jointPos2.z);
}
// user-tracking callbacks!
void onNewUser(SimpleOpenNI Kinect ,int userId)
{
println("onNewUser - userId: " + userId);
println("\tstart tracking skeleton");
Kinect.startTrackingSkeleton(userId);
}
void onLostUser(SimpleOpenNI Kinect,int userId)
{
println("onLostUser - userId: " + userId);
}
void onVisibleUser(SimpleOpenNI Kinect,int userId)
{
//println("onVisibleUser - userId: " + userId);
}
即时使用处理2.2.1& simpleOpenNI 1.96 这段代码来自“让事情看到”这本书,但我改变了//用户跟踪回调下的最后几行! 因为我在运行原始代码时遇到问题(处理告诉我某些功能不存在),我也改变了(kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL);)到(kinect.enableUser();) 帮助PLZ :)?