2011-12-24 10 views
0

C++に詳しいことはありませんが、Java /処理スケッチにデータを送信しようとしています。問題は、OpenFrame forxOpenNIのユーザー数がどのようになっているのか分かりません。私はkinectカメラを通して3人のユーザーを数えたいと思う。各ユーザーの平均を計算し、さらに使用するためにデータを処理スケッチに送信します。OSNを使ってユーザーをカウントしてデータを送信するOpenNI

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

 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 
     } 

は、私が知る限り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); 

答えて

0

を通して平均を送信するためにpointCloud情報を使用します。私はスクリプトにこれを適応してきたOpenNISample007.xcodeproj

を使用して

私はあなたが各ユーザーのピクセルをループしていて、中心に到達しようとしていることを理解できますか? あなたは、ユーザーの使用すると、ユーザーのピクセルをループする必要はありませんので、あなたは、質量の各ユーザーの中心部を得るために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

を用いた処理で直接これを行うことができます
関連する問題