標籤:kinect
1, 開啟骨骼幀的方式
對於V1,
方法NuiSkeletonTrackingEnable實現 m_hNextSkeletonEvent = CreateEvent(NULL, TRUE, FALSE, NULL ); hr =m_PNuiSensor->NuiSkeletonTrackingEnable( m_hNextSkeletonEvent, NUI_SKELETON_TRACKING_FLAG_ENABLE_IN_NEAR_RANGE//| ); if( FAILED( hr ) ) { cout<<"Couldnot open skeleton stream video"<<endl; return hr; }
對於V2
// Initialize the Kinect andget coordinate mapper and the body reader IBodyFrameSource* pBodyFrameSource = NULL; hr = m_pKinectSensor->Open(); if (SUCCEEDED(hr)) { hr = m_pKinectSensor->get_CoordinateMapper(&m_pCoordinateMapper); }方法get_CoordinateMapper得到座標映射 if (SUCCEEDED(hr)) { hr =m_pKinectSensor->get_BodyFrameSource(&pBodyFrameSource); }方法get_BodyFrameSource得到骨骼幀源 if (SUCCEEDED(hr)) { hr =pBodyFrameSource->OpenReader(&m_pBodyFrameReader); }方法get_BodyFrameSource開啟骨骼幀讀取器 SafeRelease(pBodyFrameSource); }
2,更新骨骼幀方式
對於V1,方法NuiSkeletonGetNextFrame實現
NUI_SKELETON_FRAMESkeletonFrame;//骨骼幀的定義 bool bFoundSkeleton = false; if(SUCCEEDED(NuiSkeletonGetNextFrame( 0, &SkeletonFrame )) )//Get the next frameof skeleton data.直接從kinect中提取骨骼幀
對於V2,
竟然木有發現如何更新的哎,再慢慢看吧。。。
3,畫骨架方式:
對於V1,主要用opencv輔助來畫,用到cvLine方法
例如左上肢的實現為:
//左上肢 if((pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER].x!=0 ||pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER].y!=0) && (pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT].x!=0 ||pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT].y!=0)) cvLine(SkeletonImage, pointSet[NUI_SKELETON_POSITION_SHOULDER_CENTER],pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT], color, 2); if((pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT].x!=0 ||pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT].y!=0) && (pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT].x!=0|| pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT].y!=0)) cvLine(SkeletonImage,pointSet[NUI_SKELETON_POSITION_SHOULDER_LEFT],pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT], color, 2); if((pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT].x!=0 ||pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT].y!=0) && (pointSet[NUI_SKELETON_POSITION_WRIST_LEFT].x!=0 ||pointSet[NUI_SKELETON_POSITION_WRIST_LEFT].y!=0)) cvLine(SkeletonImage,pointSet[NUI_SKELETON_POSITION_ELBOW_LEFT],pointSet[NUI_SKELETON_POSITION_WRIST_LEFT], color, 2); if((pointSet[NUI_SKELETON_POSITION_WRIST_LEFT].x!=0 ||pointSet[NUI_SKELETON_POSITION_WRIST_LEFT].y!=0) && (pointSet[NUI_SKELETON_POSITION_HAND_LEFT].x!=0 ||pointSet[NUI_SKELETON_POSITION_HAND_LEFT].y!=0)) cvLine(SkeletonImage,pointSet[NUI_SKELETON_POSITION_WRIST_LEFT],pointSet[NUI_SKELETON_POSITION_HAND_LEFT], color, 2);
對於V2,主要藉助Direct2D微軟的圖形映像API,具體詳細可以查閱資料。。當然也可以轉換為用opencv來畫。
Kinect for Windows V2和V1對比開發___骨骼資料擷取