OpenNi user tracking PLEAS HELP :(
in
Contributed Library Questions
•
1 year ago
Hi, i'm trying the SimpleOpenni library right now. I already tried the same thing in Open Frameworks, but after a while it just stops detecting users. What can i do to fix this? Can i somehow reset it?
I'm standing here waiting it to work correctly. Sometimes the point just hangs. Sometimes it sends a 0 value thru oscP5.
I'm using this example:
http://simple-openni.googlecode.com/svn-history/r211/trunk/SimpleOpenNI/dist/all/SimpleOpenNI/examples/SimpleOpenNI_UserScene3d/SimpleOpenNI_UserScene3d.pde
Here's my code:
- void setup()
- {
- size(1024,768,P3D); // strange, get drawing error in the cameraFrustum if i use P3D, in opengl there is no problem
- context = new SimpleOpenNI(this);
- // disable mirror
- context.setMirror(false);
- // enable depthMap generation
- context.enableDepth();
- // enable skeleton generation for all joints
- context.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL);
- // enable the scene, to get the floor
- context.enableScene();
- stroke(255,255,255);
- smooth();
- perspective(radians(45),
- float(width)/float(height),
- 10,150000);
- /* start oscP5, listening for incoming messages at port 12000 */
- oscP5 = new OscP5("127.0.0.1", 12001);
- /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
- * an ip address and a port number. myRemoteLocation is used as parameter in
- * oscP5.send() when sending osc packets to another computer, device,
- * application. usage see below. for testing purposes the listening port
- * and the port of the remote location address are the same, hence you will
- * send messages back to this sketch.
- */
- myRemoteLocation = new NetAddress("127.0.0.1", 12000);
- }
- void draw()
- {
- // update the cam
- context.update();
- background(0,0,0);
- // set the scene pos
- translate(width/2, height/2, 0);
- rotateX(rotX);
- rotateY(rotY);
- scale(zoomF);
- int[] depthMap = context.depthMap();
- int steps = 3; // to speed up the drawing, draw every third point
- int index;
- PVector realWorldPoint;
- translate(0,0,-1000); // set the rotation center of the scene 1000 infront of the camera
- int userCount = context.getNumberOfUsers();
- int[] userMap = null;
- if(userCount > 0)
- {
- userMap = context.getUsersPixels(SimpleOpenNI.USERS_ALL);
- }
- for(int y=0;y < context.depthHeight();y+=steps)
- {
- for(int x=0;x < context.depthWidth();x+=steps)
- {
- index = x + y * context.depthWidth();
- if(depthMap[index] > 0)
- {
- // get the realworld points
- realWorldPoint = context.depthMapRealWorld()[index];
- if(realWorldPoint.z <900){
- // check if there is a user
- if(userMap != null && userMap[index] != 0)
- { // calc the user color
- int colorIndex = userMap[index] % userColors.length;
- stroke(userColors[colorIndex]);
- }
- // else
- // default color
- // stroke(100);
- // pushMatrix();
- // translate(realWorldPoint.x,realWorldPoint.y,realWorldPoint.z);
- // fill(0,0,255);
- // stroke(0,0,255);
- // ellipse(0,0,50,50);
- // popMatrix();
- // point(realWorldPoint.x,realWorldPoint.y,realWorldPoint.z);
- }}
- }
- }
- // draw the center of mass
- PVector pos = new PVector();
- pushStyle();
- strokeWeight(15);
- for(int userId=1;userId <= userCount;userId++)
- {
- context.getCoM(userId,pos);
- stroke(userCoMColors[userId % userCoMColors.length]);
- /* create a new OscMessage with an address pattern, in this case /test. */
- OscMessage myOscMessage = new OscMessage("/persons");
- if(pos.z <3000){
- myOscMessage.add(userId);
- println(pos.x);
- /* add a value (an integer) to the OscMessage */
- myOscMessage.add(int(pos.x));
- /* send the OscMessage to a remote location specified in myNetAddress */
- oscP5.send(myOscMessage, myRemoteLocation);
- println(pos.z);
- pushMatrix();
- translate(pos.x,pos.y,pos.z);
- fill(0,255,0);
- stroke(0,255,0);
- ellipse(0,0,50,50);
- popMatrix();
- // println("userID : "+userId);
- // println("userposition : "+pos.x);
- // point(pos.x,pos.y,pos.z);
- }}
- popStyle();
- /*
- // draw the floor
- PVector floorCenter = new PVector();
- PVector floorNormal = new PVector();
- PVector floorEnd = new PVector();
- context.getSceneFloor(floorCenter,floorNormal);
- floorEnd = PVector.add(floorCenter,PVector.mult(floorNormal,1000));
- println(floorCenter + " - " + floorEnd);
- pushStyle();
- strokeWeight(8);
- stroke(0,255,255);
- line(floorCenter.x,floorCenter.y,floorCenter.z,
- floorEnd.x,floorEnd.y,floorEnd.z);
- stroke(0,255,100);
- line(floorEnd.x,floorEnd.y,floorEnd.z,
- 0,0,0);
- popStyle();
- */
- // draw the kinect cam
- context.drawCamFrustum();
- }
- void OSCSETUP() {
- /* start oscP5, listening for incoming messages at port 12000 */
- oscP5 = new OscP5(this,12000);
- /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
- * an ip address and a port number. myRemoteLocation is used as parameter in
- * oscP5.send() when sending osc packets to another computer, device,
- * application. usage see below. for testing purposes the listening port
- * and the port of the remote location address are the same, hence you will
- * send messages back to this sketch.
- */
- myRemoteLocation = new NetAddress("127.0.0.1",12001);
- }
- int[] userDetection = new int[10];
- /* incoming osc message are forwarded to the oscEvent method. */
- void oscEvent(OscMessage theOscMessage) {
- /* print the address pattern and the typetag of the received OscMessage */
- print("### received an osc message.");
- print(" addrpattern: "+theOscMessage.addrPattern());
- println(" typetag: "+theOscMessage.typetag());
- if (theOscMessage.checkAddrPattern("/amount")==true) {
- int userValue = theOscMessage.get(0).intValue();
- userDetection = new int[userValue];
- }
- if (theOscMessage.checkAddrPattern("/persons")==true) {
- int userValue = theOscMessage.get(0).intValue();
- println("hoeveelheid: " + userValue);
- println("variabel: " + theOscMessage.get(1).intValue());
- userDetection[userValue] = theOscMessage.get(1).intValue();
- }
- }
1