2015-04-06 106 views
2

我想使用sdk中的coordinateMapper函數將深度圖映射到顏色空間。但是,我收到的輸出結果並不符合我的預期,它的縱橫比似乎較小,圖像似乎是鏡像的。使用C的Kinect v2顏色深度映射#

下面是我使用的代碼:

depthWidth = depthFrameDescription.Width; 
depthHeight = depthFrameDescription.Height; 

var colorDesc = colorFrame.FrameDescription; 
int colorWidth = colorDesc.Width; 
int colorHeight = colorDesc.Height; 

int size = colorWidth * colorHeight; 

DepthSpacePoint[] colSpacePoints = new DepthSpacePoint[colorWidth * colorHeight]; 

using (KinectBuffer depthFrameData = depthFrame.LockImageBuffer()) 
using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer()) 
{ 
    this.bitmap.Lock(); 

    if ((colorWidth == this.bitmap.PixelWidth) && (colorHeight == this.bitmap.PixelHeight)) 
    { 
     byte[] colorFrameData = new byte[size * bytesPerPixel];  

     // Map the values here 
     ushort [] frameData = new ushort[depthWidth * depthHeight]; 
     depthFrame.CopyFrameDataToArray(frameData); 
     coordinateMapper.MapColorFrameToDepthSpace(frameData, colSpacePoints); 

     this.bitmap.WritePixels(new Int32Rect(0, 0, colorWidth, colorHeight), colSpacePoints, colorWidth * bytesPerPixel, 0); 
     this.bitmap.AddDirtyRect(new Int32Rect(0, 0, this.bitmap.PixelWidth, this.bitmap.PixelHeight)); 
    }  
    this.bitmap.Unlock(); 
} 

this.bitmapBackBufferSize = (uint)![enter image description here][1]((this.bitmap.BackBufferStride * (this.bitmap.PixelHeight - 1)) + (this.bitmap.PixelWidth * this.bytesPerPixel)); 
isBitmapLocked = true; 

回答

0

如果你想深度幀的彩色幀的座標圖,你缺少的一個步驟。

這裏是一個鏈接,或許可以解釋它更好,我可以: http://www.bryancook.net/2014/03/mapping-between-kinect-color-and-depth.html

但在你的情況下,當您使用

coordinateMapper.MapColorFrameToDepthSpace(frameData, colSpacePoints); 

輸出並不是你如何使用它來使用。該函數的輸出包含色彩空間和深度空間中存在的所有點。因此,爲了展示這些內容,您希望遍歷colSpacePoints並對每個結果進行一些操作,在我鏈接的示例中,它被稱爲_colorSpacePoints,因此您可以查看他對它的操作。

我被困在試圖做可能類似於你正在做的事情,但幾天後,我發現如何正確使用映射。如果您需要更多幫助,請告訴我您要在您的WriteableBitmap中顯示的內容。