0

C++ にはあまり詳しくありませんが、データを Java/Processing スケッチに送信しようとしています。問題は、xOpenNI のオープン フレームワークのユーザー数がわからないことです。kinect カメラを通して最大 3 人のユーザーを数えたいと考えています。各ユーザーの平均を計算し、さらに使用するためにデータを処理スケッチに送信します。

問題は、時々 2 番目のユーザーの数が無限になることです。誰かが理由を教えてもらえますか?

OpenNISample007.xcodeproj の使用

これをスクリプトに適応させました:

        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
        }

次に、pointCloud 情報を使用して、OSC を介して平均を送信します。

 float  positionsX ;
float positionsBegin;
int counter = 0;
for(int y = 0; y < h; y += step) {
    for(int x = 0; x < w; x += step) {
        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);

        positionsX+=pos.x;
        if (x == 1){

            positionsBegin = pos.x;
        }
        counter++;


    }
}


float average = positionsX/counter;

cout<<"Average:"<<average<<endl;
//cout<<"positionsBegin:"<<positionsBegin<<endl;



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

m.addFloatArg(average);


sender.sendMessage( m );
4

1 に答える 1

0

私が理解できる限り、あなたは各ユーザーのピクセルをループして中心に到達しようとしていますか?ユーザーを取得している場合は、getCoM()メソッドを使用して各ユーザーの重心を取得できるため、ユーザーのピクセルをループする必要はありません。

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;

これにより、3D空間の座標が得られることに注意してください。画面上の位置が必要な場合は、ConvertRealWorldToProjectiveを使用して座標を変換する必要があります

それが役立つかどうかはわかりませんが、 SimpleOpenNIを使用した処理で直接行うことができます

于 2012-08-05T11:17:10.400 に答える