我正在用 C# 编写一个 kinect 应用程序,我有这个代码
try //start of kinect code
{
_nui = new Runtime();
_nui.Initialize(RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseColor);
// hook up our events for video
_nui.DepthFrameReady += _nui_DepthFrameReady;
_nui.VideoFrameReady += _nui_VideoFrameReady;
// hook up our events for skeleton
_nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(_nui_SkeletonFrameReady);
// open the video stream at the proper resolution
_nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);
_nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
// parameters used to smooth the skeleton data
_nui.SkeletonEngine.TransformSmooth = true;
TransformSmoothParameters parameters = new TransformSmoothParameters();
parameters.Smoothing = 0.8f;
parameters.Correction = 0.2f;
parameters.Prediction = 0.2f;
parameters.JitterRadius = 0.07f;
parameters.MaxDeviationRadius = 0.4f;
_nui.SkeletonEngine.SmoothParameters = parameters;
//set camera angle
_nui.NuiCamera.ElevationAngle = 17;
}
catch (System.Runtime.InteropServices.COMException)
{
MessageBox.Show("Could not initialize Kinect device.\nExiting application.");
_nui = null;
}
我正在寻找一种方法,让我的应用程序在 kinect 未连接时不会崩溃(要忽略的异常)。我在这里创建了另一个问题,但解决方案无法应用于我的场合,因为我被迫使用过时的 sdk,没有人能解决这个问题,所以我尝试使用不同的方法。如何忽略此异常?(之后我可以自己撤销对 _nui 所做的更改)