2013-02-13 51 views
1

我是StackOverflow和Kinect SDK的新手。我目前正在研究我的最後一年項目,其中涉及Kinect的Record/Replay Color/Depth和骨架數據。我找到了一個Kinect Toolbox,它啓用了這個功能,我將Toolbox與SDK示例項目(Color/Depth/skeleton基本知識C#WPF)集成在一起,製作一個程序,可以顯示之前記錄的.replay文件中的所有流。kinect工具箱記錄和重播的用法

我現在遇到的問題是由於KinectReplay類與SDK中的工具箱和KinectSensor類的不同。在深度基本示例代碼,在爲了顯示流,在WindowLoaded()以下行,其用於從所述Kinect的檢索到的數據中分配空間:

/

/ Allocate space to put the depth pixels we'll receive 
this.depthPixels = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength]; 

       // Allocate space to put the color pixels we'll create 
       this.colorPixels = new byte[this.sensor.DepthStream.FramePixelDataLength * sizeof(int)]; 

       // This is the bitmap we'll display on-screen 
       this.colorBitmap = new WriteableBitmap(this.sensor.DepthStream.FrameWidth, this.sensor.DepthStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null); 

//The code below came from "Skeleton basics C# WPF", which I need to find the correspondence of "CoordinateMapper" in KinectReplay Class 
    // We are not using depth directly, but we do want the points in our 640x480 output resolution. 
       DepthImagePoint depthPoint = this.sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skelpoint, DepthImageFormat.Resolution640x480Fps30); 

在原始樣品代碼,所述上面的對象大小的參數是從KinectSensor對象中獲取的,我需要做類似的事情,但是從KinectReplay對象中獲取數據,例如,如何從KinectReplay對象中獲得等效的「this.sensor.DepthStream.FramePixelDataLength」作爲「this.replay = new KinectReplay(recordStream);」?

我能想到的唯一解決方案是調用「this.depthPixels = new DepthImagePixel[e.FramePixelDataLength]; 「在replay_DepthImageFrameReady(object sender, ReplayDepthImageFrameReadyEventArgs e)中,每當從KinectReplay接收到深度圖像幀時調用它。因此,一個DepthImagePixel數組將被初始化很多次,效率很低,在示例代碼中這隻會被執行一次。

回答

1

一種解決方案是在初始化過程中簡單地獲取一幀中像素的數量,並始終使用此值,因爲記錄幀中的像素數量不太可能會發生變化。

例如,假設你有一個名爲OnNewDepthReplay框架方法,你會做這樣的事情(未測試,語法可能會關閉):

public void OnNewDepthReplayFrame(DepthReplayFrameEventArgs e) { 
    if (depthPixels == null) { 
     depthPixels = new new DepthImagePixel[eFramePixelDataLength]; 
    } 
    // code that uses your depthPixels here 
} 

但是,使用附帶的記錄/回放功能Kinect 1.5和1.6 SDK實際上可能比使用Kinect Toolbox更好。我以前使用Kinect工具箱進行錄製/重放,但是當Kinect for Windows v 1.5出來時,我自己將其移至Kinect Studio。以下是關於如何使用Kinect Studio以及guide on MSDNvideo

+0

謝謝Julenka。我無法使用Kinect Studio的原因是記錄/重放功能傾向於成爲我的項目的一項功能,並且沒有任何API用於訪問Studio生成的.xed。 此外,你有什麼想法如何'this.sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skelpoint,DepthImageFormat.Resolution640x480Fps30);'可以被工具箱中的方法取代,現在我找不到相應的。此外,真的很感謝你可以給我發一些關於使用記錄/重放的示例代碼/項目,因爲我正在努力找到一個。 – soudazhou 2013-02-20 16:41:22

+0

剛剛發現可以使用Kinect Toolbox庫中的ColorStreamManager類來顯示,對於其他兩個流類似 – soudazhou 2013-02-22 17:50:28