【问题标题】:OpenNI2+Nite2 isNew() isLost() methods in Kinect SDKKinect SDK 中的 OpenNI2+Nite2 isNew() isLost() 方法
【发布时间】:2015-05-11 20:22:05
【问题描述】:

我最近为一个项目从 OpenNI2+Nite2 配置切换到官方 Kinect SDK。在晚上我的代码是这样的:

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 的地图中骨架的专用插槽。

赞赏任何想法或敏锐的眼光。

【问题讨论】:

    标签: kinect kinect-sdk openni nite


    【解决方案1】:

    最后我通过计算没有跟踪骨架的帧来解决这个问题。骨架数据有 6 个插槽,在某些帧中,其跟踪 ID 未设置为 NUI_SKELETON_TRACKED。 因此,如果空骨架槽的数量超过 20(这意味着大约 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;
            }
        }
    }
    

    希望对他人有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多