Pergunta

I am new to StackOverflow and Kinect SDK. I am currently working on my final year project which involves Record/Replay Colour/Depth and skeleton data from Kinect. A Kinect Toolbox was found which enables this and I am integrating the Toolbox with the SDK sample projects (Colour/Depth/skeleton basics C# WPF) to make a program that could display all those stream from the .replay file recorded previously.

The problem I have for now is due to the differences of the KinectReplay Class from the Toolbox and the KinectSensor Class in the SDK. In the Depth Basics Sample code, in order to display the streams, the following lines in WindowLoaded() which allocate space for data retrieved from the 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);

In the original sample code, the parameter for the size of above objects were retrieved from KinectSensor Object, which I need to do similar things but took data from KinectReplay Object, for example, how do I get the equivalent of “this.sensor.DepthStream.FramePixelDataLength” from a KinectReplay object as “this.replay = new KinectReplay(recordStream);” ?

The only solution that I can think of is to call “this.depthPixels = new DepthImagePixel[e.FramePixelDataLength]; ” in the replay_DepthImageFrameReady(object sender, ReplayDepthImageFrameReadyEventArgs e) which is invoked each time a depth image frame is received from the KinectReplay. Thus an array of DepthImagePixel will be initialised many times which is inefficient, and in the sample code this will be done only once.

Foi útil?

Solução

One solution would be to simply get the number of pixels in a frame once during initialization and always use this value since it's unlikely that the number of pixels in a recorded frame will change.

For example, assuming you have a method called OnNewDepthReplay frame, you would do something like this (not tested, syntax might be off):

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

However, using the record/replay capabilities that come with the Kinect 1.5 and 1.6 SDKs might actually be a better option than using the Kinect Toolbox. I used to use Kinect Toolbox for it's recording/replay but then moved to Kinect Studio myself when Kinect for Windows v 1.5 came out. Here's a video on how to use Kinect Studio as well as a guide on MSDN.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top