Example #1
0
        private void OnFrameArrived(object o, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference brf = e.FrameReference;
            BodyFrame          bf  = brf.AcquireFrame();

            if (bf != null)
            {
                using (bf) {
                    bf.GetAndRefreshBodyData(mBodies);

                    Body  b = null;
                    float f = float.MaxValue;

                    foreach (Body v in mBodies)
                    {
                        if (v.IsTracked)
                        {
                            float z = v.Joints[JointType.SpineMid].Position.Z;
                            if (z > 0.5 && z < f)
                            {
                                f = z;
                                b = v;
                            }
                        }
                    }

                    if (b != null)
                    {
                        OnKinectReceivedBody(this, new KinectEventArgs(new SkeletonJSON(b)));
                    }
                }
            }
        }
Example #2
0
        void useBodyFrame(BodyFrameReference bodyFrameReference)
        {
            try
            {
                BodyFrame bodyFrame = bodyFrameReference.AcquireFrame();

                if (bodyFrame != null)
                {
                    using (bodyFrame)
                    {
                        bodyFrame.GetAndRefreshBodyData(this.bodies);
                        if (this.bodyToTrack < 0)
                        {
                            this.findBodyToTrack();
                        }

                        if (this.bodyToTrack > -1)
                        {
                            this.updateCurrentBody();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                Console.WriteLine(message);
                // Don't worry about empty frames.
            }
        }
Example #3
0
        /// <summary>
        /// Process the body-frames and draw joints
        /// </summary>
        public void OnBodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            // Get frame reference
            BodyFrameReference refer = e.FrameReference;

            if (refer == null)
            {
                return;
            }

            // Get body frame
            BodyFrame frame = refer.AcquireFrame();

            if (frame == null)
            {
                return;
            }

            using (frame)
            {
                // Aquire body data
                frame.GetAndRefreshBodyData(_bodies);


                // Loop all bodies
                foreach (Body body in _bodies)
                {
                    // Only process tracked bodies
                    if (body.IsTracked)
                    {
                    }
                }
            }
        }
        void lecteurBody_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference refer = e.FrameReference;

            if (refer == null)
            {
                return;
            }

            // Obtenir body frame
            BodyFrame frame = refer.AcquireFrame();

            if (frame == null)
            {
                return;
            }

            using (frame)
            {
                // Obtenir les donnƩes des joueurs
                frame.GetAndRefreshBodyData(bodies);

                // Clear Skeleton Canvas
                CanvasCameraPrincipale.Children.Clear();

                List <Point> Mains = new List <Point>();

                // Loop all bodies
                foreach (Body body in bodies)
                {
                    // Only process tracked bodies
                    if (body.IsTracked)
                    {
                        Mains.Clear();
                        Mains.Add(ObtenirPositionEcran(body.Joints[JointType.HandLeft]));
                        Mains.Add(ObtenirPositionEcran(body.Joints[JointType.HandRight]));

                        //On regarde si le joueur Ć  fait un choix
                        if (DetermineContact(Mains, bt_jouer, body))
                        {
                            MainWindow window = new MainWindow();
                            window.Show();
                            this.Close();
                        }
                        else if (DetermineContact(Mains, bt_quitter, body))
                        {
                            this.Close();
                        }
                        else if (DetermineContact(Mains, bt_galerie, body))
                        {
                            Galerie galerie = new Galerie();
                            galerie.Show();
                            this.Close();
                        }
                    }
                }
            }
        }
Example #5
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;
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// Display the skeleton data when a frame is received
        /// </summary>
        private void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference frameReference = e.FrameReference;
            BodyFrame          frame          = frameReference.AcquireFrame();

            if (frame != null)
            {
                Dispatcher.Invoke(() => { skeletonRenderer.Reader_FrameArrived(e); frame.Dispose(); });
            }
        }
Example #7
0
        /// <summary>
        /// Process the body-frames and draw joints
        /// </summary>
        private void OnBodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            // Get frame reference
            BodyFrameReference refer = e.FrameReference;

            if (refer == null)
            {
                return;
            }

            // Get body frame
            BodyFrame frame = refer.AcquireFrame();

            if (frame == null)
            {
                return;
            }

            using (frame)
            {
                // Aquire body data
                frame.GetAndRefreshBodyData(_bodies);

                // Clear Skeleton Canvas
                SkeletonCanvas.Children.Clear();

                int bodyIndex = 0;
                // Loop all bodies
                foreach (Body body in _bodies)
                {
                    // Only process tracked bodies
                    if (body.IsTracked)
                    {
                        // replace with custom messages
                        Random rnd         = new Random();
                        int    randomValue = rnd.Next(0, myMessages.Length);
                        if (bodyTrackingIds[bodyIndex] == body.TrackingId)
                        {
                            // same body, don't update text
                            //textToDisplay = body.TrackingId.ToString();
                        }
                        else
                        {
                            // new body detected, update text!
                            textToDisplay[bodyIndex] = "" + myMessages[randomValue] + "";
                            // set body tracking id!
                            bodyTrackingIds[bodyIndex] = body.TrackingId;
                        }
                        // pass on the message
                        DrawBody(body, textToDisplay[bodyIndex]);
                    }
                    bodyIndex++;
                }
            }
        }
Example #8
0
        private void BodyFrameReader_FrameArrived(BodyFrameReference bodyFrameReference)
        {
            using (BodyFrame bodyFrame = bodyFrameReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    if (this.bodies == null || this.bodies.Count != bodyFrame.BodyCount)
                    {
                        this.bodies = new Body[bodyFrame.BodyCount];
                    }

                    bodyFrame.GetAndRefreshBodyData(this.bodies);

                    // compute the number of tracked bodies
                    this.trackedBodies = this.bodies.Count(b => b.IsTracked);

                    if (this.kinectBodies == null || this.kinectBodies.Count != this.trackedBodies)
                    {
                        this.kinectBodies = new List <KinectBody>(this.trackedBodies);
                        for (int i = 0; i < this.trackedBodies; i++)
                        {
                            this.kinectBodies.Add(new KinectBody());
                        }
                    }

                    // construct the output
                    int ti = 0;
                    for (int i = 0; i < bodyFrame.BodyCount; i++)
                    {
                        if (this.bodies[i].IsTracked)
                        {
                            this.kinectBodies[ti].FloorClipPlane      = bodyFrame.FloorClipPlane;
                            this.kinectBodies[ti].ClippedEdges        = this.bodies[i].ClippedEdges;
                            this.kinectBodies[ti].HandLeftConfidence  = this.bodies[i].HandLeftConfidence;
                            this.kinectBodies[ti].HandLeftState       = this.bodies[i].HandLeftState;
                            this.kinectBodies[ti].HandRightConfidence = this.bodies[i].HandRightConfidence;
                            this.kinectBodies[ti].HandRightState      = this.bodies[i].HandRightState;
                            this.kinectBodies[ti].IsRestricted        = this.bodies[i].IsRestricted;
                            this.kinectBodies[ti].IsRestricted        = this.bodies[i].IsRestricted;
                            this.kinectBodies[ti].IsTracked           = this.bodies[i].IsTracked;
                            this.kinectBodies[ti].JointOrientations   = this.CloneDictionary(this.bodies[i].JointOrientations);
                            this.kinectBodies[ti].Joints            = this.CloneDictionary(this.bodies[i].Joints);
                            this.kinectBodies[ti].Lean              = this.bodies[i].Lean;
                            this.kinectBodies[ti].LeanTrackingState = this.bodies[i].LeanTrackingState;
                            this.kinectBodies[ti].TrackingId        = this.bodies[i].TrackingId;
                            ti++;
                        }
                    }

                    var time = this.pipeline.GetCurrentTimeFromElapsedTicks(bodyFrameReference.RelativeTime.Ticks);
                    this.Bodies.Post(this.kinectBodies, time);
                }
            }
        }
Example #9
0
        /// <summary>
        /// Parse the data received from kinect
        /// </summary>
        void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference frameReference = e.FrameReference;
            BodyFrame          frame          = frameReference.AcquireFrame();

            if (frame == null)
            {
                return;
            }

            // Make first list of people to compare to determine who has left the scene
            List <Person> oldPersonList = new List <Person>();

            foreach (Body body in bodies)
            {
                if (body != null)
                {
                    oldPersonList.Add(ConvertBodyToPerson((body)));
                }
            }

            frame.GetAndRefreshBodyData(bodies);
            frame.Dispose();

            // Second list of people to compare with first to determine who has left the scene
            List <int> currentIDList = new List <int>();

            foreach (Body body in bodies)
            {
                currentIDList.Add(GetSimpleID(body.TrackingId));
            }


            List <Person> persons = new List <Person>();

            foreach (Body body in bodies)
            {
                if (body.IsTracked)
                {
                    Person person = ConvertBodyToPerson(body);

                    persons.Add(person);
                    if (FileRecording.recording)
                    {
                        int currentId = GetSimpleID(body.TrackingId);;
                        FileRecording.Record_Joint_Points(currentId, person.Joints, DateTime.Now);
                    }
                }
            }
        }
        private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference frameReference = e.FrameReference;

            try
            {
                BodyFrame frame = frameReference.AcquireFrame();
                if (frame != null)
                {
                    // BodyFrame is IDisposable
                    using (frame)
                    {
                        frame.GetAndRefreshBodyData(this.bodies);

                        // Find body closest to kinect
                        Body  closestBody = null;
                        float closest     = 9999;

                        foreach (Body body in this.bodies)
                        {
                            if (body.IsTracked)
                            {
                                float z = body.Joints[JointType.SpineMid].Position.Z;
                                if (z > 0.5 && z < closest)
                                {
                                    closest     = z;
                                    closestBody = body;
                                }
                            }
                        }

                        if (closestBody != null)
                        {
                            List <GeenenBody> bodyList = new List <GeenenBody>();

                            // Filter
                            this.filters[0].UpdateFilter(closestBody);
                            bodyList.Add(new GeenenBody(closestBody, this.filters[0].getJoints()));

                            KinectReceivedBody(this, new KinectEventArgs(bodyList));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }
        }
Example #11
0
        public void AddFrame(BodyFrameReference frame)
        {
            this.currentFrame = frame;
            this.framesSinceUpdate++;
            this.InitStartTimeOnFirstFrame();

            if (this.IsReadyForUpdate())
            {
                this.PerformUpdate();
                this.SetNextUpdateTime();
            }

            this.InitStopwatchOnFirstFrame();
            this.SetFirstFramePassed();
        }
Example #12
0
        public void AddFrame(BodyFrameReference frame)
        {
            this.currentFrame = frame;
            this.framesSinceUpdate++;
            this.InitStartTimeOnFirstFrame();

            if (this.IsReadyForUpdate())
            {
                this.PerformUpdate();
                this.SetNextUpdateTime();
            }

            this.InitStopwatchOnFirstFrame();
            this.SetFirstFramePassed();
        }
Example #13
0
        private void OnBodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            // Get frame reference
            BodyFrameReference refer = e.FrameReference;

            if (refer == null)
            {
                return;
            }
            {
                //Get body frame
                BodyFrame frame = refer.AcquireFrame();

                if (frame == null)
                {
                    StatusText.Text       = "BodyOff";
                    StatusText.Visibility = Visibility.Visible;
                    return;
                }

                else
                {
                    StatusText.Text       = "BodyOn";
                    StatusText.Visibility = Visibility.Visible;
                }

                //Process it
                using (frame)
                {
                    //Aquire body data
                    frame.GetAndRefreshBodyData(_bodies);

                    //Clear Skeleton Canvas
                    SkeletonCanvas.Children.Clear();

                    //Loop all bodies
                    foreach (Body body in _bodies)
                    {
                        //Only process tracked bodyie
                        if (body.IsTracked)
                        {
                            DrawBody(body);
                        }
                    }
                }
            }
        }
Example #14
0
        void lecteurBody_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference refer = e.FrameReference;

            if (refer == null)
            {
                return;
            }

            // Obtenir body frame
            BodyFrame frame = refer.AcquireFrame();

            if (frame == null)
            {
                return;
            }

            using (frame)
            {
                // Obtenir les donnƩes des joueurs
                frame.GetAndRefreshBodyData(bodies);

                // Clear Skeleton Canvas
                CanvasCameraPrincipale.Children.Clear();

                // Loop all bodies
                foreach (Body body in bodies)
                {
                    // Only process tracked bodies and if the timer is over
                    if (body.IsTracked && tempsFini)
                    {
                        if (body.HandLeftState == HandState.Closed)                        //Si la main gauche est fermƩe on met l'image d'avant
                        {
                            indexPhoto--;
                            afficherPhoto();
                        }
                        else if (body.HandRightState == HandState.Closed)                         //Si la main droite est fermĆ©e on met l'image d'aprĆØs
                        {
                            indexPhoto++;
                            afficherPhoto();
                        }
                    }
                }
            }
        }
Example #15
0
        /// <summary>
        /// Handle the new body frames
        /// </summary>
        private async void OnBodiesArrive(object sender, BodyFrameArrivedEventArgs e)
        {
            // Retrieve the body reference
            BodyFrameReference bodyRef = e.FrameReference;

            if (bodyRef == null)
            {
                return;
            }

            // Acquire the body frame
            using (BodyFrame frame = bodyRef.AcquireFrame())
            {
                if (frame == null)
                {
                    return;
                }

                // Create a new collection when required
                if (_bodies == null || _bodies.Count() != frame.BodyCount)
                {
                    _bodies = new Body[frame.BodyCount];
                }

                // Refresh the bodies
                frame.GetAndRefreshBodyData(_bodies);

                // Start tracking faces
                foreach (Body body in _bodies)
                {
                    if (body.IsTracked)
                    {
                        // Create a new tracker if required
                        if (!_trackers.ContainsKey(body.TrackingId))
                        {
                            FaceTracker tracker = new FaceTracker(body.TrackingId, _faceFrameFeatures, _kinect);
                            tracker.FaceAnalyticsAvailable += OnFaceAnalyticsAvailable;

                            // Add to dictionary
                            _trackers.Add(body.TrackingId, tracker);
                        }
                    }
                }
            }
        }
        void reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference BFReference = e.FrameReference;

            try
            {
                BodyFrame frame = BFReference.AcquireFrame();
                if (frame != null)
                {
                    using (frame)
                    {
                        using (DrawingContext dc = SkeletonDrawing.Open())
                        {
                            dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, DisplayWidth, DisplayHeight));
                            if (Bodies == null)
                            {
                                Bodies = new Body[frame.BodyCount];
                            }
                            frame.GetAndRefreshBodyData(Bodies);
                            foreach (Body b in Bodies)
                            {
                                if (b.IsTracked)
                                {
                                    this.DrawClippedEdges(b, dc);
                                    IReadOnlyDictionary <JointType, Joint> joints = b.Joints;

                                    Dictionary <JointType, Point> jointsPoints = new Dictionary <JointType, Point>();
                                    foreach (JointType jt in joints.Keys)
                                    {
                                        DepthSpacePoint dsp = CordMapper.MapCameraPointToDepthSpace(joints[jt].Position);
                                        jointsPoints[jt] = new Point(dsp.X, dsp.Y);
                                    }
                                    this.DrawBody(joints, jointsPoints, dc);
                                    DrawHand(b.HandLeftState, jointsPoints[JointType.HandLeft], dc);
                                    DrawHand(b.HandRightState, jointsPoints[JointType.HandRight], dc);
                                }
                                this.SkeletonDrawing.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, DisplayWidth, DisplayHeight));
                            }
                        }
                    }
                }
            }
            catch (Exception) { }
        }
        /// <summary>
        /// Process body frames
        /// </summary>
        private void OnBodyFrameReceived(object sender, BodyFrameArrivedEventArgs e)
        {
            // Get Frame ref
            BodyFrameReference bodyRef = e.FrameReference;

            if (bodyRef == null)
            {
                return;
            }

            // Get body frame
            using (BodyFrame frame = bodyRef.AcquireFrame())
            {
                if (frame == null)
                {
                    return;
                }

                // Allocate array when required
                if (_bodies == null)
                {
                    _bodies = new Body[frame.BodyCount];
                }

                // Refresh bodies
                frame.GetAndRefreshBodyData(_bodies);

                foreach (Body body in _bodies)
                {
                    if (body.IsTracked && _faceSource == null)
                    {
                        // Create new sources with body TrackingId
                        _faceSource = new FaceFrameSource(_kinect, body.TrackingId, _faceFrameFeatures);

                        // Create new reader
                        _faceReader = _faceSource.OpenReader();

                        // Wire events
                        _faceReader.FrameArrived   += OnFaceFrameArrived;
                        _faceSource.TrackingIdLost += OnTrackingIdLost;
                    }
                }
            }
        }
        /// <summary>
        /// Handles the body frame data arriving from the sensor
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference frameReference = e.FrameReference;

            try
            {
                BodyFrame frame = frameReference.AcquireFrame();

                if (frame != null)
                {
                    // BodyFrame is IDisposable
                    using (frame)
                    {
                        // 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(_bodies);

                        foreach (Body body in _bodies)
                        {
                            if (body.IsTracked)
                            {
                                IReadOnlyDictionary <Microsoft.Kinect.JointType, Joint> joints = body.Joints;

                                // convert the joint points to depth (display) space
                                Dictionary <JointType, Point> jointPoints = new Dictionary <JointType, Point>();
                                foreach (JointType jointType in joints.Keys)
                                {
                                    DepthSpacePoint depthSpacePoint = _coordinateMapper.MapCameraPointToDepthSpace(joints[jointType].Position);
                                    jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                                }
                            }
                        }

                        ProcessData();
                    }
                }
            }
            catch (Exception)
            {
                // ignore if the frame is no longer available
            }
        }
Example #19
0
        void multiSourceFrameReader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            MultiSourceFrameReference msFrameReference = e.FrameReference;

            try
            {
                MultiSourceFrame msFrame = msFrameReference.AcquireFrame();

                if (msFrame != null)
                {
                    LongExposureInfraredFrameReference leirFrameReference = msFrame.LongExposureInfraredFrameReference;
                    InfraredFrameReference             irFrameReference   = msFrame.InfraredFrameReference;
                    ColorFrameReference colorFrameReference = msFrame.ColorFrameReference;
                    DepthFrameReference depthFrameReference = msFrame.DepthFrameReference;
                    BodyFrameReference  bodyFrameReference  = msFrame.BodyFrameReference;
                    switch (this.imageType)
                    {
                    case ImageType.Color:
                        useColorFrame(colorFrameReference);
                        break;

                    case ImageType.Depth:
                        useDepthFrame(depthFrameReference);
                        break;

                    case ImageType.IR:
                        useIRFrame(irFrameReference);
                        break;

                    case ImageType.LEIR:
                        useLIRFrame(leirFrameReference);
                        break;
                    }
                    useBodyFrame(bodyFrameReference);
                    //updatePulse(colorFrameReference, irFrameReference, bodyFrameReference);
                }
            }
            catch (Exception ex)
            {
            }
        }
 public void GetBitmap(BodyFrameReference frameReference)
 {
     IEnumerable<IBody> bodies = null;
     using (var frame = frameReference.AcquireFrame())
     {
         if (frame != null)
         {
             frame.GetAndRefreshBodyData(_bodies);
             bodies = _bodies;
         }
         if (bodies != null)
         {
             bodies.MapDepthPositions();
             Bitmap = bodies.GetBitmap(Colors.LightGreen, Colors.Yellow);
         }
         else
         {
             Bitmap = null;
         }
     }
 }
        /// <summary>
        /// Process the body-frames and draw joints
        /// </summary>
        private void OnBodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            // Get frame reference
            BodyFrameReference refer = e.FrameReference;

            if (refer == null)
            {
                return;
            }

            // Get body frame
            BodyFrame frame = refer.AcquireFrame();

            if (frame == null)
            {
                return;
            }

            using (frame)
            {
                // Aquire body data
                frame.GetAndRefreshBodyData(_bodies);

                // Clear Skeleton Canvas
                SkeletonCanvas.Children.Clear();

                // Loop all bodies
                foreach (Body body in _bodies)
                {
                    // Only process tracked bodies
                    if (body.IsTracked)
                    {
                        DrawBody(body);
                        checkDepth(body);
                        barbellEvenness(body);
                    }
                }
            }
        }
        void lecteurBody_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference refer = e.FrameReference;

            if (refer == null)
            {
                return;
            }

            // Obtenir bodies frame
            BodyFrame frame = refer.AcquireFrame();

            if (frame == null)
            {
                return;
            }

            using (frame)
            {
                // Obtenir les donnƩes des joueurs
                frame.GetAndRefreshBodyData(bodies);

                // Effacer le canvas
                CanvasCameraPrincipale.Children.Clear();
                CanvasCameraVignette.Children.Clear();

                // ItƩrer das tous les corps disponibles
                foreach (Body bodies in bodies)
                {
                    // On ne traite que les corps trackƩs
                    if (bodies.IsTracked)
                    {
                        DessineBody(bodies);
                    }
                }
                timer.Start();
            }
        }
Example #23
0
 private void OnFrameArrived(object sender, BodyFrameArrivedEventArgs e)
 {
     BFRefence = e.FrameReference;
     try
     {
         //this.APS.IncrimentActions();
         this.APS.TryActionsPerSecondUpdate();
         BFFrame = BFRefence.AcquireFrame();
         using (BFFrame)
         {
             this.APS.IncrimentActions();
             //BFFrame.GetAndRefreshBodyData(Bodies);
             BFRefence = e.FrameReference;
             Bodies    = new Body[BFFrame.BodyCount];
             BFFrame.GetAndRefreshBodyData(Bodies);
             foreach (Body b in Bodies)
             {
                 if (b.IsTracked)
                 {
                     KinectData joid = new KinectData(JointsOfInterest, b);
                     if (NewTData != null)
                     {
                         NewTData(this, joid);
                     }
                     if (NewIData != null)
                     {
                         NewIData(this, joid);
                     }
                 }
             }
         }
     }
     catch (Exception e1)
     {
         throw e1;
     }
 }
Example #24
0
        private void HandleBodyFrame(BodyFrameReference reference)
        {
            if (Task.StandBy)
            {
                BodyWatch.Reset(); return;
            }

            BodyWatch.Again();
            using (var frame = reference.AcquireFrame()) {
                if (frame == null)
                {
                    return;
                }

                // 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.
                var tmp = (IList <Body>)Body.RawData;
                frame.GetAndRefreshBodyData(tmp);
                Body.Stamp.Time = System.DateTime.Now;
                RefreshBodyData(Body);
            }
            BodyWatch.Stop();
        }
Example #25
0
        private void _BodyFrameHandler(BodyFrameReference frameRef)
        {
            using (BodyFrame frame = frameRef.AcquireFrame())
            {
                if (frame != null)
                {
                    Body[] bodies = new Body[frame.BodyCount];
                    frame.GetAndRefreshBodyData(bodies);

                    // Select last body in list which is being tracked
                    Body body = bodies.Where(thisBody => thisBody.IsTracked).LastOrDefault();

                    // If it's not already tracking...
                    if (!_faceSource.IsTrackingIdValid)
                    {
                        // And if the body from the List<Body> isn't null...
                        if (body != null)
                        {
                            _faceSource.TrackingId = body.TrackingId;
                        }
                    }
                }
            }
        }
Example #26
0
    private void HandleBodyFrame(BodyFrameReference reference) {
      if (Task.StandBy) { BodyWatch.Reset(); return; }

      BodyWatch.Again();
      using (var frame = reference.AcquireFrame()) {
        if (frame == null) return;

        // 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.
        var tmp = (IList<Body>)Body.RawData;
        frame.GetAndRefreshBodyData(tmp);
        Body.Stamp.Time = System.DateTime.Now;
        RefreshBodyData(Body);
      }
      BodyWatch.Stop();
    }
Example #27
0
        /// <summary>
        /// Catches the AllFrameReady-Event and saves the skeletons of the actual frame before they are available to processing.
        /// Addtionally it checks, if a skeleton completely left the room.
        /// </summary>
        /// <param name="sender">sender of the AllFrameReady event</param>
        /// <param name="e">AllFrameReadyEvent with associated data.</param>
        public void reader_FramesReady(object sender, BodyFrameArrivedEventArgs e)
        {
            if (e == null)
            {
                return;
            }

            Body[]             bodies         = new Body[0];
            BodyFrameReference frameReference = e.FrameReference;

            using (BodyFrame bodyFrame = frameReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    bodies = new Body[bodyFrame.BodyCount];
                    bodyFrame.GetAndRefreshBodyData(bodies);
                }
                else
                {
                    return;
                }

                HashSet <int> idsSeen = new HashSet <int>();

                foreach (Body s in bodies)
                {
                    if (s.TrackingId != 0)
                    {
                        idsSeen.Add((int)s.TrackingId);
                    }
                }

                bool bodiesLastFrameNotNull = false;

                foreach (Body s in _bodiesLastFrame)
                {
                    if (s == null && bodiesLastFrameNotNull == true)
                    {
                        bodiesLastFrameNotNull = false;
                        break;
                    }
                    if (s != null && bodiesLastFrameNotNull == false)
                    {
                        bodiesLastFrameNotNull = true;
                    }
                }

                if (bodiesLastFrameNotNull)
                {
                    //checks if a skeleton doesnt exist anymore.
                    foreach (Body s in _bodiesLastFrame.Where(s => s != null && !idsSeen.Contains((int)s.TrackingId) && s.TrackingId != 0))
                    {
                        this.OnUserLeft(this, new KinectUserEventArgs((int)s.TrackingId));
                        for (int i = 0; i < Bodies.Count; i++)
                        {
                            if (Bodies[i].Id == (int)s.TrackingId)
                            {
                                Bodies.Remove(Bodies[i]);
                            }
                        }
                    }
                }
                _bodiesLastFrame = bodies;

                if (checkOnEveryFrame)
                {
                }

                if (movingWindowCollect == true)
                {
                    Body[] bodiesToSave = new Body[bodies.Length];
                    for (int i = 0; i < bodies.Length; i++)
                    {
                        bodiesToSave[i] = bodies[i];
                    }
                    if (workingOnWindow == false)
                    {
                        if (movingWindowCollect == true && lastBodies.Count == windowSize)
                        {
                            lastBodies.RemoveAt(0);
                        }
                        lastBodies.Add(bodiesToSave);
                    }
                }
            }
        }
Example #28
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);
            }
        }
Example #29
0
        /// <summary>
        /// Handles the arrival of each skeleton frame
        /// </summary?
        private void Reader_FrameArrivedSkel(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference frameReference = e.FrameReference;

            try
            {
                BodyFrame frame = frameReference.AcquireFrame();

                if (frame != null)
                {
                    // BodyFrame is IDisposable
                    using (frame)
                    {
                        this.framesSinceUpdate++;


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

                            // 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);

                            foreach (Body body in this.bodies)
                            {
                                if (body.IsTracked)
                                {
                                    // this.DrawClippedEdges(body, dc);

                                    IReadOnlyDictionary <JointType, Joint> joints = body.Joints;

                                    // convert the joint points to depth (display) space
                                    Dictionary <JointType, Point> jointPoints = new Dictionary <JointType, Point>();
                                    foreach (JointType jointType in joints.Keys)
                                    {
                                        ColorSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToColorSpace(joints[jointType].Position);
                                        jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                                    }

                                    this.DrawBody(joints, jointPoints, dc);

                                    this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc);
                                    this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc);

                                    //save the skel coords if the option is selected
                                    if (skelRecO == true)
                                    {
                                        long milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

                                        saveSkelInformation(milliseconds, body);
                                        saveTimeStamp("time_skel", milliseconds);
                                        //Save current frame time stamp
                                    }
                                }
                            }

                            // prevent drawing outside of our render area
                            this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                // ignore if the frame is no longer available
            }
        }
Example #30
0
 private void HandleBodies(BodyFrameReference bodyFrameReference)
 {
     BodyFrame bodyFrame = bodyFrameReference.AcquireFrame();
     if (bodyFrame != null)
     {
         using (bodyFrame)
         {
             bodyFrame.GetAndRefreshBodyData(this.bodies);
             this.bodyCount = 0;
             foreach (Body b in this.bodies)
             {
                 if (b.IsTracked)
                 {
                     this.bodyCount += 1;
                     this.bfd.Body = b;
                     this.BodyFrameArrived(this, this.bfd);
                 }
             }
         }
     }
 }
Example #31
0
        /// <summary>
        /// Device-specific implementation of Update.
        /// Updates data buffers of all active channels with data of current frame.
        /// </summary>
        /// <remarks>This method is implicitely called by <see cref="Camera.Update"/> inside a camera lock.</remarks>
        /// <seealso cref="Camera.Update"/>
        protected override void UpdateImpl()
        {
            // TODO: This method could yield rather asynchronous channels. If necessary: Try to find a mechanism that updates frames that are already fetched when waiting for others that are not yet available.
            MultiSourceFrame multiSourceFrame       = null;
            bool             bodyIndexRequired      = IsChannelActive(CustomChannelNames.BodyIndex);
            bool             depthRequired          = IsChannelActive(ChannelNames.Distance) || IsChannelActive(ChannelNames.Point3DImage);
            bool             amplitudeRequired      = IsChannelActive(ChannelNames.Amplitude);
            bool             colorRequired          = IsChannelActive(ChannelNames.Color);
            bool             longExposureIRRequired = IsChannelActive(CustomChannelNames.LongExposureIR);

            do
            {
                if (!dataAvailable.WaitOne(UpdateTimeoutMilliseconds))
                {
                    throw ExceptionBuilder.BuildFromID(typeof(MetriCam2Exception), this, 005);
                }

                lock (newFrameLock)
                {
                    try
                    {
                        if (multiFrameReference != null)
                        {
                            multiSourceFrame = multiFrameReference.AcquireFrame();
                        }
                    }
                    catch (Exception)
                    {
                        // ignore if the frame is no longer available
                        continue;// throw
                    }
                }

                try
                {
                    // fetch depth?
                    if (depthRequired)
                    {
                        DepthFrameReference depthFrameReference = multiSourceFrame.DepthFrameReference;
                        if (depthFrameReference != null)
                        {
                            // always synchornize on depth frames if possible.
                            if (lastTimeStamp == GetAbsoluteTimeStamp(depthFrameReference.RelativeTime.Ticks))
                            {
                                continue;
                            }
                            using (DepthFrame depthFrame = depthFrameReference.AcquireFrame())
                            {
                                if (depthFrame == null)
                                {
                                    continue;
                                }

                                depthFrameDescription = depthFrame.FrameDescription;
                                int depthWidth  = depthFrameDescription.Width;
                                int depthHeight = depthFrameDescription.Height;
                                if ((depthWidth * depthHeight) == this.depthFrameData.Length)
                                {
                                    lock (this.depthFrameData)
                                    {
                                        depthFrame.CopyFrameDataToArray(this.depthFrameData);
                                        lastTimeStamp  = GetAbsoluteTimeStamp(depthFrameReference.RelativeTime.Ticks);
                                        timestampDepth = lastTimeStamp;
                                    }
                                    depthRequired = false;
                                }
                            }
                        }
                    }

                    // fetch IR?
                    if (amplitudeRequired)
                    {
                        InfraredFrameReference irFrameReference = multiSourceFrame.InfraredFrameReference;
                        if (irFrameReference != null)
                        {
                            // If depth data is inactive, synchronize on IR frames. If depth and IR are inactive, we synchronize on color frames.
                            if (!(IsChannelActive(ChannelNames.Distance) || IsChannelActive(ChannelNames.Point3DImage)) && lastTimeStamp == GetAbsoluteTimeStamp(irFrameReference.RelativeTime.Ticks))
                            {
                                continue;
                            }

                            using (InfraredFrame irFrame = irFrameReference.AcquireFrame())
                            {
                                if (irFrame == null)
                                {
                                    continue;
                                }

                                FrameDescription irFrameDescription = irFrame.FrameDescription;
                                int irWidth  = irFrameDescription.Width;
                                int irHeight = irFrameDescription.Height;
                                if ((irWidth * irHeight) == this.irFrameData.Length)
                                {
                                    lock (this.irFrameData)
                                    {
                                        irFrame.CopyFrameDataToArray(this.irFrameData);
                                        lastTimeStamp = GetAbsoluteTimeStamp(irFrameReference.RelativeTime.Ticks);
                                        timestampIR   = lastTimeStamp;
                                    }
                                    amplitudeRequired = false;
                                }
                            }
                        }
                    }

                    // (always) fetch body frame
                    BodyFrameReference bodyFrameReference = multiSourceFrame.BodyFrameReference;
                    if (bodyFrameReference != null)
                    {
                        using (BodyFrame bodyFrame = bodyFrameReference.AcquireFrame())
                        {
                            if (bodyFrame != null)
                            {
                                this.bodies = new Body[bodyFrame.BodyCount];
                                using (bodyFrame)
                                {
                                    bodyFrame.GetAndRefreshBodyData(this.bodies);
                                }
                            }
                            else
                            {
                                // TODO: check if channel is activated.
                            }
                        }
                    }

                    // fetch color?
                    if (colorRequired)
                    {
                        ColorFrameReference colorFrameReference = multiSourceFrame.ColorFrameReference;
                        if (colorFrameReference == null)
                        {
                            continue;
                        }
                        // If depth and IR data is inactive, synchronize on color frames. If color, depth and IR are inactive, we don't care for synchronization.
                        if (!(IsChannelActive(ChannelNames.Distance) || IsChannelActive(ChannelNames.Point3DImage) || IsChannelActive(ChannelNames.Amplitude)) && lastTimeStamp == GetAbsoluteTimeStamp(colorFrameReference.RelativeTime.Ticks))
                        {
                            continue;
                        }

                        using (ColorFrame colorFrame = colorFrameReference.AcquireFrame())
                        {
                            //FrameDescription colorFrameDescription = colorFrame.FrameDescription;
                            //int cWidth = colorFrameDescription.Width;
                            //int cHeight = colorFrameDescription.Width;
                            if (colorFrame != null)
                            {
                                using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer())
                                {
                                    lock (this.colorFrameData)
                                    {
                                        colorFrame.CopyConvertedFrameDataToArray(this.colorFrameData, ColorImageFormat.Bgra);
                                        lastTimeStamp  = GetAbsoluteTimeStamp(colorFrameReference.RelativeTime.Ticks);
                                        timestampColor = lastTimeStamp;
                                    }
                                }
                                colorRequired = false;
                            }
                        }
                    }

                    // fetch long exposure IR? (this is independent of the IR images and are acquired at the same rate, so every new frame also
                    // has one of these.)
                    if (longExposureIRRequired)
                    {
                        LongExposureInfraredFrameReference longExposureIRFrameRef = multiSourceFrame.LongExposureInfraredFrameReference;
                        using (LongExposureInfraredFrame longIRFrame = longExposureIRFrameRef.AcquireFrame())
                        {
                            if (longIRFrame == null)
                            {
                                continue;
                            }

                            int longIRWidth  = longIRFrame.FrameDescription.Width;
                            int longIRHeight = longIRFrame.FrameDescription.Height;
                            if (longExposureIRData == null || (longIRWidth * longIRHeight) != longExposureIRData.Length)
                            {
                                longExposureIRData = new ushort[longIRWidth * longIRHeight];
                            }
                            longIRFrame.CopyFrameDataToArray(longExposureIRData);
                            longExposureIRRequired = false;
                        }
                    }

                    // fetch body index frames?
                    if (bodyIndexRequired)
                    {
                        BodyIndexFrameReference bodyIndexFrameRef = multiSourceFrame.BodyIndexFrameReference;
                        using (BodyIndexFrame bodyIndexFrame = bodyIndexFrameRef.AcquireFrame())
                        {
                            if (bodyIndexFrame == null)
                            {
                                log.Debug("bodyIndexFrame is NULL.");
                                continue;
                            }

                            int bodyIndexWidth  = bodyIndexFrame.FrameDescription.Width;
                            int bodyIndexHeight = bodyIndexFrame.FrameDescription.Height;
                            if (bodyIndexData == null || (bodyIndexWidth * bodyIndexHeight) != bodyIndexData.Length)
                            {
                                bodyIndexData = new byte[bodyIndexWidth * bodyIndexHeight];
                            }
                            bodyIndexFrame.CopyFrameDataToArray(bodyIndexData);
                            bodyIndexRequired = false;
                        }
                    }
                }
                catch (Exception)
                {
                    // ignore if the frame is no longer available
                }
                finally
                {
                    multiSourceFrame = null;
                }
            } while (depthRequired || colorRequired || bodyIndexRequired || longExposureIRRequired || amplitudeRequired);
        }
        void updatePulse(ColorFrameReference colorFrameReference, InfraredFrameReference irFrameReference, BodyFrameReference bodyFrameReference)
        {
            long currentTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

            int width = 0;
            int height = 0;
            try
            {
                InfraredFrame IRFrame = irFrameReference.AcquireFrame();

                if (IRFrame != null)
                {
                    using (IRFrame)
                    {
                        width = IRFrame.FrameDescription.Width;
                        height = IRFrame.FrameDescription.Height;

                        IRFrame.CopyFrameDataToArray(this.irImagePixelData);
                    }
                }
            }
            catch (Exception er)
            {
                string message = er.Message;
                Console.WriteLine(message);
                // Don't worry about empty frames.
            }
            try
            {
                if (this.bodyToTrack > -1)
                {
                    BodyFrame bodyFrame = bodyFrameReference.AcquireFrame();

                    if (bodyFrame != null)
                    {
                        using (bodyFrame)
                        {
                            bodyFrame.GetAndRefreshBodyData(this.bodies);

                            Body body = this.bodies[this.bodyToTrack];
                            if (body.IsTracked)
                            {
                                CameraSpacePoint headPosition = body.Joints[JointType.Head].Position;
                                CameraSpacePoint neckPosition = body.Joints[JointType.Neck].Position;

                                float centerX = neckPosition.X - headPosition.X;
                                centerX = headPosition.X + (centerX / 2.0f);

                                float centerY = neckPosition.Y - headPosition.Y;
                                centerY = headPosition.Y + (centerY / 2.0f);

                                centerX += 1.0f;
                                centerX /= 2.0f;

                                centerY += 1.0f;
                                centerY /= 2.0f;

                                if (this.colorImageBitmap != null)
                                {
                                    Color c = this.colorImageBitmap.GetPixel((int)(centerX * this.colorImageBitmap.Width), (int)(centerY * this.colorImageBitmap.Height));

                                    hueValues.Enqueue(c.GetHue());
                                    if (hueValues.Count > 10)
                                    {
                                        hueValues.Dequeue();
                                    }

                                    if (hueValues.Count >= 10)
                                    {
                                        //this.pulseLabel.Text = "Pulse: " + ((float)c.GetHue() / (float)hueValues.Average());
                                        if (c.GetHue() > hueValues.Average())
                                        {
                                            this.pulseLabel.Text = "Pulse: " + ((float)(currentTime - lastTime) / (float)pulses);
                                            //this.pulseLabel.Text = "Pulse: 1";
                                            pulses += 1;
                                        }
                                        if (currentTime - lastTime > 1000 * 5)
                                        {
                                            lastTime = currentTime;
                                            pulses = 0;
                                        }
                                        Console.WriteLine("Hue Average: " + hueValues.Average());
                                    }
                                }

                                if (width > 0 && height > 0)
                                {
                                    ushort irValue = this.irImagePixelData[(int)(centerX * width) + (int)(centerY * height) * width];

                                    irValues.Enqueue(irValue);
                                    if (irValues.Count > 10)
                                    {
                                        irValues.Dequeue();
                                    }

                                    if (irValues.Count >= 10)
                                    {
                                        //Console.WriteLine("IR Average: " + irValues.Average());
                                    }
                                }

                                //Console.WriteLine("Color: " + c.R + ", " + c.G + ", " + c.B);
                                //Console.WriteLine("Position:" + centerX + ", " + centerY);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                Console.WriteLine(message);
                // Don't worry about empty frames.
            }
        }
Example #33
0
        /// <summary>
        /// Handles the body frame data arriving from the sensor
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            BodyFrameReference frameReference = e.FrameReference;

            if (this.startTime.Ticks == 0)
            {
                this.startTime = frameReference.RelativeTime;
            }

            try
            {
                BodyFrame frame = frameReference.AcquireFrame();

                if (frame != null)
                {
                    // BodyFrame is IDisposable
                    using (frame)
                    {
                        this.framesSinceUpdate++;

                        // update status unless last message is sticky for a while
                        if (DateTime.Now >= this.nextStatusUpdate)
                        {
                            // calcuate fps based on last frame received
                            double fps = 0.0;

                            if (this.stopwatch.IsRunning)
                            {
                                this.stopwatch.Stop();
                                fps = this.framesSinceUpdate / this.stopwatch.Elapsed.TotalSeconds;
                                this.stopwatch.Reset();
                            }

                            this.nextStatusUpdate = DateTime.Now + TimeSpan.FromSeconds(1);
                            this.StatusText       = string.Format(Properties.Resources.StandardStatusTextFormat, fps, frameReference.RelativeTime - this.startTime);
                        }

                        if (!this.stopwatch.IsRunning)
                        {
                            this.framesSinceUpdate = 0;
                            this.stopwatch.Start();
                        }

                        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, this.displayWidth, this.displayHeight));

                            // 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);

                            foreach (Body body in this.bodies)
                            {
                                if (body.IsTracked)
                                {
                                    this.DrawClippedEdges(body, dc);

                                    IReadOnlyDictionary <JointType, Joint> joints = body.Joints;

                                    // convert the joint points to depth (display) space
                                    Dictionary <JointType, Point> jointPoints = new Dictionary <JointType, Point>();
                                    foreach (JointType jointType in joints.Keys)
                                    {
                                        DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(joints[jointType].Position);
                                        jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                                    }

                                    this.DrawBody(joints, jointPoints, dc);

                                    this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc);
                                    this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc);

                                    Dictionary <JointType, Vector3D> bodyVectors = MapJointsToVectors(joints);

                                    bodyPartTree = new TreeBodyPart(bodyVectors, Side.C, BodyPart.SpineMid, Brushes.Firebrick);

                                    ////Language Test
                                    //IEnumerable<TreeBodyPart> res;
                                    //res = bodyPartTree.spineshoulder();
                                    //foreach (var b in res)
                                    //{
                                    //	bodyPartTree = b;
                                    //}
                                    ////res = bodyPartTree.elbow();
                                    ////foreach (var b in res)
                                    ////{
                                    ////	bodyPartTree = b;
                                    ////}
                                    //bodyPartTree.ReComputeLabel();
                                    //this.FeedbackText.Visibility = System.Windows.Visibility.Visible;
                                    //if (bodyPartTree.ispointingup())
                                    //	this.FeedbackText.Text = "straight";
                                    //else
                                    //	this.FeedbackText.Text = "take care";
                                    //res = bodyPartTree.resetjt();
                                    //foreach (var b in res)
                                    //{
                                    //	bodyPartTree = b;
                                    //}

                                    if (started && first)
                                    {
                                        first   = false;
                                        updated = true;
                                    }

                                    if (updated)
                                    {
                                        //If a skeleton has matched we compute the new set of available moves
                                        if (matched)
                                        {
                                            moves   = moveSeq.AvailableMoves();
                                            myPen   = new List <Pen>();
                                            shadows = new List <TreeBodyPart>();

                                            shadow = new TreeBodyPart(bodyVectors, Side.C, BodyPart.SpineMid, Brushes.AliceBlue);
                                            //foreach (Transduction m in moves)
                                            //{
                                            shadow = shadow.MakeMove(moves[0]);
                                            while (!shadow.IsActivated() && !moveSeq.isFinal())
                                            {
                                                moveSeq.MakeOneStep(moves[0]);
                                                moves  = moveSeq.AvailableMoves();
                                                shadow = shadow.MakeMove(moves[0]);
                                            }

                                            shadows.Add(shadow);
                                            shadow = new TreeBodyPart(bodyVectors, Side.C, BodyPart.SpineMid, Brushes.AliceBlue);
                                            //}
                                            matched = false;
                                        }

                                        for (int i = 0; i < shadows.Count; i++)
                                        {
                                            if (bodyPartTree.SimilarTo(shadows[i]))
                                            {
                                                moveSeq.MakeOneStep(moves[i]);
                                                if (moveSeq.isFinal())
                                                {
                                                    updated = false;
                                                    started = false;
                                                    ActivIn();
                                                }
                                                else
                                                {
                                                    matched = true;
                                                }
                                                break;
                                            }
                                        }
                                    }

                                    if (started && updated)
                                    {
                                        foreach (var s in shadows)
                                        {
                                            Dictionary <JointType, Vector3D> vectors = new Dictionary <JointType, Vector3D>();
                                            Dictionary <JointType, bool>     actList = new Dictionary <JointType, bool>();
                                            s.GetVectors(ref vectors, ref actList);
                                            //Dictionary<JointType, Joint> shadowJoints = MapVectorsToJoints(vectors, joints);
                                            Dictionary <JointType, Joint> shadowJoints = MapShadowVectorsToJoints(vectors, actList, joints);

                                            Dictionary <JointType, Point> shadowJointPoints = new Dictionary <JointType, Point>();
                                            foreach (JointType shadowJointType in shadowJoints.Keys)
                                            {
                                                DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(shadowJoints[shadowJointType].Position);
                                                shadowJointPoints[shadowJointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                                            }

                                            this.DrawShadow(shadowJointPoints, jointPoints, actList, dc);
                                        }
                                    }

                                    // prevent drawing outside of our render area
                                    //this.Dispatcher.Invoke(new Clipp(this.ClippIn), new object[] { });
                                }
                            }

                            // prevent drawing outside of our render area
                            this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));
                        }
                    }
                }
            }
            catch (Exception)
            {
                // ignore if the frame is no longer available
            }
        }
        void useBodyFrame(BodyFrameReference bodyFrameReference)
        {
            try
            {
                BodyFrame bodyFrame = bodyFrameReference.AcquireFrame();

                if (bodyFrame != null)
                {
                    using (bodyFrame)
                    {
                        bodyFrame.GetAndRefreshBodyData(this.bodies);
                        if (this.bodyToTrack < 0)
                        {
                            this.findBodyToTrack();
                        }

                        if (this.bodyToTrack > -1)
                        {
                            this.updateCurrentBody();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                Console.WriteLine(message);
                // Don't worry about empty frames.
            }
        }
Example #35
0
        private void ProcessJoints(BodyFrameReference aReference)
        {
            using (BodyFrame bodyFrame = aReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    _bodies = new Body[bodyFrame.BodyFrameSource.BodyCount];

                    bodyFrame.GetAndRefreshBodyData(_bodies);

                    lock (hands)
                    {
                        hands.Clear();
                    }

                    foreach (var body in _bodies)
                    {
                        if (body != null)
                        {
                            if (body.IsTracked)
                            {
                                JointType[] JointsToGet = { JointType.HandRight, JointType.HandLeft };

                                //Console.WriteLine("I can see a joint at:" + handRight.Position.X + ", " + handRight.Position.Y + ", " + handRight.Position.Z);

                                foreach (JointType jt in JointsToGet)
                                {
                                    lock (hands)
                                    {
                                        hands.Add(MapJointToPoint(body.Joints[jt]));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #36
0
 public void notify(BodyFrameReference reference)
 {
 }
Example #37
0
        /// <summary>
        /// Update to get a new frame.
        /// This code is similar to the code in the Kinect SDK samples.
        /// </summary>
        private static void Update()
        {
            if (!isConnected)
            {
                return;
            }

            dataAvailable.WaitOne();

            MultiSourceFrame multiSourceFrame = null;
            DepthFrame       depthFrame       = null;
            InfraredFrame    irFrame          = null;
            BodyFrame        bodyFrame        = null;

            lock (updateLock)
            {
                try
                {
                    if (frameReference != null)
                    {
                        multiSourceFrame = frameReference.AcquireFrame();

                        if (multiSourceFrame != null)
                        {
                            DepthFrameReference    depthFrameReference = multiSourceFrame.DepthFrameReference;
                            InfraredFrameReference irFrameReference    = multiSourceFrame.InfraredFrameReference;
                            BodyFrameReference     bodyFrameReference  = multiSourceFrame.BodyFrameReference;

                            depthFrame = depthFrameReference.AcquireFrame();
                            irFrame    = irFrameReference.AcquireFrame();

                            if ((depthFrame != null) && (irFrame != null))
                            {
                                FrameDescription depthFrameDescription = depthFrame.FrameDescription;
                                FrameDescription irFrameDescription    = irFrame.FrameDescription;

                                int depthWidth  = depthFrameDescription.Width;
                                int depthHeight = depthFrameDescription.Height;
                                int irWidth     = irFrameDescription.Width;
                                int irHeight    = irFrameDescription.Height;

                                // verify data and write the new registered frame data to the display bitmap
                                if (((depthWidth * depthHeight) == depthFrameData.Length) &&
                                    ((irWidth * irHeight) == irFrameData.Length))
                                {
                                    depthFrame.CopyFrameDataToArray(depthFrameData);
                                    irFrame.CopyFrameDataToArray(irFrameData);
                                }

                                if (bodyFrameReference != null)
                                {
                                    bodyFrame = bodyFrameReference.AcquireFrame();

                                    if (bodyFrame != null)
                                    {
                                        if (bodies == null || bodies.Length < bodyFrame.BodyCount)
                                        {
                                            bodies = new Body[bodyFrame.BodyCount];
                                        }
                                        using (bodyFrame)
                                        {
                                            bodyFrame.GetAndRefreshBodyData(bodies);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // ignore if the frame is no longer available
                }
                finally
                {
                    if (depthFrame != null)
                    {
                        depthFrame.Dispose();
                        depthFrame = null;
                    }

                    if (irFrame != null)
                    {
                        irFrame.Dispose();
                        irFrame = null;
                    }
                    if (bodyFrame != null)
                    {
                        bodyFrame.Dispose();
                        bodyFrame = null;
                    }
                    if (multiSourceFrame != null)
                    {
                        multiSourceFrame = null;
                    }
                }
            }
        }