【发布时间】:2014-03-07 09:17:48
【问题描述】:
我正在尝试存储来自 kinect 的最新 45 色帧。我的想法是,我可以使用 kinect 使用的 colorPixel 数组以字节形式存储像素数据,并将其保存到我称为 Frames 的锯齿状数组中。下面的代码是 kinect 标准颜色查看器的事件处理程序的样子 `
//These are global parameter
next index = 0;
byte[45][] Frames;
byte nextIndex = 0;
//This is the event handler within the code for a typical color viewer
void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
//Opens the color frame sent from the event handler and declares it
//as 'colorFrame'.
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
/*Check to see if colorFrame is null. It will be null if this frame cannot
be processed before the event handler registers another frame. This
results in the null frame being dropped as there is no method for
colorFrame == null.*/
if (colorFrame != null)
{
//Copies a frame of data to 'colorPixels'.
colorFrame.CopyPixelDataTo(colorPixels);
//Assigns colorPixels to the array Frames. Also, this will only store
//the 45 most recent Frames
Frames[nextIndex] = colorPixels;
nextIndex++;
if (nextIndex == 45)
{
nextIndex = 0;
}
/*Updates the pixels in the specified region of the bitmap. Parameteres:
Int32Rect- Describes the width, height, and location of an integer rectangle
XAML value for X coordinate of top left corner
XAML value for Y coordinate of top left corner
Width of the rectangle
Heigth of the rectangle
Pixels- the pixel array used to update the bitmap
Stride- the stride of the update region in pixels
Offset- the input buffer offset */
colorBitmap.WritePixels(
new Int32Rect(0, 0, colorBitmap.PixelWidth, colorBitmap.PixelHeight),
colorPixels,
colorBitmap.PixelWidth * sizeof(int),
0);
}
}
}`
该代码的问题在于,当它运行时,它将当前正在处理的数组 (colorPixels) 分配给 Frames 数组的每个元素。因此,来自第一帧的第一个数组 colorPixels 存储为 Frames[0],但是当事件处理程序再次触发并且第二个 colorPixels 数组准备就绪时,Frames[0] 和 Frames[1] 都被重新分配为 colorPixel 数组第 2 帧。谢谢!
【问题讨论】: