예제 #1
0
        // cut hand image  get bool
        private void SensorDepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            try
            {
                using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
                {
                    if (depthFrame != null)
                    {
                        DepthImagePoint handPos = new DepthImagePoint();
                        try
                        {
                            handPos = sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(RightHand,
                                                                                           DepthImageFormat.
                                                                                           Resolution640x480Fps30);
                            this.DepthImage.Source = DepthToBitmapSource(depthFrame);
                            if (handtracked)
                            {
                                var   person    = skeletons.First(p => p.TrackingState == SkeletonTrackingState.Tracked);
                                Joint handJoint = person.Joints[JointType.HandRight];

                                double handausschnitt = handDection.ComputeHandSize(handJoint);


                                if ((handPos.X + HandTracker.EpsilonTolerance + handausschnitt / 2) > 640 || handPos.X - HandTracker.EpsilonTolerance - handausschnitt / 2 <= 0)
                                {
                                    return;                                                                                                                                              // epsilon +2 wegen möglichem -1  von handPosX/Y
                                }
                                if ((handPos.Y + HandTracker.EpsilonTolerance + handausschnitt / 2) > 480 || handPos.Y - HandTracker.EpsilonTolerance - handausschnitt / 2 <= 0)
                                {
                                    return;
                                }

                                ImageSource imgRightHandSource =
                                    new CroppedBitmap((BitmapSource)DepthImage.Source.CloneCurrentValue(), new Int32Rect(
                                                          handPos.X - (int)handausschnitt / 2,
                                                          handPos.Y - (int)handausschnitt / 2,
                                                          (int)handausschnitt, (int)handausschnitt));
                                RightHandImage.Source = imgRightHandSource; //paints

                                DepthImagePixel[] depthPixels = new DepthImagePixel[sensor.DepthStream.FramePixelDataLength];
                                depthFrame.CopyDepthImagePixelDataTo(depthPixels);

                                //var handStatus = handDection.GetHandOpenedClosedStatus(depthPixels, handJoint, sensor, DepthImageFormat.Resolution640x480Fps30);
                                var handStatus = handDection.GetBufferedHandStatus(depthPixels, handJoint, sensor, DepthImageFormat.Resolution640x480Fps30);

                                this.HandDescriptionTBox.Text = "Hand is " + handStatus.ToString();
                                //this.HandDescriptionTBox.Text = " rightH.: " + RightHand.Z.ToString();
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
            }
            catch
            {
                Console.WriteLine("Error HandDetect");
            }
        }