我正在使用Kinect傳感器,我試圖對齊深度和顏色框架,以便我可以將它們保存爲適合彼此的圖像。我已經花了很多時間去了msdn論壇和Kinect SDK的適度文檔,我完全沒有辦法。Kinect SDK:對齊深度和顏色框架
基於此答案:Kinect: Converting from RGB Coordinates to Depth Coordinates
我有以下功能,其中depthData
和colorData
從NUI_LOCKED_RECT.pBits
和mappedData
得到一種包含新彩色幀的輸出,映射到深度座標:
bool mapColorFrameToDepthFrame(unsigned char *depthData, unsigned char* colorData, unsigned char* mappedData)
{
INuiCoordinateMapper* coordMapper;
// Get coordinate mapper
m_pSensor->NuiGetCoordinateMapper(&coordMapper);
NUI_DEPTH_IMAGE_POINT* depthPoints = new NUI_DEPTH_IMAGE_POINT[640 * 480];
HRESULT result = coordMapper->MapColorFrameToDepthFrame(NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, NUI_IMAGE_RESOLUTION_640x480, 640 * 480, reinterpret_cast<NUI_DEPTH_IMAGE_PIXEL*>(depthData), 640 * 480, depthPoints);
if (FAILED(result))
{
return false;
}
int pos = 0;
int* colorRun = reinterpret_cast<int*>(colorData);
int* mappedRun = reinterpret_cast<int*>(mappedData);
// For each pixel of new color frame
for (int i = 0; i < 640 * 480; ++i)
{
// Find the corresponding pixel in original color frame from depthPoints
pos = (depthPoints[i].y * 640) + depthPoints[i].x;
// Set pixel value if it's within frame boundaries
if (pos < 640 * 480)
{
mappedRun[i] = colorRun[pos];
}
}
return true;
}
我運行此代碼時得到的所有像素都是未更改的顏色框,其中depthFrame沒有任何信息,所有像素均已去除(白色)。
有你的Kinect的檢查了綠屏例如用於Windows編碼的例子嗎? http://kinectforwindows.codeplex.com/。它對齊顏色和深度。 – 2013-04-15 13:44:38
是的,我有。它不使用新的'INuiCoordinateMapper',而是使用舊的方法'INuiSensor :: NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution'。我試過了,它也不適用於我(我得到所有白色圖像)。不知何故,他們得到的深度值數組是USHORT(16位),而我的數據是32位,可能的原因是我用不同的參數(深度只有沒有玩家指數)初始化我的Kinect傳感器。即使我從32位創建了一個16位深度值的數組,該函數也不適用於我。 – jaho 2013-04-15 14:30:00
類似的東西在這裏得到了解決:http://stackoverflow.com/a/19905805/2521214 Kinect的SDK有圖像allign功能,但他們根本沒有爲我工作(有一個非常老版本的kinect),所以我做到了我自己...在這個鏈接是我的你的kinect校準數據,你必須自己測量它 – Spektre 2014-02-26 08:19:06