示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (SkeletonFrame frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                {
                    return;
                }

                // resize the skeletons array if needed
                if (skeletons.Length != frame.SkeletonArrayLength)
                {
                    skeletons = new Skeleton[frame.SkeletonArrayLength];
                }

                // get the skeleton data
                frame.CopySkeletonDataTo(skeletons);

                foreach (var skeleton in skeletons)
                {
                    // skip the skeleton if it is not being tracked
                    if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                    {
                        continue;
                    }

                    // update the gesture controller
                    gestureController.UpdateAllGestures(skeleton);
                }
            }
        }
示例#2
0
        private void OnSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (SkeletonFrame frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                {
                    return;
                }

                // resize the skeletons array if needed
                if (skeletons.Length != frame.SkeletonArrayLength)
                {
                    skeletons = new Skeleton[frame.SkeletonArrayLength];
                }

                // get the skeleton data
                frame.CopySkeletonDataTo(skeletons);
                using (DrawingContext dc = this.drawingGroup.Open())
                {
                    dc.DrawRectangle(Brushes.Transparent, null, new Rect(0, 0, dI.Width, dI.Height));
                    foreach (var skeleton in skeletons)
                    {
                        // skip the skeleton if it is not being tracked
                        if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                        {
                            continue;
                        }

                        // update the gesture controller
                        gestureController.UpdateAllGestures(skeleton);
                        drawCursorBox(skeleton, dc);
                    }
                }
            }
        }
示例#3
0
        void sensor_SkeletonFrameReady(object sender, BodyFrameArrivedEventArgs e)
        {
            Joint Spine     = new Joint();
            Joint LeftFeet  = new Joint();
            Joint RightFeet = new Joint();

            BodyFrameReference frameReference = e.FrameReference;

            BodyFrame frame = frameReference.AcquireFrame();


            if (frame != null)
            {
                // BodyFrame is IDisposable
                using (frame)
                {
                    if (this.bodies == null)
                    {
                        this.bodies = new Body[frame.BodyCount];
                    }

                    frame.GetAndRefreshBodyData(this.bodies);

                    Body skeleton = GetPrimarySkeleton(this.bodies);

                    if (skeleton != null)
                    {
                        Spine     = skeleton.Joints[JointType.SpineMid];
                        LeftFeet  = skeleton.Joints[JointType.FootLeft];
                        RightFeet = skeleton.Joints[JointType.FootRight];

                        //Recognize Gestures either way
                        // update the gesture controller
                        gestureController.UpdateAllGestures(skeleton);

                        if (LeftFeet.TrackingState == TrackingState.Tracked && RightFeet.TrackingState == TrackingState.Tracked)
                        {
                            if (Globals.setCoordinates)
                            {
                                double averageWidth  = (LeftFeet.Position.Z + RightFeet.Position.Z) / 2;
                                double averageLength = (LeftFeet.Position.X + RightFeet.Position.X) / 2;
                                SetCoordinates(averageWidth, averageLength);
                                Globals.setCoordinates = false;
                            }
                        }
                        else
                        {
                            CurrentLocation = -1;
                        }
                        //activeRecognizer.Recognize(sender, frame, this._FrameSkeletons);
                    }
                    else
                    {
                        CurrentLocation = -1;
                    }
                }
            }
        }
示例#4
0
        //private void HttpPost()
        //{
        //    Console.WriteLine("testing");
        //    // Create a request using a URL that can receive a post.
        //    WebRequest request = WebRequest.Create("http://www.contoso.com/PostAccepter.aspx ");
        //    // Set the Method property of the request to POST.
        //    request.Method = "POST";
        //    // Create POST data and convert it to a byte array.
        //    string postData = "This is a test that posts this string to a Web server.";
        //    byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        //    // Set the ContentType property of the WebRequest.
        //    request.ContentType = "application/x-www-form-urlencoded";
        //    // Set the ContentLength property of the WebRequest.
        //    request.ContentLength = byteArray.Length;
        //    // Get the request stream.
        //    Stream dataStream = request.GetRequestStream();
        //    // Write the data to the request stream.
        //    dataStream.Write(byteArray, 0, byteArray.Length);
        //    // Close the Stream object.
        //    dataStream.Close();
        //    // Get the response.
        //    WebResponse response = request.GetResponse();
        //    // Display the status.
        //    Console.WriteLine(((HttpWebResponse)response).StatusDescription);
        //    // Get the stream containing content returned by the server.
        //    dataStream = response.GetResponseStream();
        //    // Open the stream using a StreamReader for easy access.
        //    StreamReader reader = new StreamReader(dataStream);
        //    // Read the content.
        //    string responseFromServer = reader.ReadToEnd();
        //    // Display the content.
        //    Console.WriteLine(responseFromServer);
        //    // Clean up the streams.
        //    reader.Close();
        //    dataStream.Close();
        //    response.Close();
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (SkeletonFrame frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                {
                    return;
                }

                // resize the skeletons array if needed
                if (skeletons.Length != frame.SkeletonArrayLength)
                {
                    skeletons = new Skeleton[frame.SkeletonArrayLength];
                }
                // get the skeleton data
                frame.CopySkeletonDataTo(skeletons);
                int count = 0;
                foreach (var skeleton in skeletons)
                {
                    // skip the skeleton if it is not being tracked
                    if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                    {
                        continue;
                    }

                    count++;

                    // update the gesture controller
                    gestureController.UpdateAllGestures(skeleton);
                }

                //if (count != skCount)
                //{
                //serialPort1.Open();

                //if (count == 0)
                //{
                //    if (serialPort1.IsOpen)
                //    {
                //        serialPort1.Write("0");
                //        Console.WriteLine("LED High");
                //    }
                //}
                //else if (count > 0)
                //{
                //    if (serialPort1.IsOpen)
                //    {
                //        serialPort1.Write("1");
                //        Console.WriteLine("LED High");
                //    }
                //}
                //skCount = count;
                //serialPort1.Close();
                //}
            }
        }
示例#5
0
        void newSensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            Skeleton first = getSkeleton(e);

            if (first == null)
            {
                return;
            }
            GetCameraPoint(first, e);
            gestureController.UpdateAllGestures(first);

            // throw new NotImplementedException();
        }
示例#6
0
        private void SkeletonReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    this.lastframe = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(this.lastframe);

                    List <int> trackedids = new List <int>();

                    foreach (var skeleton in lastframe)
                    {
                        // skip the skeleton if it is not being tracked
                        if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                        {
                            continue;
                        }

                        trackedids.Add(skeleton.TrackingId);

                        // update the gesture controller
                        gestureController.UpdateAllGestures(skeleton);
                    }

                    lock (m_lock)
                    {
                        List <int> toremove = new List <int>();

                        foreach (int k in this.LastGestures.Keys)
                        {
                            if (!trackedids.Contains(k))
                            {
                                toremove.Add(k);
                            }
                        }

                        foreach (int k in toremove)
                        {
                            LastGestures.Remove(k);
                        }
                    }


                    skeletonFrame.Dispose();
                }
            }
            this.FInvalidate = true;
        }
        void kinect_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            SkeletonFrame skeletonFrame = e.OpenSkeletonFrame();

            Skeleton[] skeletonData = new Skeleton[0];

            if (skeletonFrame != null)
            {
                skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
                skeletonFrame.CopySkeletonDataTo(skeletonData);
                skeletonFrame.Dispose();
            }

            using (DrawingContext dc = this.drawingGroup.Open())
            {
                if (dc != null)
                {
                    dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                    if (skeletonData.Length > 0)
                    {
                        foreach (Skeleton skel in skeletonData)
                        {
                            RenderClippedEdges(skel, dc);

                            if (skel.TrackingState == SkeletonTrackingState.Tracked)
                            {
                                gestureController.UpdateAllGestures(skel);
                                DrawBonesAndJoints(skel, dc);
                                DebugSkel = skel;
                            }
                            else if (skel.TrackingState == SkeletonTrackingState.PositionOnly)
                            {
                                dc.DrawEllipse(
                                    centerPointBrush,
                                    null,
                                    SkeletonPointToScreen(skel.Position),
                                    BodyCenterThickness,
                                    BodyCenterThickness);
                            }
                        }
                    }

                    drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
                }
            }
        }
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnAllFrameReady(object sender, AllFramesReadyEventArgs e)
        {
            SkeletonFrame skeletonFrame = e.OpenSkeletonFrame();

            if (skeletonFrame == null)
            {
                return;
            }

            using (SkeletonFrame frame = e.OpenSkeletonFrame())
            {
                if (frame == null)
                {
                    return;
                }

                // resize the skeletons array if needed
                if (skeletons.Length != frame.SkeletonArrayLength)
                {
                    skeletons = new Skeleton[frame.SkeletonArrayLength];
                }

                // get the skeleton data
                frame.CopySkeletonDataTo(skeletons);

                foreach (var skeleton in skeletons)
                {
                    // skip the skeleton if it is not being tracked
                    if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                    {
                        continue;
                    }

                    // update the gesture controller
                    gestureController.UpdateAllGestures(skeleton, e);
                }

                if (gestureController.gestureStatus.isMakingAFast)
                {
                    Start.Text = "Is Making a fast";
                }
                else
                {
                    Start.Text = "Is not Making a fast";
                }
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            GetKinect();
            Dev.Start();
            Console.WriteLine(Dev.IsRunning);
            Dev.ElevationAngle = 5;
            Dev.SkeletonStream.Enable();

            IRelativeGestureSegment[] waveLeftSegments = new IRelativeGestureSegment[20];
            WaveLeftSegment1          waveLeftSegment  = new WaveLeftSegment1();

            for (int i = 0; i < 20; i++)
            {
                // gesture consists of the same thing 10 times
                waveLeftSegments[i] = waveLeftSegment;
            }

            GestureController g = new GestureController();

            g.AddGesture(GestureType.WaveLeft, waveLeftSegments);
            g.GestureRecognised += OnGestureRecognized;

            Console.WriteLine("start recognizing:");
            Skeleton[] skeletons = new Skeleton[6];
            while (true)
            {
                SkeletonFrame f = Dev.SkeletonStream.OpenNextFrame(50);
                if (f != null)
                {
                    f.CopySkeletonDataTo(skeletons);
                    foreach (var skeleton in skeletons)
                    {
                        // skip the skeleton if it is not being tracked
                        if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                        {
                            continue;
                        }

                        // update the gesture controller
                        g.UpdateAllGestures(skeleton);
                    }
                }
            }
        }
示例#10
0
        private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            bool dataReceived = false;

            using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    if (this.bodies == null)
                    {
                        bodies = new Body[bodyFrame.BodyCount];
                    }
                    // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
                    // As long as those body objects are not disposed and not set to null in the array,
                    // those body objects will be re-used.
                    bodyFrame.GetAndRefreshBodyData(this.bodies);
                    dataReceived = true;
                }
            }

            if (dataReceived)
            {
                var trackedBodies = bodies.Where(b => b.IsTracked == true);
                if (trackedBodies == null || trackedBodies.Count() == 0)
                {
                    return;
                }
                var activeBody = trackedBodies.OrderBy(b => b.Joints[JointType.FootLeft].Position.Z).First();
                if (activeBody != null)
                {
                    _gestureController.UpdateAllGestures(activeBody);
                }

                //foreach (Body body in this.bodies)
                //{
                //    if (body.IsTracked)
                //    {
                //        //LogHelper.GetInstance().ShowMsg(body.Joints[JointType.HandLeft].Position.X + "," + body.Joints[JointType.ElbowLeft].Position.X);
                //        _gestureController.UpdateAllGestures(body);
                //    }
                //}
            }
        }
示例#11
0
        void sensor_SkeletonFrameReady(object sender, BodyFrameArrivedEventArgs e)
        {
            Joint Spine              = new Joint();
            Joint LeftFeet           = new Joint();
            Joint RightFeet          = new Joint();
            float delta              = 0.00f;
            float leftFeetXPosition  = 0.00f;
            float rightFeetXPosition = 0.00f;

            try
            {
                BodyFrameReference frameReference = e.FrameReference;

                BodyFrame frame = frameReference.AcquireFrame();


                if (frame != null)
                {
                    // BodyFrame is IDisposable
                    using (frame)
                    {
                        if (this.bodies == null)
                        {
                            this.bodies = new Body[frame.BodyCount];
                        }
                        // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
                        // As long as those body objects are not disposed and not set to null in the array,
                        // those body objects will be re-used.
                        frame.GetAndRefreshBodyData(this.bodies);

                        Body skeleton = GetPrimarySkeleton(this.bodies);

                        if (skeleton != null)
                        {
                            if (skeleton.IsTracked)
                            {
                                delta              = 0.00f;
                                Spine              = skeleton.Joints[JointType.SpineMid];
                                LeftFeet           = skeleton.Joints[JointType.FootLeft];
                                RightFeet          = skeleton.Joints[JointType.FootRight];
                                leftFeetXPosition  = LeftFeet.Position.X - delta;
                                rightFeetXPosition = RightFeet.Position.X + delta;
                            }
                            //else if (skeleton.TrackingState == SkeletonTrackingState.PositionOnly)
                            //{
                            //    delta = 0.08f;
                            //    LeftFeet.Position = skeleton.Position;
                            //    RightFeet.Position = skeleton.Position;
                            //    Spine.Position = skeleton.Position;
                            //    leftFeetXPosition = LeftFeet.Position.X - delta;
                            //    rightFeetXPosition = RightFeet.Position.X + delta;
                            //}

                            if (skeleton.IsTracked)
                            {
                                //Recognize Gestures either way
                                // update the gesture controller
                                gestureController.UpdateAllGestures(skeleton);

                                //User being detected
                                lastUserVisibleTime = DateTime.Now;

                                if (Globals.currentAppState == RippleSystemStates.UserPlayingAnimations || Globals.currentAppState == RippleSystemStates.NoUser || Globals.currentAppState == RippleSystemStates.UserDetected)
                                {
                                    //Run Mouse Interop
                                    #region Calibrated MouseInterop
                                    if ((LeftFeet.Position.Z > frontDistance && LeftFeet.Position.Z < backDistance) && (LeftFeet.Position.X > (leftDistance) && LeftFeet.Position.X < rightDistance))
                                    {
                                        double CursorX = (((LeftFeet.Position.Z + RightFeet.Position.Z) / 2 - (frontDistance)) / (backDistance - frontDistance)) * Globals.CurrentResolution.HorizontalResolution;
                                        CursorX = Globals.CurrentResolution.HorizontalResolution - CursorX;
                                        double CursorY = (((LeftFeet.Position.X + RightFeet.Position.X) / 2 - (leftDistance)) / (rightDistance - leftDistance)) * Globals.CurrentResolution.VerticalResolution;
                                        int    x       = Convert.ToInt32(CursorX);
                                        int    y       = Convert.ToInt32(CursorY);
                                        Mouse.OverrideCursor = Cursors.None;

                                        //if (count == 0)
                                        //{
                                        //    RippleCommonUtilities.OSNativeMethods.SendMouseInput(x, y, (int)Globals.CurrentResolution.HorizontalResolution, (int)Globals.CurrentResolution.VerticalResolution, true);
                                        //    count = 10;
                                        //}
                                        //count--;
                                        //RippleCommonUtilities.OSNativeMethods.SendMouseInput(x, y, (int)Globals.CurrentResolution.HorizontalResolution, (int)Globals.CurrentResolution.VerticalResolution, true);
                                        RippleCommonUtilities.OSNativeMethods.SendMouseInput(x, y, (int)Globals.CurrentResolution.HorizontalResolution, (int)Globals.CurrentResolution.VerticalResolution, false);
                                    }
                                    #endregion
                                }
                                //Run block identification only if not in above mode
                                else
                                {
                                    #region Calibrated Tile Detection

                                    bool locationChanged = false;
                                    for (int i = 0; i < tileCount; i++)
                                    {
                                        if ((LeftFeet.Position.Z > topTileBoundary[i] && LeftFeet.Position.Z < bottomTileBoundary[i]) && (RightFeet.Position.Z > topTileBoundary[i] && RightFeet.Position.Z < bottomTileBoundary[i]) && (leftFeetXPosition > (leftTileBoundary[i]) && leftFeetXPosition < rightTileBoundary[i]) && (rightFeetXPosition > (leftTileBoundary[i]) && rightFeetXPosition < rightTileBoundary[i]))
                                        {
                                            CurrentLocation = i;
                                            locationChanged = true;
                                            i = 0;
                                            break;
                                        }
                                    }
                                    if (locationChanged == false)
                                    {
                                        CurrentLocation = -1;
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                CurrentLocation = -1;
                            }
                        }
                        else
                        {
                            CurrentLocation = -1;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Do nothing
                RippleCommonUtilities.LoggingHelper.LogTrace(1, "Went wrong in Kinect helper {0}", ex.Message);
            }
        }
示例#12
0
        void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (var skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame == null)
                {
                    return;
                }

                if (skeletons == null ||
                    skeletons.Length != skeletonFrame.SkeletonArrayLength)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                }

                skeletonFrame.CopySkeletonDataTo(skeletons);
            }

            closestSkeleton = skeletons.Where(s => s.TrackingState == SkeletonTrackingState.Tracked)
                              .OrderBy(s => s.Position.Z * Math.Abs(s.Position.X))
                              .FirstOrDefault();

            if (closestSkeleton == null)
            {
                return;
            }

            Joint head           = closestSkeleton.Joints[JointType.Head];
            Joint rightHand      = closestSkeleton.Joints[JointType.HandRight];
            Joint leftHand       = closestSkeleton.Joints[JointType.HandLeft];
            Joint rightElbow     = closestSkeleton.Joints[JointType.ElbowRight];
            Joint leftElbow      = closestSkeleton.Joints[JointType.ElbowLeft];
            Joint rightShoulder  = closestSkeleton.Joints[JointType.ShoulderRight];
            Joint leftShoulder   = closestSkeleton.Joints[JointType.ShoulderLeft];
            Joint centerShoulder = closestSkeleton.Joints[JointType.ShoulderCenter];
            Joint spine          = closestSkeleton.Joints[JointType.Spine];
            Joint centerHip      = closestSkeleton.Joints[JointType.HipCenter];

            SetEllipsePosition(ellipseHead, head);
            SetEllipsePosition(ellipseLeftHand, leftHand);
            SetEllipsePosition(ellipseRightHand, rightHand);
            SetEllipsePosition(ellipseLeftElbow, leftElbow);
            SetEllipsePosition(ellipseRightElbow, rightElbow);
            SetEllipsePosition(ellipseLeftShoulder, leftShoulder);
            SetEllipsePosition(ellipseRightShoulder, rightShoulder);
            SetEllipsePosition(ellipseShoulderCenter, centerShoulder);
            SetEllipsePosition(ellipseSpine, spine);
            SetEllipsePosition(ellipseHipCenter, centerHip);

            if (!isLengthCallibrated)
            {
                l1.Content = "Callibrating";
            }

            if (Math.Abs(leftHand.Position.X - leftElbow.Position.X) < 0.1 && Math.Abs(leftHand.Position.Z - centerShoulder.Position.Z + 0.2) < 0.1 && count != 20 && !isLengthCallibrated && Math.Abs(leftHand.Position.Y - centerShoulder.Position.Y) > 0.3)
            {
                armLength = (armLength * count + Math.Abs(leftHand.Position.Y - leftElbow.Position.Y)) / (count + 1);
                count++;
                return;
            }
            else if (count == 20)
            {
                isLengthCallibrated = true;
                armLength           = armLength + 0.1;
                l1.Content          = "Ready. ArmLength = " + armLength;
                count++;
            }

            if (mouse)
            {
                double i, j;
                i = 0.4 * rightHand.Position.X + 0.3 * x[0] + 0.2 * x[1] + 0.1 * x[2];
                j = 0.4 * rightHand.Position.Y + 0.3 * y[0] + 0.2 * y[1] + y[2] * 0.1;
                for (int t = 0; t < 2; t++)
                {
                    x[t + 1] = x[t];
                    y[t + 1] = y[t];
                }
                x[0] = rightHand.Position.X;
                y[0] = rightHand.Position.Y;
                int a = (int)Math.Floor((i - originX - 0.05) * 3000);
                int b = 360 + (int)Math.Floor((j - originY + .1) * -2000);
                SetCursorPos(a, b);
                Thread.Sleep(10);
                if ((leftHand.Position.Z < centerShoulder.Position.Z - 0.5) && !isDragOn)
                {
                    mouse_event(MOUSEEVENTF_LEFTDOWN, System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y, 0, 0);
                    isDragOn = true;
                }
                else if (!(leftHand.Position.Z < centerShoulder.Position.Z - 0.40) && isDragOn)
                {
                    mouse_event(MOUSEEVENTF_LEFTUP, System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y, 0, 0);
                    isDragOn = false;
                }
                //SystemCursors.setCustomCursor("C:\\Users\\Rituj Beniwal\\Desktop\\PowerPoint_kinect\\PowerPoint_kinect\\cursor.cur");
            }

            if (head.TrackingState == JointTrackingState.NotTracked ||
                rightHand.TrackingState == JointTrackingState.NotTracked ||
                leftHand.TrackingState == JointTrackingState.NotTracked)
            {
                //Don't have a good read on the joints so we cannot process gestures
                return;
            }

            // update the gesture controller
            gestureController.UpdateAllGestures(closestSkeleton);
        }
示例#13
0
        void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            Skeleton[] skeletons = new Skeleton[0];

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
            }

            using (DrawingContext dc = this.drawingGroup.Open())
            {
                // Draw a transparent background to set the render size
                dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                if (skeletons.Length != 0)
                {
                    foreach (Skeleton skel in skeletons)
                    {
                        RenderClippedEdges(skel, dc);
                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            this.DrawBonesAndJoints(skel, dc);
                            SetDepthPoints(skel, e);
                            if (m_gestureController != null)
                            {
                                m_gestureController.UpdateAllGestures(skel, m_headDepthPoint, m_leftHandDepthPoint, m_rightHandDepthPoint);
                            }
                            break;
                        }
                        else if (skel.TrackingState == SkeletonTrackingState.PositionOnly)
                        {
                            dc.DrawEllipse(
                                this.centerPointBrush,
                                null,
                                this.SkeletonPointToScreen(skel.Position),
                                BodyCenterThickness,
                                BodyCenterThickness);
                        }
                    }
                }

                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
            }


            //Get raw image
            using (DepthImageFrame depth = e.OpenDepthImageFrame())
            {
                if (depth != null)
                {
                    //Create array for pixel data and copy it from the image frame
                    short[] pixelData = new short[depth.PixelDataLength];
                    depth.CopyPixelDataTo(pixelData);
                    byte[] convertedPixels = ConvertDepthFrame(pixelData, ((KinectSensor)sender).DepthStream, 640 * 480 * 4);
                    m_colorImageData.ColorImage = convertedPixels;
                    m_colorImageData.Height     = depth.Height;
                    m_colorImageData.Width      = depth.Width;
                }
            }
        }
示例#14
0
        /// <summary>
        /// Handler for skeleton ready handler.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event args.</param>
        private void OnSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            // Get the frame.
            using (var frame = e.OpenSkeletonFrame())
            {
                // Ensure we have a frame.
                if (frame != null)
                {
                    // Resize the skeletons array if a new size (normally only on first call).
                    if (this.skeletons.Length != frame.SkeletonArrayLength)
                    {
                        this.skeletons = new Skeleton[frame.SkeletonArrayLength];
                    }

                    // Get the skeletons.
                    frame.CopySkeletonDataTo(this.skeletons);

                    // Assume no nearest skeleton and that the nearest skeleton is a long way away.
                    var newNearestId     = -1;
                    var nearestDistance2 = double.MaxValue;

                    // Look through the skeletons.
                    foreach (var skeleton in this.skeletons)
                    {
                        // Only consider tracked skeletons.
                        if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            // Find the distance squared.
                            var distance2 = (skeleton.Position.X * skeleton.Position.X) +
                                            (skeleton.Position.Y * skeleton.Position.Y) +
                                            (skeleton.Position.Z * skeleton.Position.Z);

                            // Is the new distance squared closer than the nearest so far?
                            if (distance2 < nearestDistance2)
                            {
                                // Use the new values.
                                newNearestId     = skeleton.TrackingId;
                                nearestDistance2 = distance2;
                            }
                            gestureController.UpdateAllGestures(skeleton);
                            if (detialWindow != null)
                            {
                                if (CheckIfShowHand(skeleton))
                                {
                                    detialWindow.SetHandLeftPoint(CalcScreenPoint(skeleton, JointType.HandLeft));
                                    detialWindow.SetHandRightPoint(CalcScreenPoint(skeleton, JointType.HandRight));
                                }
                            }
                        }
                    }

                    if (this.nearestId != newNearestId)
                    {
                        this.nearestId = newNearestId;
                    }
                    // Pass skeletons to recognizer.
                    this.activeRecognizer.Recognize(sender, frame, this.skeletons);
                    this.DrawStickMen(this.skeletons);
                }
            }
        }