schonfeld / simple-openni

Automatically exported from code.google.com/p/simple-openni
0 stars 0 forks source link

problem the output is white bachground processing&kinect #113

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
im running the following code in processing but i only get a white background!!
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);
}
im using processing 2.2.1 & simpleOpenNI 1.96
help plz :) ?

Original issue reported on code.google.com by EsraS...@gmail.com on 8 Apr 2015 at 6:42