public KinectProvider(IInputListener listener) { if (listener == null) throw new ArgumentNullException("listener"); Listener = listener; Enabled = true; Available = true; try { nui = new Runtime(); #if(RETRHOW_RUNTIME_EXCEPTION) try { nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking); } catch (InvalidOperationException) { throw new InvalidOperationException("Runtime initialization failed. Please make sure Kinect device is plugged in."); } try { nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex); } catch (InvalidOperationException) { throw new InvalidOperationException("Failed to open stream. Please make sure to specify a supported image type and resolution."); } #else nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex);// | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor); nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex); #endif nui.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_DepthFrameReady); nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(nui_SkeletonFrameReady); leftHandProvider = new KinectPositionProvider("left", this); rightHandProvider = new KinectPositionProvider("right", this); providers = new KinectPositionProvider[] { rightHandProvider, leftHandProvider }; } catch { Available = false; } if (Available) { try { ImageProcessingEngine = new ImageProcessingEngine(320, 240, 4); KinectBlobsMatcher = new KinectBlobsMatcher(ImageProcessingEngine, 320 >> 1, 240 >> 1); } catch { KinectBlobsMatcher = null; ImageProcessingEngine = null; Available = false; } } }
private CursorState ParseKinectCursorState(KinectBlobsMatcher.BlobParametersRecord blobRecord) { if (blobRecord == null || blobRecord.MBlob == null) return CursorState.Default; else { var mblob = blobRecord.MBlob; switch (mblob.Status) { default: case BlobsTracker.Status.Lost: return CursorState.Default; case BlobsTracker.Status.Tracking: return CursorState.Tracked; case BlobsTracker.Status.Waiting: return CursorState.StandBy; } } }