如果应用程序只需要捕捉上半身动作,就可以采用半身模式(Seated Mode),只捕捉上半身的10个骨骼点,可以解决用户在椅子上无法被识别的问题,代码如下绿色底纹,放在开启数据流中。
private KinectSensor kinectDevice; private KinectSensor KinectDevice { get { return kinectDevice; } set { if (kinectDevice != value) { //未初始化 if (kinectDevice != null) { kinectDevice.Stop(); kinectDevice.SkeletonFrameReady -= KinectDevice_SkeletonFrameReady; kinectDevice.SkeletonStream.Disable(); kinectDevice.DepthFrameReady -= this.KinectSensorOnDepthFrameReady; kinectDevice.ColorStream.Disable(); //this.interactionStream.InteractionFrameReady -= this.InteractionFrameReady; //this.interactionStream.Dispose(); frameSkeletons = null; } kinectDevice = value; //初始化 if (kinectDevice != null) { if (kinectDevice.Status == KinectStatus.Connected) { kinectDevice.SkeletonStream.Enable(); frameSkeletons = new Skeleton[kinectDevice.SkeletonStream.FrameSkeletonArrayLength]; kinectDevice.ColorFrameReady += DeviceColorFrameReady; kinectDevice.ColorStream.Enable(); //开启深度流数据 kinectDevice.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30); //开启骨骼流数据 kinectDevice.SkeletonStream.Enable(); //设置深度数据读取委托实例 kinectDevice.DepthFrameReady += kinectSensor_DepthFrameReady; //设置骨骼数据读取委托实例 kinectDevice.SkeletonFrameReady += kinectSensor_SkeletonFrameReady; //实例化交互端 ic = new InteractionClient(); //实例化交互流 its = new InteractionStream(kinectDevice, ic); //设置交互数据读取委托实例 its.InteractionFrameReady += its_InteractionFrameReady; //this.interactionStream = new InteractionStream(kinectDevice, kinectAdapter); //this.interactionStream.InteractionFrameReady += this.InteractionFrameReady; //kinectDevice.DepthFrameReady += this.KinectSensorOnDepthFrameReady; kinectDevice.DepthStream.Enable(); kinectDevice.SkeletonFrameReady += KinectDevice_SkeletonFrameReady; //上半身模式 kinectDevice.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated; //开启Kinect,读取数据 kinectDevice.Start(); } } } } }