2014-12-01 4 views
0

나는 키 넥트 API를 실험하고, 그리고 무엇을 달성하려는 (그리고 실패)하고하면 다음과 같다 :넥트는 깊이 데이터에 해골 데이터로 변환하고 다시

오프 시작 나는 키 넥트에서 골격의 데이터를 얻을 수 및

mRightHandPosition = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT];  
distance = sqrt(pow(mRightHandPosition.x, 2) + pow(mRightHandPosition.y, 2) + pow(mRightHandPosition.z, 2)); 

I는 (깊이/컬러)의 손의 위치를 ​​얻기 위해, 깊이 데이터에 오른손의 골격 데이터 변환 넥트에서 사용자의 오른손의 거리 alculate 영상.

FLOAT curRightX = 0, curRightY = 0; 
Vector4 pixelInSkeletonSpace; 
NuiTransformSkeletonToDepthImage(mRightHandPosition, &curRightX, &curRightY, cDepthResolution); 

은 손의 화소 위치를 획득 한 난 골격 데이터로 픽셀을 다시 변환하고 넥트에서 픽셀 (손), 다시 물체의 거리를 산출 할. 그 일을하는 것은 이전과 거의 같은 거리를 제공해야한다고 생각 하겠지만 (물론 약간의 오류는 있지만) 그렇지 않습니다. 다음은 내가하는 일입니다.

//the position of the depth pixel in the mLockedRect.pBits array 
//i have set the depth sensor resolution to 320x240 
int pixelPosition = 2 * ((int)curRightX + (int)curRightY * 320); 
USHORT p; 
//convert the two consecutive bytes to USHORT 
p = (((unsigned short)mLockedRect.pBits[pixelPosition]) << 8) | mLockedRect.pBits[pixelPosition + 1]; 
//get the pixel in skeleton space 
pixelInSkeletonSpace = NuiTransformDepthImageToSkeleton(LONG(curRightX), LONG(curRightY), p, cDepthResolution); 
//calculate again the distance (which turns out completely wrong) 
distance = sqrt(pow(pixelInSkeletonSpace.x, 2) + pow(pixelInSkeletonSpace.y, 2) + pow(pixelInSkeletonSpace.z, 2)); 

제가 분명한 사실을 놓치고 있습니까? 내가 잘못 알아 발견 검색을 많이 후 사전

답변

0

에 감사 .. 여기에 깊이 데이터를 저장하기 위해

첫 비슷한 뭔가를 시도하고 다른 사람에 대한 해결책이 최선의 방법 (내가 발견))가 processDepth() 함수에서 다음

이었다 다음 ComposeImage에

bghr = m_pBackgroundRemovalStream->ProcessDepth(m_depthWidth * m_depthHeight * cBytesPerPixel, LockedRect.pBits, depthTimeStamp); 
const NUI_DEPTH_IMAGE_PIXEL* pDepth = reinterpret_cast<const NUI_DEPTH_IMAGE_PIXEL*>(LockedRect.pBits); 
memcpy(mLockedBits, pDepth, m_depthWidth * m_depthHeight * sizeof(NUI_DEPTH_IMAGE_PIXEL)); 

() 함수 (또는 기능 당신은 깊이 데이터)를 사용하려면 :

//transform skeleton data point to depth data 
NuiTransformSkeletonToDepthImage(mRightHandPosition, &curRightX, &curRightY, cDepthResolution); 

//calculate position of pixel in array 
int pixelPosition = (int)curRightX + ((int)curRightY * m_depthWidth); 

//get the depth value of the pixel 
const USHORT depth = mLockedBits[pixelPosition].depth; 

//create a new point in skeleton space using the data we got from the previous transformation 
pixelInSkeletonSpace = NuiTransformDepthImageToSkeleton(LONG(curRightX), LONG(curRightY), depth << 3, cDepthResolution); 

//calculate estimated distance of right hand from the kinect sensor using our recreated data 
FLOAT estimated_distance = sqrt(pow(pixelInSkeletonSpace.x, 2) + pow(pixelInSkeletonSpace.y, 2) + pow(pixelInSkeletonSpace.z, 2)); 

//calculate the distance of the right hand from the kinect sensor using the skeleton data that we got straight from the sensor 
FLOAT actual_distance = sqrt(pow(mRightHandPosition.x, 2) + pow(mRightHandPosition.y, 2) + pow(mRightHandPosition.z, 2)); 

이제 estimated_distance와 actual_distance는 약간의 차이가있는 거의 동일한 값을 가져야합니다.