Example #1
0
        private void ProcessFrame(SkeletonFrame frame)
        {
            foreach (var skeleton in frame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                foreach (Joint joint in skeleton.Joints)
                {
                    if (joint.Position.W < 0.8f || joint.TrackingState != JointTrackingState.Tracked)
                    {
                        continue;
                    }

                    if (joint.ID == JointID.HandRight)
                    {
                        gestureRecognizer.Add(joint.Position, kinectRuntime.SkeletonEngine);
                    }
                }

                skeletonDisplayManager.Draw(frame);
            }
        }
Example #2
0
        void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            using (var frame = e.OpenColorImageFrame())
            {
                if (frame == null)
                {
                    return;
                }

                imageCanvas.Background = new ImageBrush(frame.ToBitmapSource());
            }

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

                var skeletons = frame.GetSkeletons().Where(x => x.TrackingState == SkeletonTrackingState.Tracked).ToArray();
                skeletonDisplayManager.Draw(skeletons, false);

                var skeleton = skeletons.FirstOrDefault();
                if (skeleton != null)
                {
                    var handJoint = skeleton.Joints.First(x => x.JointType == JointType.HandRight);
                    gestureDetector.Add(handJoint.Position, sensor);
                    postureDetector.TrackPostures(skeleton);
                }
            }
        }
Example #3
0
        void UpdateSkeletonDisplay(ReplaySkeletonFrame frame)
        {
            if (frame.Skeletons == null)
            {
                return;
            }
            Dictionary <int, string> stabilities = new Dictionary <int, string>();

            foreach (var skeleton in frame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                contextTracker.Add(skeleton.Position.ToVector3(), skeleton.TrackingId);
                stabilities.Add(skeleton.TrackingId,
                                contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId) ?
                                "Stable" : "Non stable");
            }

            try {
                if (viewSkeleton && skeletonDisplayManager != null)
                {
                    skeletonDisplayManager.Draw(frame.Skeletons, false,
                                                HandInputParams.ColorImageFormat);
                }
                else
                {
                    skeletonCanvas.Children.Clear();
                }
            } catch (Exception e) {
                Log.Error(e.Message);
            }
        }
Example #4
0
        void ProcessSkeletonFrame(SkeletonFrame frame)
        {
            if (gestureRecognizer != null)
            {
                gestureRecognizer.Update(frame);
            }

            if (skeletonDisplayManager != null)
            {
                skeletonDisplayManager.Draw(frame);
            }
        }
Example #5
0
        private static void AttachKinect()
        {
            if (_skeletonDisplayManager != null)
            {
                return;
            }

            //var kinectSensor = DependencyFactory.Container.Resolve<KinectSensor>();
            var testKinect = DependencyFactory.Container.Resolve<TKinect.TKinect>();

            var framesCollector = new FramesCollector(testKinect);
            _skeletonDisplayManager = new SkeletonDisplayManager(_kinectCanvas);
            framesCollector.FrameReady += (sender, arg) => _skeletonDisplayManager.Draw(arg.Frames.Last().Skeletons, false);
        }
Example #6
0
        void ProcessFrame(ReplaySkeletonFrame frame)
        {
            Dictionary <int, string> stabilities = new Dictionary <int, string>();

            foreach (var skeleton in frame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                barycenterHelper.Add(skeleton.Position.ToVector3(), skeleton.TrackingID);

                stabilities.Add(skeleton.TrackingID, barycenterHelper.IsStable(skeleton.TrackingID) ? "Stable" : "Unstable");
                if (!barycenterHelper.IsStable(skeleton.TrackingID))
                {
                    continue;
                }

                if (recordNextFrameForPosture)
                {
                    recordNextFrameForPosture = false;
                    templatePostureDetector.AddTemplate(skeleton);
                }

                foreach (Joint joint in skeleton.Joints)
                {
                    if (joint.Position.W < 0.8f || joint.TrackingState != JointTrackingState.Tracked)
                    {
                        continue;
                    }

                    if (joint.ID == JointID.HandRight)
                    {
                        swipeGestureRecognizer.Add(joint.Position, kinectRuntime.SkeletonEngine);
                        circleGestureRecognizer.Add(joint.Position, kinectRuntime.SkeletonEngine);
                    }
                }

                algorithmicPostureRecognizer.TrackPostures(skeleton);
                templatePostureDetector.TrackPostures(skeleton);
            }

            skeletonDisplayManager.Draw(frame);

            stabilitiesList.ItemsSource = stabilities;

            currentPosture.Text = "Current posture: " + algorithmicPostureRecognizer.CurrentPosture.ToString();
        }
Example #7
0
        private static void AttachKinect()
        {
            if (_skeletonDisplayManager != null)
            {
                return;
            }

            //var kinectSensor = DependencyFactory.Container.Resolve<KinectSensor>();
            var testKinect = DependencyFactory.Container.Resolve <TKinect.TKinect>();

            var framesCollector = new FramesCollector(testKinect);

            _skeletonDisplayManager     = new SkeletonDisplayManager(_kinectCanvas);
            framesCollector.FrameReady += (sender, arg) => _skeletonDisplayManager.Draw(arg.Frames.Last().Skeletons, false);
        }
Example #8
0
        void kinectRuntime_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            SkeletonFrame skeletonFrame = e.SkeletonFrame;

            foreach (SkeletonData data in skeletonFrame.Skeletons)
            {
                if (data.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                barycenterHelper.Add(data.Position.ToVector3(), data.TrackingID);
                if (!barycenterHelper.IsStable(data.TrackingID))
                {
                    continue;
                }

                foreach (Joint joint in data.Joints)
                {
                    if (joint.Position.W < 0.8f || joint.TrackingState != JointTrackingState.Tracked)
                    {
                        continue;
                    }

                    if (joint.ID == JointID.HandRight)
                    {
                        rightHandGestureRecognizer.Add(joint.Position, kinectRuntime.SkeletonEngine);
                        Trace.WriteLine(Gesture.Content = "HandRight.Add");
                    }
                }

                // ポーズの検出
                postureRecognizer.TrackPostures(data);
            }

            // スケルトンの描画
            skeletonDisplayManager.Draw(e.SkeletonFrame);

            labelPose.Content = "Pose: " + postureRecognizer.CurrentPosture.ToString();
        }
Example #9
0
        void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            using (var frame = e.OpenColorImageFrame())
            {
                if (frame == null)
                {
                    return;
                }

                imageCanvas.Background = new ImageBrush(frame.ToBitmapSource());
            }

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

                var skeletons = frame.GetSkeletons().Where(x => x.TrackingState == SkeletonTrackingState.Tracked).ToArray();
                skeletonDisplayManager.Draw(skeletons, false);
            }
        }
Example #10
0
 void ProcessFrame(ReplaySkeletonFrame frame)
 {
     SkeletonDisplayManager.Draw(frame.Skeletons, Models.Settings.SeatedMode);
 }
Example #11
0
        void ProcessFrame(ReplaySkeletonFrame frame)
        {
            Dictionary <int, string> stabilities = new Dictionary <int, string>();

            foreach (var skeleton in frame.Skeletons)
            {
                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                //if (eyeTracker == null)
                //    eyeTracker = new EyeTracker(kinectSensor);

                //eyeTracker.Track(skeleton);

                contextTracker.Add(skeleton.Position.ToVector3(), skeleton.TrackingId);
                stabilities.Add(skeleton.TrackingId, contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId) ? "Stable" : "Non stable");
                if (!contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId))
                {
                    continue;
                }

                //if (eyeTracker.IsLookingToSensor.HasValue && eyeTracker.IsLookingToSensor == false)
                //    continue;

                foreach (Joint joint in skeleton.Joints)
                {
                    if (joint.TrackingState != JointTrackingState.Tracked)
                    {
                        continue;
                    }

                    if (joint.JointType == JointType.HandRight)
                    {
                        circleGestureRecognizer.Add(joint.Position, kinectSensor);
                    }
                    else if (joint.JointType == JointType.HandLeft)
                    {
                        swipeGestureRecognizer.Add(joint.Position, kinectSensor);
                        if (controlMouse.IsChecked == true)
                        {
                            MouseController.Current.SetHandPosition(kinectSensor, joint, skeleton);
                        }
                    }
                }

                algorithmicPostureRecognizer.TrackPostures(skeleton);
                templatePostureDetector.TrackPostures(skeleton);

                if (recordNextFrameForPosture)
                {
                    templatePostureDetector.AddTemplate(skeleton);
                    recordNextFrameForPosture = false;
                }
            }

            skeletonDisplayManager.Draw(frame.Skeletons, seatedMode.IsChecked == true);

            stabilitiesList.ItemsSource = stabilities;
        }
Example #12
0
        void ProcessFrame(ReplaySkeletonFrame frame)
        {
            Dictionary <int, string> stabilities = new Dictionary <int, string>();

            foreach (var skeleton in frame.Skeletons)
            {
                StringBuilder strBuilder = new StringBuilder();

                if (skeleton.TrackingState != SkeletonTrackingState.Tracked)
                {
                    continue;
                }

                //timer for recording and wait
                if (!timerWait.IsRunning && (timerRec.Elapsed.Seconds > 2 || !timerRec.IsRunning))
                {
                    timerRec.Stop();
                    timerRec.Reset();
                    //Console.WriteLine("Please wait while we process the gesture......");
                    //strBuilder.Append("Please wait while we process the gesture......\n");
                    ProcessGesture();
                    timerWait.Reset();
                    timerWait.Start();
                }
                if (timerWait.Elapsed.Seconds >= 5 && !timerRec.IsRunning)
                {
                    //Console.WriteLine("Gesture recorded, NEXT GESTURE!");
                    //strBuilder.Append("Gesture recorded, NEXT GESTURE!\n");
                    timerWait.Stop();
                    timerRec.Start();
                }

                /*contextTracker.Add(skeleton.Position.ToVector3(), skeleton.TrackingId);
                 * stabilities.Add(skeleton.TrackingId, contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId) ? "Stable" : "Non stable");
                 * if (!contextTracker.IsStableRelativeToCurrentSpeed(skeleton.TrackingId))
                 *  continue;
                 */
                bool touchedLeft  = false;
                bool touchedRight = false;
                foreach (Joint joint in skeleton.Joints)
                {
                    if (status == RecordingStatus.STOP)
                    {
                        break;
                    }

                    if (!timerRec.IsRunning)
                    {
                        continue;
                    }

                    if (m_useGestureLocked && (System.DateTime.Now >= m_timeToEndAt))
                    {
                        strBuilder.Append("Unlocking");
                        m_useGestureLocked = false;
                        break;
                    }
                    else if (m_useGestureLocked)
                    {
                        strBuilder.Append("Locked - " + m_gestureLockMessage);
                        break;
                    }

                    if (joint.TrackingState != JointTrackingState.Tracked)
                    {
                        continue;
                    }
                    //strBuilder.Append(joint.JointType.ToString());

                    if (status == RecordingStatus.RECORD)
                    {
                        if (joint.JointType.Equals(JointType.HandRight))
                        {
                            Console.WriteLine(String.Format("Right [{0}, {1}, {2}]", joint.Position.X, joint.Position.Y, joint.Position.Z));
                            strBuilder.Append(String.Format("\nRight [{0}, {1}, {2}]", joint.Position.X, joint.Position.Y, joint.Position.Z));
                            rightList.Add(new CoordinateContainer(joint.Position.X, joint.Position.Y));
                        }
                        else if (joint.JointType.Equals(JointType.HandLeft))
                        {
                            Console.WriteLine(String.Format("Left [{0}, {1}, {2}]", joint.Position.X, joint.Position.Y, joint.Position.Z));
                            strBuilder.Append(String.Format("\nLeft [{0}, {1}, {2}]", joint.Position.X, joint.Position.Y, joint.Position.Z));
                            leftList.Add(new CoordinateContainer(joint.Position.X, joint.Position.Y));
                        }
                    }
                    else if (status == RecordingStatus.USE)
                    {
                        double cur_pos = joint.Position.Y;
                        if (joint.JointType.Equals(JointType.HandRight))
                        {
                            //Console.WriteLine(String.Format("Using right: [{0}, {1}]", joint.Position.X, joint.Position.Y));
                            //strBuilder.Append(String.Format("\nUsing right: [{0}, {1}]", joint.Position.X, joint.Position.Y));
                            //assume gesture array have only 6 elements
                            int rightIndex = 0;
                            foreach (CoordinateContainer container in gesture1_right)
                            {
                                touchedRight |= IsWithinRange(joint.Position.Y, container.getY()) || IsWithinRange(joint.Position.X, container.getX());
                                if (touchedRight)
                                {
                                    m_rightIndex = rightIndex;
                                    break;
                                }
                                rightIndex++;
                            }
                            if (touchedRight)
                            {
                                if (m_rightIndex != -1)
                                {
                                    Console.WriteLine("Right Hand gesture detected " + gesture1_right[m_rightIndex].name);
                                }
                                //strBuilder.Append("\nRight Hand gesture detected");
                            }
                        }
                        else if (joint.JointType.Equals(JointType.HandLeft))
                        {
                            //Console.WriteLine(String.Format("Using left: [{0}, {1}]", joint.Position.X, joint.Position.Y));
                            //strBuilder.Append(String.Format("\nUsing left: [{0}, {1}]", joint.Position.X, joint.Position.Y));
                            //assume gesture array have only 6 elements
                            int leftIndex = 0;
                            foreach (CoordinateContainer container in gesture1_left)
                            {
                                touchedLeft |= IsWithinRange(joint.Position.Y, container.getY()) || IsWithinRange(joint.Position.X, container.getX());
                                if (touchedLeft)
                                {
                                    m_leftIndex = leftIndex;
                                    break;
                                }
                                leftIndex++;
                            }
                            if (touchedLeft)
                            {
                                if (m_leftIndex != -1)
                                {
                                    Console.WriteLine("Left Hand gesture detected " + gesture1_left[m_leftIndex].name);
                                }
                                //strBuilder.Append("\nLeft Hand gesture detected");
                            }
                        }

                        //if a gesture was discovered, lock for time buffer
                        if (m_rightIndex != -1 && m_leftIndex != -1)
                        {
                            if (m_rightIndex == m_leftIndex)
                            {
                                m_timeToEndAt        = System.DateTime.Now.AddSeconds(k_secondsToBuffer);
                                m_useGestureLocked   = true;
                                m_gestureLockMessage = strBuilder.ToString();
                                strBuilder.Append("\n" + gesture1_right[m_leftIndex].name);
                                Console.WriteLine(gesture1_right[m_leftIndex].name);
                                m_codeString     = m_codeString + gesture1_right[m_leftIndex].name + " ";
                                codeView.Content = m_codeString;
                                m_leftIndex      = -1;
                                m_rightIndex     = -1;
                                touchedRight     = false;
                                touchedLeft      = false;
                            }
                        }
                    }
                }

                //MessageBox.Show(strBuilder.ToString());

                //this is the place to draw sitting position or not
                skeletonDisplayManager.Draw(frame.Skeletons, false);
                Output.Text = strBuilder.ToString();
                //we only care about 1 skeleton
                break;
            }
        }