Esempio n. 1
0
        /// <summary>
        /// Captures the specified Kinect depth frame and saves it to the specified location.
        /// </summary>
        /// <param name="frame">The depth frame to capture.</param>
        /// <param name="file">The storage file for the new image. JPEG, PNG, GIF, BMP and TIFF formats are supported.</param>
        /// <param name="width">The width of the image file.</param>
        /// <param name="height">The height of the image file.</param>
        /// <returns>True if the bitmap file was successfully saved. False otherwise.</returns>
        public static async Task <bool> Capture(this DepthFrame frame, StorageFile file, int width, int height)
        {
            if (frame == null)
            {
                return(false);
            }

            return(await Capture(frame.ToBitmap(), file, width, height));
        }
Esempio n. 2
0
        /// <summary>
        /// Captures the specified Kinect depth frame and saves it to the specified location.
        /// </summary>
        /// <param name="frame">The depth frame to capture.</param>
        /// <param name="path">The desired file path, including file name and extension, for the new image. Currently, JPEG, PNG and BMP formats are supported.</param>
        /// <returns>True if the bitmap file was successfully saved. False otherwise.</returns>
        public static bool Capture(this DepthFrame frame, string path)
        {
            if (frame == null)
            {
                return(false);
            }

            return(Capture(frame.ToBitmap(), path));
        }
Esempio n. 3
0
 /// <summary>
 /// Acquires the latest depth frame.
 /// It calles the OnDepthFrameReceived only if the acquired frame is not null.
 /// </summary>
 protected void UpdateDepthFrame(bool updateFrameView = true)
 {
     if (depthFrameReader != null)
     {
         using (DepthFrame frame = depthFrameReader.AcquireLatestFrame())
         {
             if (frame != null)
             {
                 if (updateFrameView)
                 {
                     frameView.FrameTexture = frame.ToBitmap();
                 }
                 OnDepthFrameReceived(frame);
             }
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Converts the specified depth and body index frames to a bitmap and saves it to the specified location.
        /// </summary>
        /// <param name="depthFrame">The source depth frame.</param>
        /// <param name="bodyIndexFrame">The source body index frame.</param>
        /// <param name="destination">The destination path for the new image. JPEG, PNG, GIF, BMP and TIFF formats are supported.</param>
        /// <returns>True if the image was successfully saved. False otherwise.</returns>
        public static bool Save(this DepthFrame depthFrame, BodyIndexFrame bodyIndexFrame, string path)
        {
            var bitmap = depthFrame.ToBitmap(bodyIndexFrame);

            return(_capture.Save(bitmap, path));
        }
Esempio n. 5
0
        /// <summary>
        /// Converts the specified depth frame to a bitmap and saves it to the specified location.
        /// </summary>
        /// <param name="source">The source depth frame.</param>
        /// <param name="destination">The destination path for the new image. JPEG, PNG, GIF, BMP and TIFF formats are supported.</param>
        /// <returns>True if the frame was successfully saved. False otherwise.</returns>
        public static bool Save(this DepthFrame frame, string path)
        {
            var bitmap = frame.ToBitmap();

            return(_capture.Save(bitmap, path));
        }
Esempio n. 6
0
        /// <summary>
        /// Converts the specified depth and body index frames to a bitmap and saves it to the specified location.
        /// </summary>
        /// <param name="depthFrame">The source depth frame.</param>
        /// <param name="bodyIndexFrame">The source body index frame.</param>
        /// <param name="destination">The destination storage file for the image. JPEG, PNG, GIF, BMP and TIFF formats are supported.</param>
        /// <param name="width">The width of the image file.</param>
        /// <param name="height">The height of the image file.</param>
        /// <returns>True if the image was successfully saved. False otherwise.</returns>
        public static async Task <bool> Save(this DepthFrame depthFrame, BodyIndexFrame bodyIndexFrame, StorageFile destination, int width, int height)
        {
            var bitmap = depthFrame.ToBitmap(bodyIndexFrame);

            return(await _capture.Save(bitmap, destination, width, height));
        }
Esempio n. 7
0
        /// <summary>
        /// Converts the specified depth frame to a bitmap and saves it to the specified location.
        /// </summary>
        /// <param name="frame">The source depth frame.</param>
        /// <param name="destination">The destination storage file for the image. JPEG, PNG, GIF, BMP and TIFF formats are supported.</param>
        /// <returns>True if the frame was successfully saved. False otherwise.</returns>
        public static async Task <bool> Save(this DepthFrame frame, StorageFile destination)
        {
            var bitmap = frame.ToBitmap();

            return(await _capture.Save(bitmap, destination));
        }
 public static Bitmap ToBitmap(this DepthFrame image)
 {
     return(image.ToBitmap(System.Drawing.Imaging.PixelFormat.Format16bppRgb565));
 }
Esempio n. 9
0
        /// <summary>
        /// Converts the specified depth and body index frames to a bitmap and saves it to the specified location.
        /// </summary>
        /// <param name="depthFrame">The source depth frame.</param>
        /// <param name="bodyIndexFrame">The source body index frame.</param>
        /// <param name="destination">The destination path for the image. JPEG, PNG, GIF, BMP and TIFF formats are supported.</param>
        /// <param name="width">The width of the image file.</param>
        /// <param name="height">The height of the image file.</param>
        /// <returns>True if the image was successfully saved. False otherwise.</returns>
        public static async Task <bool> Save(this DepthFrame depthFrame, BodyIndexFrame bodyIndexFrame, string path, int width, int height)
        {
            var bitmap = depthFrame.ToBitmap(bodyIndexFrame);

            return(await _capture.Save(bitmap, path, width, height));
        }
Esempio n. 10
0
        /// <summary>
        /// Converts the specified depth frame to a bitmap and saves it to the specified location.
        /// </summary>
        /// <param name="source">The source depth frame.</param>
        /// <param name="destination">The destination path for the new image. JPEG, PNG, GIF, BMP and TIFF formats are supported.</param>
        /// <returns>True if the frame was successfully saved. False otherwise.</returns>
        public static async Task <bool> Save(this DepthFrame frame, string path)
        {
            var bitmap = frame.ToBitmap();

            return(await _capture.Save(bitmap, path));
        }
        public void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var reference = e.FrameReference.AcquireFrame();

            // Color
            colorFrame = reference.ColorFrameReference.AcquireFrame();
            {
                if (colorFrame != null)
                {

                    if (_mode == CameraMode.Color)
                    {
                        camera.Source = colorFrame.ToBitmap();
                    }
                }
            }

            // Depth
            depthFrame = reference.DepthFrameReference.AcquireFrame();
            {
                if (depthFrame != null)
                {
                    if (_mode == CameraMode.Depth)
                    {
                        cameraDepth.Source = depthFrame.ToBitmap();
                    }
                }
            }

            Ellipse ellipse1 = new Ellipse
            {
                Fill = Brushes.Green,
                Width = 30,
                Height = 30
            };
            Ellipse ellipse2 = new Ellipse
            {
                Fill = Brushes.Red,
                Width = 30,
                Height = 30
            };

            Ellipse ellipse3 = new Ellipse
            {
                Fill = Brushes.Green,
                Width = 30,
                Height = 30
            };
            Ellipse ellipse4 = new Ellipse
            {
                Fill = Brushes.Red,
                Width = 30,
                Height = 30
            };

            Ellipse ellipse5 = new Ellipse
            {
                Fill = Brushes.Green,
                Width = 30,
                Height = 30
            };
            Ellipse ellipse6 = new Ellipse
            {
                Fill = Brushes.Red,
                Width = 30,
                Height = 30
            };

            Ellipse ellipse7 = new Ellipse
            {
                Fill = Brushes.Green,
                Width = 30,
                Height = 30
            };
            Ellipse ellipse8 = new Ellipse
            {
                Fill = Brushes.Red,
                Width = 30,
                Height = 30
            };

            Ellipse ellipse9 = new Ellipse
            {
                Fill = Brushes.Green,
                Width = 30,
                Height = 30
            };
            Ellipse ellipse10 = new Ellipse
            {
                Fill = Brushes.Red,
                Width = 30,
                Height = 30
            };

            Ellipse ellipse11 = new Ellipse
            {
                Fill = Brushes.Green,
                Width = 30,
                Height = 30
            };
            Ellipse ellipse12 = new Ellipse
            {
                Fill = Brushes.Red,
                Width = 30,
                Height = 30
            };

            if (finishedCountdown)
            {
                if (_mode == CameraMode.Color)
                {
                    camera.Visibility = Visibility.Visible;
                    canvas.Visibility = Visibility.Visible;
                    cameraDepth.Visibility = Visibility.Hidden;
                    canvasDepth.Visibility = Visibility.Hidden;
                    finishedCountdown = false;
                }

                if (_mode == CameraMode.Depth)
                {
                    camera.Visibility = Visibility.Hidden;
                    canvas.Visibility = Visibility.Hidden;
                    cameraDepth.Visibility = Visibility.Visible;
                    canvasDepth.Visibility = Visibility.Visible;
                    finishedCountdown = false;
                }
            }

            // Body
            using (var frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame != null)
                {

                    this.canvas.Children.Clear();
                    this.canvasDepth.Children.Clear();

                    _bodies = new Body[frame.BodyFrameSource.BodyCount];

                    frame.GetAndRefreshBodyData(_bodies);

                    //int bodyIndex = 0;
                    foreach (var body in _bodies)
                    {
                        //if (bodyIndex != 0) continue;
                        //bodyIndex++;
                        var cameraSpacePoint = new CameraSpacePoint();

                        DepthSpacePoint depthPointWristLeft = new DepthSpacePoint();
                        DepthSpacePoint depthPointWristRight = new DepthSpacePoint();
                        DepthSpacePoint depthPointHead = new DepthSpacePoint();
                        DepthSpacePoint depthPointSpineMid = new DepthSpacePoint();
                        DepthSpacePoint depthPointKneeLeft = new DepthSpacePoint();
                        DepthSpacePoint depthPointKneeRight = new DepthSpacePoint();

                        ColorSpacePoint colorPointWristLeft = new ColorSpacePoint();
                        ColorSpacePoint colorPointWristRight = new ColorSpacePoint();
                        ColorSpacePoint colorPointHead = new ColorSpacePoint();
                        ColorSpacePoint colorPointSpineMid = new ColorSpacePoint();
                        ColorSpacePoint colorPointKneeLeft = new ColorSpacePoint();
                        ColorSpacePoint colorPointKneeRight = new ColorSpacePoint();

                        if (body.IsTracked)
                        {
                            BodyStructure currentFrameBody = new BodyStructure();

                            var lines = new List<string>();

                            foreach (var joint in body.Joints.Values)
                            {
                                cameraSpacePoint.X = joint.Position.X;//(float)currentFrameBody.currentFrameBody[joint.JointType].X;
                                cameraSpacePoint.Y = joint.Position.Y; //(float)currentFrameBody.currentFrameBody[joint.JointType].Y;
                                cameraSpacePoint.Z = joint.Position.Z; //(float)currentFrameBody.currentFrameBody[joint.JointType].Z;

                                if (PressSpaced && !escape && jointsOfInterest.Contains(joint.JointType))
                                {
                                    curNumOfFrames++;
                                    distanceSum[joint.JointType] += cameraSpacePoint.Z;
                                    meanDistanceToSensor[joint.JointType] = distanceSum[joint.JointType] / ( (curNumOfFrames/6) + 1);
                                }
                                else if(escape && movementVector != null && jointsOfInterest.Contains(joint.JointType))
                                {
                                    distanceScale[joint.JointType] = cameraSpacePoint.Z / meanDistanceToSensor[joint.JointType];
                                }

                                var colorPoint = _sensor.CoordinateMapper.MapCameraPointToColorSpace(cameraSpacePoint);
                                var depthPoint = _sensor.CoordinateMapper.MapCameraPointToDepthSpace(cameraSpacePoint);

                                if (_mode == CameraMode.Depth)
                                {
                                    /*  Ellipse ellipseBlue = new Ellipse
                                      {
                                          Fill = Brushes.Blue,
                                          Width = 10,
                                          Height = 10
                                      };
                                      var xPos = depthPoint.X - ellipseBlue.Width / 2;
                                      var yPos = depthPoint.Y - ellipseBlue.Height / 2;

                                      if (xPos >= 0 && xPos < this.canvasDepth.ActualWidth &&
                                          yPos >= 0 && yPos < this.canvasDepth.ActualHeight)
                                      {
                                          Canvas.SetLeft(ellipseBlue, xPos);
                                          Canvas.SetTop(ellipseBlue, yPos);

                                          canvasDepth.Children.Add(ellipseBlue);
                                      } */

                                    Extensions.DrawSkeleton(canvas, body, jointsOfInterest, _sensor);

                                    //currentFrameBody.currentFrameBody.Add(joint.JointType, new Point3D());
                                    if (jointsOfInterest.Contains(joint.JointType))
                                    {
                                        if (joint.JointType == JointType.HandLeft)
                                            depthPointWristLeft = depthPoint;

                                        else if (joint.JointType == JointType.HandRight)
                                            depthPointWristRight = depthPoint;

                                        else if (joint.JointType == JointType.Head)
                                            depthPointHead = depthPoint;

                                        else if (joint.JointType == JointType.SpineMid)
                                            depthPointSpineMid = depthPoint;

                                        else if (joint.JointType == JointType.KneeRight)
                                            depthPointKneeRight = depthPoint;

                                        else if (joint.JointType == JointType.KneeLeft)
                                            depthPointKneeLeft = depthPoint;

                                        currentFrameBody.currentFrameBody.Add(joint.JointType, new Point3D(depthPoint.X, depthPoint.Y, 0));
                                    }
                                }
                                else
                                {
                                      Ellipse ellipseBlue = new Ellipse
                                      {
                                          Fill = Brushes.Blue,
                                          Width = 10,
                                          Height = 10
                                      };
                                      var xPos = colorPoint.X - ellipseBlue.Width / 2;
                                      var yPos = colorPoint.Y - ellipseBlue.Height / 2;

                                      if (xPos >= 0 && xPos < this.canvas.ActualWidth &&
                                          yPos >= 0 && yPos < this.canvas.ActualHeight)
                                      {
                                          Canvas.SetLeft(ellipseBlue, xPos);
                                          Canvas.SetTop(ellipseBlue, yPos);

                                          canvas.Children.Add(ellipseBlue);
                                      }

                                    Extensions.DrawSkeleton(canvas, body, jointsOfInterest, _sensor);

                                    //currentFrameBody.currentFrameBody.Add(joint.JointType, new Point3D());
                                    if (jointsOfInterest.Contains(joint.JointType))
                                    {
                                        if (joint.JointType == JointType.HandLeft)
                                            colorPointWristLeft = colorPoint;

                                        else if (joint.JointType == JointType.HandRight)
                                            colorPointWristRight = colorPoint;

                                        else if (joint.JointType == JointType.Head)
                                            colorPointHead = colorPoint;

                                        else if (joint.JointType == JointType.SpineMid)
                                            colorPointSpineMid = colorPoint;

                                        else if (joint.JointType == JointType.KneeRight)
                                            colorPointKneeRight = colorPoint;

                                        else if (joint.JointType == JointType.KneeLeft)
                                            colorPointKneeLeft = colorPoint;

                                        var pointCurJoint = new Point3D(colorPoint.X, colorPoint.Y, 0);
                                        this.dictAllMovementPositions[joint.JointType].Add(pointCurJoint);
                                        currentFrameBody.currentFrameBody.Add(joint.JointType, pointCurJoint);
                                    }
                                }
                            }

                            /*TODO - null or empty Dictionary  (.Count == 0)*/
                            //  if (movementVector == null)
                            if (PressSpaced && !escape)
                            {
                                if (movementVector != null && jointsChange)
                                {
                                    movementVector.Clear();
                                }

                                jointsChange = false;
                                movementVector = record.GetMovementVectors(currentFrameBody);

                            }
                            //else if(movementVector != null)
                            else if (escape && movementVector != null)
                            {
                                var curFrameResult = benchPress.ValidateCurrentSkeletonFrame(movementVector, currentFrameBody, distanceScale);
                                var resultWristLeft = curFrameResult.BoneStates[JointType.HandLeft];
                                var resultWristRight = curFrameResult.BoneStates[JointType.HandRight];

                                Extensions.DrawSkeleton(canvas, body, jointsOfInterest, _sensor);

                                if (recordVisualization)
                                {
                                    recordVisualization = false;

                                    Color colorHandLeft = Color.FromArgb(255, 35, 63, 147);
                                    Color colorHandRight = Color.FromArgb(255, 0, 136, 170);
                                    Color colorHead = Color.FromArgb(255, 193, 84, 151);
                                    Color colorSpineMid = Color.FromArgb(255, 238, 198, 20);
                                    Color colorKneeLeft = Color.FromArgb(255, 116, 81, 67);
                                    Color colorKneeRight = Color.FromArgb(255, 94, 58, 106);

                                    foreach (var joy in this.dictAllMovementPositions)
                                    {
                                        Color fillColor = Color.FromArgb(255, 255, 255, 255);
                                        switch (joy.Key)
                                        {
                                            case JointType.HandLeft:
                                                fillColor = colorHandLeft;
                                                break;

                                            case JointType.HandRight:
                                                fillColor = colorHandRight;
                                                break;

                                            case JointType.Head:
                                                fillColor = colorHead;
                                                break;

                                            case JointType.SpineMid:
                                                fillColor = colorSpineMid;
                                                break;

                                            case JointType.KneeLeft:
                                                fillColor = colorKneeLeft;
                                                break;

                                            case JointType.KneeRight:
                                                fillColor = colorKneeRight;
                                                break;
                                        }

                                        foreach (var point in joy.Value)
                                        {

                                           float opacityFactor =  joy.Value.Count / 255  ;
                                            if (opacityFactor == 0.0f)
                                                opacityFactor = 1.0f;

                                            int alpha = (int)opacityFactor * (joy.Value.IndexOf(point) + 1);

                                            fillColor = SetTransparency(alpha, fillColor);

                                            Brush fill = new SolidColorBrush(fillColor);

                                            Ellipse newEllipse = new Ellipse
                                            {
                                                Fill = fill,
                                                Width = 20,
                                                Height = 20
                                            };

                                            var xPosRecord = point.X - newEllipse.Width / 2;
                                            var yPosRecord = point.Y - newEllipse.Height / 2;

                                            if (xPosRecord >= 0 && xPosRecord < this.Record.ActualWidth &&
                                                yPosRecord >= 0 && yPosRecord < this.Record.ActualHeight)
                                            {
                                                Canvas.SetLeft(newEllipse, xPosRecord);
                                                Canvas.SetTop(newEllipse, yPosRecord);

                                                Record.Children.Add(newEllipse);
                                            }
                                        }
                                    }
                                }

                                if (sixJoints.IsChecked == true)
                                {
                                    var resultHead = curFrameResult.BoneStates[JointType.Head];
                                    var resultSpineMid = curFrameResult.BoneStates[JointType.SpineMid];
                                    var resultKneeLeft = curFrameResult.BoneStates[JointType.KneeLeft];
                                    var resultKneeRight = curFrameResult.BoneStates[JointType.KneeRight];

                                    if (_mode == CameraMode.Depth)
                                    {
                                        if (resultSpineMid == SkeletonBoneState.Matched)
                                        {
                                            var xPosMid = depthPointSpineMid.X - ellipse7.Width / 2;
                                            var yPosMid = depthPointSpineMid.Y - ellipse7.Height / 2;

                                            if (xPosMid >= 0 && xPosMid < this.canvasDepth.ActualWidth &&
                                                yPosMid >= 0 && yPosMid < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse7, xPosMid);
                                                Canvas.SetTop(ellipse7, yPosMid);

                                                canvasDepth.Children.Add(ellipse7);
                                            }
                                        }
                                        else
                                        {
                                            var xPosMid = depthPointSpineMid.X - ellipse8.Width / 2;
                                            var yPosMid = depthPointSpineMid.Y - ellipse8.Height / 2;

                                            if (xPosMid >= 0 && xPosMid < this.canvasDepth.ActualWidth &&
                                                yPosMid >= 0 && yPosMid < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse8, xPosMid);
                                                Canvas.SetTop(ellipse8, yPosMid);

                                                canvasDepth.Children.Add(ellipse8);
                                            }
                                        }

                                        if (resultKneeLeft == SkeletonBoneState.Matched)
                                        {
                                            var xPosKneeLeft = depthPointKneeLeft.X - ellipse9.Width / 2;
                                            var yPosKneeLeft = depthPointKneeLeft.Y - ellipse9.Height / 2;

                                            if (xPosKneeLeft >= 0 && xPosKneeLeft < this.canvasDepth.ActualWidth &&
                                                yPosKneeLeft >= 0 && yPosKneeLeft < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse9, xPosKneeLeft);
                                                Canvas.SetTop(ellipse9, yPosKneeLeft);

                                                canvasDepth.Children.Add(ellipse9);
                                            }
                                        }
                                        else
                                        {
                                            var xPosKneeLeft = depthPointKneeLeft.X - ellipse10.Width / 2;
                                            var yPosKneeLeft = depthPointKneeLeft.Y - ellipse10.Height / 2;

                                            if (xPosKneeLeft >= 0 && xPosKneeLeft < this.canvasDepth.ActualWidth &&
                                                yPosKneeLeft >= 0 && yPosKneeLeft < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse10, xPosKneeLeft);
                                                Canvas.SetTop(ellipse10, yPosKneeLeft);

                                                canvasDepth.Children.Add(ellipse10);
                                            }
                                        }

                                        if (resultKneeRight == SkeletonBoneState.Matched)
                                        {
                                            var xPosKneeRight = depthPointKneeRight.X - ellipse11.Width / 2;
                                            var yPosKneeRight = depthPointKneeRight.Y - ellipse11.Height / 2;

                                            if (xPosKneeRight >= 0 && xPosKneeRight < this.canvasDepth.ActualWidth &&
                                                yPosKneeRight >= 0 && yPosKneeRight < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse11, xPosKneeRight);
                                                Canvas.SetTop(ellipse11, yPosKneeRight);

                                                canvasDepth.Children.Add(ellipse11);
                                            }
                                        }
                                        else
                                        {
                                            var xPosKneeRight = depthPointKneeRight.X - ellipse12.Width / 2;
                                            var yPosKneeRight = depthPointKneeRight.Y - ellipse12.Height / 2;

                                            if (xPosKneeRight >= 0 && xPosKneeRight < this.canvasDepth.ActualWidth &&
                                                yPosKneeRight >= 0 && yPosKneeRight < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse12, xPosKneeRight);
                                                Canvas.SetTop(ellipse12, yPosKneeRight);

                                                canvasDepth.Children.Add(ellipse12);
                                            }
                                        }

                                        if (resultHead == SkeletonBoneState.Matched)
                                        {
                                            var xPosHead = depthPointHead.X - ellipse5.Width / 2;
                                            var yPosHead = depthPointHead.Y - ellipse5.Height / 2;

                                            if (xPosHead >= 0 && xPosHead < this.canvasDepth.ActualWidth &&
                                                yPosHead >= 0 && yPosHead < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse5, xPosHead);
                                                Canvas.SetTop(ellipse5, yPosHead);

                                                canvasDepth.Children.Add(ellipse5);
                                            }

                                        }
                                        else
                                        {
                                            var xPosHead = depthPointHead.X - ellipse6.Width / 2;
                                            var yPosHead = depthPointHead.Y - ellipse6.Height / 2;

                                            if (xPosHead >= 0 && xPosHead < this.canvasDepth.ActualWidth &&
                                                yPosHead >= 0 && yPosHead < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse6, xPosHead);
                                                Canvas.SetTop(ellipse6, yPosHead);

                                                canvasDepth.Children.Add(ellipse6);
                                            }
                                        }

                                        if (resultWristLeft == SkeletonBoneState.Matched)
                                        {
                                            var xPosLeft = depthPointWristLeft.X - ellipse1.Width / 2;
                                            var yPosLeft = depthPointWristLeft.Y - ellipse1.Height / 2;

                                            if (xPosLeft >= 0 && xPosLeft < this.canvasDepth.ActualWidth &&
                                                yPosLeft >= 0 && yPosLeft < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse1, xPosLeft);
                                                Canvas.SetTop(ellipse1, yPosLeft);

                                                canvasDepth.Children.Add(ellipse1);
                                            }

                                        }
                                        else
                                        {
                                            var xPosLeft = depthPointWristLeft.X - ellipse2.Width / 2;
                                            var yPosLeft = depthPointWristLeft.Y - ellipse2.Height / 2;

                                            if (xPosLeft >= 0 && xPosLeft < this.canvasDepth.ActualWidth &&
                                                yPosLeft >= 0 && yPosLeft < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse2, xPosLeft);
                                                Canvas.SetTop(ellipse2, yPosLeft);

                                                canvasDepth.Children.Add(ellipse2);
                                            }
                                        }

                                        if (resultWristRight == SkeletonBoneState.Matched)
                                        {
                                            var xPosRight = depthPointWristRight.X - ellipse3.Width / 2;
                                            var yPosRight = depthPointWristRight.Y - ellipse3.Height / 2;

                                            if (xPosRight >= 0 && xPosRight < this.canvasDepth.ActualWidth &&
                                                yPosRight >= 0 && yPosRight < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse3, xPosRight);
                                                Canvas.SetTop(ellipse3, yPosRight);

                                                canvasDepth.Children.Add(ellipse3);
                                            }

                                        }
                                        else
                                        {
                                            var xPosRight = depthPointWristRight.X - ellipse4.Width / 2;
                                            var yPosRight = depthPointWristRight.Y - ellipse4.Height / 2;

                                            if (xPosRight >= 0 && xPosRight < this.canvasDepth.ActualWidth &&
                                                yPosRight >= 0 && yPosRight < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse4, xPosRight);
                                                Canvas.SetTop(ellipse4, yPosRight);

                                                canvasDepth.Children.Add(ellipse4);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (resultSpineMid == SkeletonBoneState.Matched)
                                        {
                                            var xPosMid = colorPointSpineMid.X - ellipse7.Width / 2;
                                            var yPosMid = colorPointSpineMid.Y - ellipse7.Height / 2;

                                            if (xPosMid >= 0 && xPosMid < this.canvas.ActualWidth &&
                                                yPosMid >= 0 && yPosMid < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse7, xPosMid);
                                                Canvas.SetTop(ellipse7, yPosMid);

                                                canvas.Children.Add(ellipse7);
                                            }
                                        }
                                        else
                                        {
                                            var xPosMid = colorPointSpineMid.X - ellipse8.Width / 2;
                                            var yPosMid = colorPointSpineMid.Y - ellipse8.Height / 2;

                                            if (xPosMid >= 0 && xPosMid < this.canvas.ActualWidth &&
                                                yPosMid >= 0 && yPosMid < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse8, xPosMid);
                                                Canvas.SetTop(ellipse8, yPosMid);

                                                canvas.Children.Add(ellipse8);
                                            }
                                        }

                                        if (resultKneeLeft == SkeletonBoneState.Matched)
                                        {
                                            var xPosKneeLeft = colorPointKneeLeft.X - ellipse9.Width / 2;
                                            var yPosKneeLeft = colorPointKneeLeft.Y - ellipse9.Height / 2;

                                            if (xPosKneeLeft >= 0 && xPosKneeLeft < this.canvas.ActualWidth &&
                                                yPosKneeLeft >= 0 && yPosKneeLeft < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse9, xPosKneeLeft);
                                                Canvas.SetTop(ellipse9, yPosKneeLeft);

                                                canvas.Children.Add(ellipse9);
                                            }
                                        }
                                        else
                                        {
                                            var xPosKneeLeft = colorPointKneeLeft.X - ellipse10.Width / 2;
                                            var yPosKneeLeft = colorPointKneeLeft.Y - ellipse10.Height / 2;

                                            if (xPosKneeLeft >= 0 && xPosKneeLeft < this.canvas.ActualWidth &&
                                                yPosKneeLeft >= 0 && yPosKneeLeft < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse10, xPosKneeLeft);
                                                Canvas.SetTop(ellipse10, yPosKneeLeft);

                                                canvas.Children.Add(ellipse10);
                                            }
                                        }

                                        if (resultKneeRight == SkeletonBoneState.Matched)
                                        {
                                            var xPosKneeRight = colorPointKneeRight.X - ellipse11.Width / 2;
                                            var yPosKneeRight = colorPointKneeRight.Y - ellipse11.Height / 2;

                                            if (xPosKneeRight >= 0 && xPosKneeRight < this.canvas.ActualWidth &&
                                                yPosKneeRight >= 0 && yPosKneeRight < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse11, xPosKneeRight);
                                                Canvas.SetTop(ellipse11, yPosKneeRight);

                                                canvas.Children.Add(ellipse11);
                                            }
                                        }
                                        else
                                        {
                                            var xPosKneeRight = colorPointKneeRight.X - ellipse12.Width / 2;
                                            var yPosKneeRight = colorPointKneeRight.Y - ellipse12.Height / 2;

                                            if (xPosKneeRight >= 0 && xPosKneeRight < this.canvas.ActualWidth &&
                                                yPosKneeRight >= 0 && yPosKneeRight < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse12, xPosKneeRight);
                                                Canvas.SetTop(ellipse12, yPosKneeRight);

                                                canvas.Children.Add(ellipse12);
                                            }
                                        }

                                        if (resultHead == SkeletonBoneState.Matched)
                                        {
                                            var xPosHead = colorPointHead.X - ellipse5.Width / 2;
                                            var yPosHead = colorPointHead.Y - ellipse5.Height / 2;

                                            if (xPosHead >= 0 && xPosHead < this.canvas.ActualWidth &&
                                                yPosHead >= 0 && yPosHead < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse5, xPosHead);
                                                Canvas.SetTop(ellipse5, yPosHead);

                                                canvas.Children.Add(ellipse5);
                                            }

                                        }
                                        else
                                        {
                                            var xPosHead = colorPointHead.X - ellipse6.Width / 2;
                                            var yPosHead = colorPointHead.Y - ellipse6.Height / 2;

                                            if (xPosHead >= 0 && xPosHead < this.canvas.ActualWidth &&
                                                yPosHead >= 0 && yPosHead < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse6, xPosHead);
                                                Canvas.SetTop(ellipse6, yPosHead);

                                                canvas.Children.Add(ellipse6);
                                            }
                                        }

                                        if (resultWristLeft == SkeletonBoneState.Matched)
                                        {
                                            var xPosLeft = colorPointWristLeft.X - ellipse1.Width / 2;
                                            var yPosLeft = colorPointWristLeft.Y - ellipse1.Height / 2;

                                            if (xPosLeft >= 0 && xPosLeft < this.canvas.ActualWidth &&
                                                yPosLeft >= 0 && yPosLeft < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse1, xPosLeft);
                                                Canvas.SetTop(ellipse1, yPosLeft);

                                                canvas.Children.Add(ellipse1);
                                            }

                                        }
                                        else
                                        {
                                            var xPosLeft = colorPointWristLeft.X - ellipse2.Width / 2;
                                            var yPosLeft = colorPointWristLeft.Y - ellipse2.Height / 2;

                                            if (xPosLeft >= 0 && xPosLeft < this.canvas.ActualWidth &&
                                                yPosLeft >= 0 && yPosLeft < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse2, xPosLeft);
                                                Canvas.SetTop(ellipse2, yPosLeft);

                                                canvas.Children.Add(ellipse2);
                                            }
                                        }

                                        if (resultWristRight == SkeletonBoneState.Matched)
                                        {
                                            var xPosRight = colorPointWristRight.X - ellipse3.Width / 2;
                                            var yPosRight = colorPointWristRight.Y - ellipse3.Height / 2;

                                            if (xPosRight >= 0 && xPosRight < this.canvas.ActualWidth &&
                                                yPosRight >= 0 && yPosRight < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse3, xPosRight);
                                                Canvas.SetTop(ellipse3, yPosRight);

                                                canvas.Children.Add(ellipse3);
                                            }

                                        }
                                        else
                                        {
                                            var xPosRight = colorPointWristRight.X - ellipse4.Width / 2;
                                            var yPosRight = colorPointWristRight.Y - ellipse4.Height / 2;

                                            if (xPosRight >= 0 && xPosRight < this.canvas.ActualWidth &&
                                                yPosRight >= 0 && yPosRight < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse4, xPosRight);
                                                Canvas.SetTop(ellipse4, yPosRight);

                                                canvas.Children.Add(ellipse4);
                                            }
                                        }
                                    }
                                }

                                else
                                {
                                    if (_mode == CameraMode.Depth)
                                    {
                                        if (resultWristLeft == SkeletonBoneState.Matched)
                                        {
                                            var xPosLeft = depthPointWristLeft.X - ellipse1.Width / 2;
                                            var yPosLeft = depthPointWristLeft.Y - ellipse1.Height / 2;

                                            if (xPosLeft >= 0 && xPosLeft < this.canvasDepth.ActualWidth &&
                                                yPosLeft >= 0 && yPosLeft < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse1, xPosLeft);
                                                Canvas.SetTop(ellipse1, yPosLeft);

                                                canvasDepth.Children.Add(ellipse1);
                                            }

                                        }
                                        else
                                        {
                                            var xPosLeft = depthPointWristLeft.X - ellipse2.Width / 2;
                                            var yPosLeft = depthPointWristLeft.Y - ellipse2.Height / 2;

                                            if (xPosLeft >= 0 && xPosLeft < this.canvasDepth.ActualWidth &&
                                                yPosLeft >= 0 && yPosLeft < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse2, xPosLeft);
                                                Canvas.SetTop(ellipse2, yPosLeft);

                                                canvasDepth.Children.Add(ellipse2);
                                            }
                                        }

                                        if (resultWristRight == SkeletonBoneState.Matched)
                                        {
                                            var xPosRight = depthPointWristRight.X - ellipse3.Width / 2;
                                            var yPosRight = depthPointWristRight.Y - ellipse3.Height / 2;

                                            if (xPosRight >= 0 && xPosRight < this.canvasDepth.ActualWidth &&
                                                yPosRight >= 0 && yPosRight < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse3, xPosRight);
                                                Canvas.SetTop(ellipse3, yPosRight);

                                                canvasDepth.Children.Add(ellipse3);
                                            }

                                        }
                                        else
                                        {
                                            var xPosRight = depthPointWristRight.X - ellipse4.Width / 2;
                                            var yPosRight = depthPointWristRight.Y - ellipse4.Height / 2;

                                            if (xPosRight >= 0 && xPosRight < this.canvasDepth.ActualWidth &&
                                                yPosRight >= 0 && yPosRight < this.canvasDepth.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse4, xPosRight);
                                                Canvas.SetTop(ellipse4, yPosRight);

                                                canvasDepth.Children.Add(ellipse4);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (resultWristLeft == SkeletonBoneState.Matched)
                                        {
                                            var xPosLeft = colorPointWristLeft.X - ellipse1.Width / 2;
                                            var yPosLeft = colorPointWristLeft.Y - ellipse1.Height / 2;

                                            if (xPosLeft >= 0 && xPosLeft < this.canvas.ActualWidth &&
                                                yPosLeft >= 0 && yPosLeft < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse1, xPosLeft);
                                                Canvas.SetTop(ellipse1, yPosLeft);

                                                canvas.Children.Add(ellipse1);
                                            }

                                        }
                                        else
                                        {
                                            var xPosLeft = colorPointWristLeft.X - ellipse2.Width / 2;
                                            var yPosLeft = colorPointWristLeft.Y - ellipse2.Height / 2;

                                            if (xPosLeft >= 0 && xPosLeft < this.canvas.ActualWidth &&
                                                yPosLeft >= 0 && yPosLeft < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse2, xPosLeft);
                                                Canvas.SetTop(ellipse2, yPosLeft);

                                                canvas.Children.Add(ellipse2);
                                            }
                                        }

                                        if (resultWristRight == SkeletonBoneState.Matched)
                                        {
                                            var xPosRight = colorPointWristRight.X - ellipse3.Width / 2;
                                            var yPosRight = colorPointWristRight.Y - ellipse3.Height / 2;

                                            if (xPosRight >= 0 && xPosRight < this.canvas.ActualWidth &&
                                                yPosRight >= 0 && yPosRight < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse3, xPosRight);
                                                Canvas.SetTop(ellipse3, yPosRight);

                                                canvas.Children.Add(ellipse3);
                                            }

                                        }
                                        else
                                        {
                                            var xPosRight = colorPointWristRight.X - ellipse4.Width / 2;
                                            var yPosRight = colorPointWristRight.Y - ellipse4.Height / 2;

                                            if (xPosRight >= 0 && xPosRight < this.canvas.ActualWidth &&
                                                yPosRight >= 0 && yPosRight < this.canvas.ActualHeight)
                                            {
                                                Canvas.SetLeft(ellipse4, xPosRight);
                                                Canvas.SetTop(ellipse4, yPosRight);

                                                canvas.Children.Add(ellipse4);
                                            }
                                        }
                                    }
                                }

                            }
                            else
                            {
                                escape = false;
                            }
                        }
                    }
                }
            }

            if (depthFrame != null)
                depthFrame.Dispose();
            depthFrame = null;
            if (colorFrame != null)
                colorFrame.Dispose();
            colorFrame = null;
        }