我正在开发一个游戏使用XNA Framework 4.0
和Kinect 1.6 SDK
。我的代码使用颜色,深度和骨架数据,所以我正在使用AllFramesReady
事件。Kinect零深度和颜色框架
当我运行游戏并且有人要检测时,由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'? –