Преобразование Kinect из данных скелета в данные глубины и обратно

Я экспериментирую с API kinect, и я пытаюсь (и не могу) добиться следующего:

начиная я получаю данные скелета от kinect и вычисляю расстояние правой руки пользователя от kinect

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

Я преобразовываю данные скелета правой руки в данные глубины, чтобы получить положение руки на изображении (глубина/цвет).

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

получив положение пикселя руки, я хочу преобразовать этот пиксель обратно в данные скелета и снова вычислить расстояние объекта в этом пикселе (руке) от kinect. Я бы предположил, что это должно дать мне примерно то же расстояние, что и раньше (конечно, с небольшой погрешностью), но это не так. Вот что я делаю:

//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));

я пропустил что-то очевидное? заранее спасибо


person tk66    schedule 01.12.2014    source источник


Ответы (1)


После долгих поисков я понял, что не так. Вот решение для тех, кто пытается сделать что-то подобное

во-первых, чтобы сохранить данные о глубине, лучший способ (я нашел)) был следующим

в функции processDepth():

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));

в функции ComposeImage() (или любой функции, в которой вы хотите использовать данные о глубине):

//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));

теперь предполагаемое_расстояние и фактическое_расстояние должны иметь примерно одинаковые значения с небольшой разницей.

person tk66    schedule 21.12.2014