2013-07-10 22 views
0

我正在與Kinect和閱讀示例從DepthWithColor-D3D,有一些代碼,但我還不明白。在Kinect SDK中解釋代碼

// loop over each row and column of the color 
for (LONG y = 0; y < m_colorHeight; ++y) 
{ 
    LONG* pDest = (LONG*)((BYTE*)msT.pData + msT.RowPitch * y); 
    for (LONG x = 0; x < m_colorWidth; ++x) 
    { 
     // calculate index into depth array 
     int depthIndex = x/m_colorToDepthDivisor + y/m_colorToDepthDivisor * m_depthWidth; 

     // retrieve the depth to color mapping for the current depth pixel 
     LONG colorInDepthX = m_colorCoordinates[depthIndex * 2]; 
     LONG colorInDepthY = m_colorCoordinates[depthIndex * 2 + 1]; 

如何計算的colorInDepthX價值和colorInDepthY如上面的代碼?

+0

此代碼。你對什麼感到困惑? – Mikeb

+0

嗨,我的意思是爲什麼colorInDepthX和colorInDepthY之間的差異是「+1」? –

回答

0

colorInDepthXcolorInDepthY是深度圖像和彩色圖像之間的映射,以便它們對齊。由於Kinect的相機稍微偏移,所以它們的視野並不完美。

m_colorCoordinates在該文件的頂部被定義爲這樣:

m_colorCoordinates = new LONG[m_depthWidth*m_depthHeight*2]; 

這是表示2維圖像的一維數組,它被填充正上方你在你的問題張貼代碼塊:

// Get of x, y coordinates for color in depth space 
// This will allow us to later compensate for the differences in location, angle, etc between the depth and color cameras 
m_pNuiSensor->NuiImageGetColorPixelCoordinateFrameFromDepthPixelFrameAtResolution(
    cColorResolution, 
    cDepthResolution, 
    m_depthWidth*m_depthHeight, 
    m_depthD16, 
    m_depthWidth*m_depthHeight*2, 
    m_colorCoordinates 
    ); 

如評論中所述,這是運行SDK提供的一種計算方法,用於將顏色和深度座標映射到彼此上。結果放在m_colorCoordinates之內。

colorInDepthXcolorInDepthY只是m_colorCoordinates數組內的值,這些數值在當前循環的循環中執行。它們本身不是「計算」的,只是指出m_colorCoordinates中已經存在的內容。

處理顏色和深度圖像之間映射的函數在MSDN的Kinect SDK中進行了說明。這裏是一個直接鏈接:似乎是從一些數據結構獲得的值,而不是要求您計算任何

http://msdn.microsoft.com/en-us/library/jj663856.aspx

+0

感謝您的回答,但我不明白爲什麼:colorInDepthX = m_colorCoordinates [depthIndex * 2];和colorInDepthY = m_colorCoordinates [depthIndex * 2 + 1],爲什麼colorInDepthX和colorInDepthY之間的差異是「+1」? –

+1

'm_colorCoordinates'是代表二維數據集的一維數組。它將給定'x'和給定'y'座標的數據放在數組中,因此二維圖像中的任何給定點都在一維數組中表示爲'x = n '和'y = n + 1'。 –

+0

嗨,我完全理解。非常感謝你,邪惡壁櫥猴! –