Take the 2-minute tour ×

not very familiar with c++, but i'm trying to send some data to a java/processing sketch. The problem is I don't know how the user count is for Open Frameworks ofxOpenNI. I want to count as much as 3 users thru my kinect camera. Calculate an average of each user and send the data to my processing sketch for further use.

The problem is, that I get an infinity number of the second user sometimes. Could someone tell me why?

Using the OpenNISample007.xcodeproj

I've adapted this into the script:

        if (isMasking) drawMasks();
        for (int i=1; i< recordUser.getNumberOfTrackedUsers()+1; i++){
        if (isCloud) drawPointCloud(&recordUser, i);    // 0 gives you all point clouds; use userID to see point clouds for specific users

then I use the pointCloud information to send an average thru OSC

 float  positionsX ;
float positionsBegin;
int counter = 0;
        ofPoint pos = user_generator->getWorldCoordinateAt(x, y, userID);
        if (pos.z == 0 && isCPBkgnd) continue;  // gets rid of background -> still a bit weird if userID > 0...
        ofColor color = user_generator->getWorldColorAt(x,y, userID);
    //  glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a);
        glVertex3f(pos.x, pos.y, pos.z);

        if (x == 1){

            positionsBegin = pos.x;


float average = positionsX/counter;


ofxOscMessage m;
m.setAddress( "/persons" );
m.addIntArg( userID );


sender.sendMessage( m );
share|improve this question
add comment

1 Answer

As far as I can understand you're looping through each user's pixel and trying to get to the centre ? If you've got the user's you can use the getCoM() method to get the each user's centre of mass, so you wouldn't need to loop through user pixels:

float positionX = 0;
int numUsers = user_generator.getNumberOfTrackedUsers();
for(int i = 0 ; i < numUsers; i++){
  XnPoint3D userPos;
  user_generator.getXnUserGenerator().GetCoM(i, userPos);
  positionX += userPos.X;
positionX /= numUsers;

Note that this will give you the coordinates in 3D space. If you want position on screen you'd need to convert the coordinates using ConvertRealWorldToProjective

Not sure if it helps, but you could do this directly in Processing using SimpleOpenNI

share|improve this answer
add comment

Your Answer


