【发布时间】:2013-01-06 15:14:05
【问题描述】:
我正在使用XNA Framework 4.0 和Kinect 1.6 SDK 开发游戏。我的代码使用颜色、深度和骨架数据,所以我使用AllFramesReady 事件。
当我运行游戏发现有人检测时,AllFramesReady事件触发的函数会提取人的图像和骨骼数据,并设置我的Player类的属性。
问题是,这段代码过去可以完美运行。但是即使我没有对我的代码进行任何更改,它现在也无法正常工作。我在其他电脑上试了一下,效果很好。但同样的代码在我的电脑上不起作用。
当我调试时,我看到DepthFrameEventReadyArgs 和ColorFrameEventReadyArgs 有一个名为isInvalid 的成员,它们被设置为true。因此,当我使用:
DepthImageFrame depthVideoFrame = mainFrame.OpenDepthImageFrame();
...我得到一个空的depthVideoFrame。色框也是如此。
这里是我初始化 Kinect 的地方(Initialize):
if (KinectSensor.KinectSensors.Count > 0)
{
kinect = KinectSensor.KinectSensors[0];
EnableColorStream(kinect);
EnableDepthStream(kinect);
EnableSkeletonStream(kinect);
kinect.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(kinect_AllFramesReady);
kinect.Start();
}
启用方法:
void EnableColorStream(KinectSensor ks)
{
ks.ColorStream.Enable(ColorFormat);
colorWidth = ks.ColorStream.FrameWidth;
colorHeight = ks.ColorStream.FrameHeight;
colorVideo = new Texture2D(graphics.GraphicsDevice, ks.ColorStream.FrameWidth, ks.ColorStream.FrameHeight);
}
void EnableDepthStream(KinectSensor ks)
{
ks.DepthStream.Enable(DepthFormat);
depthWidth = ks.DepthStream.FrameWidth;
depthHeight = ks.DepthStream.FrameHeight;
depthVideo = new Texture2D(graphics.GraphicsDevice, ks.DepthStream.FrameWidth, ks.DepthStream.FrameHeight);
}
void EnableSkeletonStream(KinectSensor ks)
{
TransformSmoothParameters tsp = new TransformSmoothParameters();
tsp.Smoothing = 0f;
tsp.Correction = 0.1f;
tsp.Prediction = 0.1f;
tsp.JitterRadius = 0.1f;
tsp.MaxDeviationRadius = 0.1f;
ks.SkeletonStream.Enable(tsp);
}
在kinect_AllFramesReady 我正在使用类似的东西:
using (ColorImageFrame colorVideoFrame = imageFrames.OpenColorImageFrame())
{
...
}
using (SkeletonFrame skeletonFrame = imageFrames.OpenSkeletonFrame())
{
...
}
using (DepthImageFrame depthVideoFrame = imageFrames.OpenDepthImageFrame())
{
...
}
在调试时,我看到colorVideoFrame 和depthVideoFrame 的值是null,因为isInvalid 成员设置为true。当我使用深度和颜色数据运行其他程序时,它们运行正常,但只有这个不工作。我目前没有想法。感谢您的帮助。
【问题讨论】:
-
请包含您用于初始化 Kinect 和捕获事件的代码。
-
我在主信息中添加了一些代码。
-
我还不能试用代码,但是您是否尝试过使用单独的
FrameReady事件而不是AllFramesReady? -
不,我没有,但我认为这不是问题所在。正如我之前所说,这段代码曾经完美地工作过。我很确定代码的结构没有问题。我认为问题是“isInvalid”属性为真。我想知道是什么原因造成的。