最近,我为一个项目从OpenNI2+Nite2混合版本切换到了正式的Kinect SDK。在nite中,我的代码如下:
const nite::Array<nite::UserData>& users = frame.getUsers();
for (int i=0; i<users.getSize(); i++){
const nite::UserData& user = users[i];
if(user.isNew()){/* do this */}
if(user.isLost()){/* do that */}
else {/* update*/}但是,我找不到与Kinect SDK中的isNew & isLost相同的方法。我为isNew实现了自己的方法,但isLost失败了。
// handle user exit
map<string,Group3D*> g3D_copy = g3D;
for(map<string,Group3D*>::iterator mit = g3D_copy.begin();mit != g3D_copy.end();mit++){
if(mit->second->getType() == "KINECT_SKELETON")
{
string groupID = mit->first;
int countExistance2 = 0;
for (int i = 0; i < NUI_SKELETON_COUNT; i++){
int userID = (int)SkeletonFrame.SkeletonData[i].dwTrackingID;
char buffer [33];
sprintf(buffer,"%lu",SkeletonFrame.SkeletonData[i].dwTrackingID);
string myID2 = buffer;
cout << "groupID " << groupID << endl;
cout << "myID2 " << myID2 << endl;
if(myID2 == groupID){ countExistance2++;}
}
// user lost
if(countExistance2 == 0){
delete g3D[groupID];
g3D.erase(groupID);
cout << "*************deleted*******" << endl;
}
}
}最基本的是,如果骨架丢失,我将在每次更新骨架帧时,将专用槽擦除到一个名为g3D的地图中的骨架上。
任何想法或敏锐的眼睛都会受到赞赏。
发布于 2015-03-23 09:26:42
最后,我通过计算没有跟踪骨架的帧来解决这个问题。骨架数据有6个插槽,在某些帧中,它的跟踪id没有设置为NUI_SKELETON_TRACKED。因此,如果空骨架槽的数量超过20 (这意味着appx 3-4连续空帧),我假设用户丢失了。
// handle user exit
// The skeleton is not tracked in every successive frame, so use g3DCounts to count the number of frames
map<string,Group3D*> g3D_copy = g3D;
for(map<string,Group3D*>::iterator mit = g3D_copy.begin();mit != g3D_copy.end();mit++){
if(mit->second->getType() == "KINECT_SKELETON")
{
string groupID = mit->first;
for (int i = 0; i < NUI_SKELETON_COUNT; i++){
char buffer [33];
sprintf(buffer,"%lu",SkeletonFrame.SkeletonData[i].dwTrackingID);
string myID2 = buffer;
if(myID2 == groupID){ g3DCounts[groupID] = 0;}
else{ g3DCounts[groupID] += 1;}
}
if(g3DCounts[groupID] > 20){
delete g3D[groupID];
g3D.erase(groupID);
cout << "*************deleted successfully*******" << endl;
}
}
}希望它能帮助别人
https://stackoverflow.com/questions/29143867
复制相似问题