Пример #1
0
 public static AccelerationGesture AddAccelerationGesture(this User user)
 {
     var gesture = new AccelerationGesture();
     var fpsFilter = new FramesFilter(6);
     user.AttachPipeline(fpsFilter);
     fpsFilter.AttachPipeline(gesture);
     return gesture;
 }
Пример #2
0
 public static SemaphoreGesture AddSemaphoreTouchGesture(this User user)
 {
     var gesture = new SemaphoreGesture();
     var fpsFilter = new FramesFilter(6);
     user.AttachPipeline(fpsFilter);
     fpsFilter.AttachPipeline(gesture);
     return gesture;
 }
        public static AccelerationGesture AddAccelerationGesture(this User user)
        {
            var gesture   = new AccelerationGesture();
            var fpsFilter = new FramesFilter(6);

            user.AttachPipeline(fpsFilter);
            fpsFilter.AttachPipeline(gesture);
            return(gesture);
        }
        public static SemaphoreGesture AddSemaphoreTouchGesture(this User user)
        {
            var gesture   = new SemaphoreGesture();
            var fpsFilter = new FramesFilter(6);

            user.AttachPipeline(fpsFilter);
            fpsFilter.AttachPipeline(gesture);
            return(gesture);
        }
Пример #5
0
        private void KinectUserCreated(object sender, KinectUserEventArgs e)
        {
            WindowMessage = "User found";
            lock (SyncRoot)
            {
                if (_activeUser != null)
                {
                    return;
                }
                _activeUser          = _kinect.GetUser(e.User.Id);
                _activeUser.Updated += ActiveUserUpdated;

                var framesFilter = new FramesFilter(15);

                //Initialize filters
                _lefthandRighthandCollision     = new CollisionFilter(new Point3D(100, 50, 130), JointID.HandLeft, JointID.HandRight);
                _lefthandHeadCollision          = new CollisionFilter(new Point3D(150, 30, 500), JointID.HandLeft, JointID.Head);
                _lefthandRightShoulderCollision = new CollisionFilter(new Point3D(50, 50, 300), JointID.HandLeft, JointID.ShoulderRight);
                _righthandHeadCollision         = new CollisionFilter(new Point3D(125, 40, 150), JointID.HandRight, JointID.Head);
                _righthandLeftShoulderCollision = new CollisionFilter(new Point3D(50, 50, 300), JointID.HandRight, JointID.ShoulderLeft);
                _righthandRightHipCollision     = new CollisionFilter(new Point3D(80, 30, 200), JointID.HandRight, JointID.HipRight);

                //Initialize gestures
                _lefthandRighthandGesture     = new SelfTouchGesture(1);
                _lefthandHeadGesture          = new SelfTouchGesture(1);
                _lefthandRightShoulderGesture = new SelfTouchGesture(1);
                _righthandHeadGesture         = new SelfTouchGesture(1);
                _righthandLeftShoulderGesture = new SelfTouchGesture(1);
                _righthandRightHipGesture     = new SelfTouchGesture(1);

                //Attach filters and gestures
                _activeUser.AttachPipeline(framesFilter);
                framesFilter.AttachPipeline(_lefthandRighthandCollision);
                framesFilter.AttachPipeline(_lefthandHeadCollision);
                framesFilter.AttachPipeline(_lefthandRightShoulderCollision);
                framesFilter.AttachPipeline(_righthandHeadCollision);
                framesFilter.AttachPipeline(_righthandLeftShoulderCollision);
                framesFilter.AttachPipeline(_righthandRightHipCollision);
                _lefthandRighthandCollision.AttachPipeline(_lefthandRighthandGesture);
                _lefthandHeadCollision.AttachPipeline(_lefthandHeadGesture);
                _lefthandRightShoulderCollision.AttachPipeline(_lefthandRightShoulderGesture);
                _righthandHeadCollision.AttachPipeline(_righthandHeadGesture);
                _righthandLeftShoulderCollision.AttachPipeline(_righthandLeftShoulderGesture);
                _righthandRightHipCollision.AttachPipeline(_righthandRightHipGesture);

                _righthandLeftShoulderGesture.SelfTouchDetected += SwitchMode;

                //Debug info
                //_righthandLeftShoulderCollision.Filtered += (s, args) => ShowDebugInfo(args, "Filter info: ");
                _lefthandRightShoulderGesture.SelfTouchDetected += FireCustomEvent;
                SwitchMode(null, null);
            }
        }
Пример #6
0
        private void KinectUserCreated(object sender, KinectUserEventArgs e)
        {
            WindowMessage = "User found";
            lock (SyncRoot)
            {
                if (_activeUser != null)
                {
                    return;
                }
                _activeUser = _kinect.GetUser(e.User.Id);
                _activeUser.Updated += ActiveUserUpdated;

                var framesFilter = new FramesFilter(15);

                //Initialize filters
                _lefthandRighthandCollision = new CollisionFilter(new Point3D(100, 50, 130), JointID.HandLeft, JointID.HandRight);
                _lefthandHeadCollision = new CollisionFilter(new Point3D(150, 30, 500), JointID.HandLeft, JointID.Head);
                _lefthandRightShoulderCollision = new CollisionFilter(new Point3D(50, 50, 300), JointID.HandLeft, JointID.ShoulderRight);
                _righthandHeadCollision = new CollisionFilter(new Point3D(125, 40, 150), JointID.HandRight, JointID.Head);
                _righthandLeftShoulderCollision = new CollisionFilter(new Point3D(50, 50, 300), JointID.HandRight, JointID.ShoulderLeft);
                _righthandRightHipCollision = new CollisionFilter(new Point3D(80, 30, 200), JointID.HandRight, JointID.HipRight);

                //Initialize gestures
                _lefthandRighthandGesture = new SelfTouchGesture(1);
                _lefthandHeadGesture = new SelfTouchGesture(1);
                _lefthandRightShoulderGesture = new SelfTouchGesture(1);
                _righthandHeadGesture = new SelfTouchGesture(1);
                _righthandLeftShoulderGesture = new SelfTouchGesture(1);
                _righthandRightHipGesture = new SelfTouchGesture(1);

                //Attach filters and gestures
                _activeUser.AttachPipeline(framesFilter);
                framesFilter.AttachPipeline(_lefthandRighthandCollision);
                framesFilter.AttachPipeline(_lefthandHeadCollision);
                framesFilter.AttachPipeline(_lefthandRightShoulderCollision);
                framesFilter.AttachPipeline(_righthandHeadCollision);
                framesFilter.AttachPipeline(_righthandLeftShoulderCollision);
                framesFilter.AttachPipeline(_righthandRightHipCollision);
                _lefthandRighthandCollision.AttachPipeline(_lefthandRighthandGesture);
                _lefthandHeadCollision.AttachPipeline(_lefthandHeadGesture);
                _lefthandRightShoulderCollision.AttachPipeline(_lefthandRightShoulderGesture);
                _righthandHeadCollision.AttachPipeline(_righthandHeadGesture);
                _righthandLeftShoulderCollision.AttachPipeline(_righthandLeftShoulderGesture);
                _righthandRightHipCollision.AttachPipeline(_righthandRightHipGesture);

                _righthandLeftShoulderGesture.SelfTouchDetected += SwitchMode;

                //Debug info
                //_righthandLeftShoulderCollision.Filtered += (s, args) => ShowDebugInfo(args, "Filter info: ");
                _lefthandRightShoulderGesture.SelfTouchDetected += FireCustomEvent;
                SwitchMode(null, null);
            }
        }
        private static List <Filter <IUserChangedEvent> > GetFilters(XElement filters, params JointID[] joints)
        {
            IOrderedEnumerable <XElement> myFilters = from node in filters.Descendants()
                                                      orderby node.Attribute(XName.Get("Sequence")).Value ascending
                                                      select node;

            var filterCollection = new List <Filter <IUserChangedEvent> >(myFilters.Count());

            foreach (XElement filter in myFilters)
            {
                Filter <IUserChangedEvent> createdFilter = null;
                if (filter.Name == "FramesFilter")
                {
                    int    fpsCount;
                    string fps = filter.Attribute(XName.Get("FPS")).Value;
                    if (int.TryParse(fps, out fpsCount))
                    {
                        createdFilter = new FramesFilter(fpsCount);
                    }
                    else
                    {
                        createdFilter = new FramesFilter(10);
                    }
                }
                else if (filter.Name == "CollisionFilter")
                {
                    int    x, y, z;
                    string xValue = filter.Attribute(XName.Get("MarginX")).Value;
                    string yValue = filter.Attribute(XName.Get("MarginY")).Value;
                    string zValue = filter.Attribute(XName.Get("MarginZ")).Value;

                    if (int.TryParse(xValue, out x) && int.TryParse(yValue, out y) && int.TryParse(zValue, out z))
                    {
                        createdFilter = new CollisionFilter(new Point3D(x, y, z), joints);
                    }
                    else
                    {
                        var exception = new ArgumentException("You need to provide the XYZ margins");

                        _log.IfError(string.Empty, exception);

                        throw exception;
                    }
                }
                else if (filter.Name == "CorrectionFilter")
                {
                    var correction = new Point3D();
                    correction.X = SafeFloatParse(filter.Attribute(XName.Get("MarginX")));
                    correction.Y = SafeFloatParse(filter.Attribute(XName.Get("MarginY")));
                    correction.Z = SafeFloatParse(filter.Attribute(XName.Get("MarginZ")));
                    JointID joint;

                    //TODO better catch if XML isn't correct? DTD
                    if (Enum.TryParse(filter.Attribute(XName.Get("SkeletonJoint")).Value, out joint))
                    {
                        createdFilter = new CorrectionFilter(joint, correction);
                    }
                    else
                    {
                        var exception = new ArgumentException("You need to provide a SkeletonJoint to correct");

                        _log.IfError(string.Empty, exception);

                        throw exception;
                    }
                }
                else
                {
                    var exception = new ArgumentException("The provided filter isn't supported");

                    _log.IfError(string.Empty, exception);

                    throw exception;
                }

                if (createdFilter != null)
                {
                    filterCollection.Add(createdFilter);
                }
            }
            return(filterCollection);
        }
Пример #8
0
        private static List<Filter<IUserChangedEvent>> GetFilters(XElement filters, params JointID[] joints)
        {
            IOrderedEnumerable<XElement> myFilters = from node in filters.Descendants()
                                                     orderby node.Attribute(XName.Get("Sequence")).Value ascending
                                                     select node;

            var filterCollection = new List<Filter<IUserChangedEvent>>(myFilters.Count());
            foreach (XElement filter in myFilters)
            {
                Filter<IUserChangedEvent> createdFilter = null;
                if (filter.Name == "FramesFilter")
                {
                    int fpsCount;
                    string fps = filter.Attribute(XName.Get("FPS")).Value;
                    if (int.TryParse(fps, out fpsCount))
                    {
                        createdFilter = new FramesFilter(fpsCount);
                    }
                    else
                    {
                        createdFilter = new FramesFilter(10);
                    }
                }
                else if (filter.Name == "CollisionFilter")
                {
                    int x, y, z;
                    string xValue = filter.Attribute(XName.Get("MarginX")).Value;
                    string yValue = filter.Attribute(XName.Get("MarginY")).Value;
                    string zValue = filter.Attribute(XName.Get("MarginZ")).Value;

                    if (int.TryParse(xValue, out x) && int.TryParse(yValue, out y) && int.TryParse(zValue, out z))
                    {
                        createdFilter = new CollisionFilter(new Point3D(x, y, z), joints);
                    }
                    else
                    {
                        var exception = new ArgumentException("You need to provide the XYZ margins");

                        _log.IfError(string.Empty, exception);

                        throw exception;
                    }
                }
                else if (filter.Name == "CorrectionFilter")
                {
                    var correction = new Point3D();
                    correction.X = SafeFloatParse(filter.Attribute(XName.Get("MarginX")));
                    correction.Y = SafeFloatParse(filter.Attribute(XName.Get("MarginY")));
                    correction.Z = SafeFloatParse(filter.Attribute(XName.Get("MarginZ")));
                    JointID joint;

                    //TODO better catch if XML isn't correct? DTD
                    if (Enum.TryParse(filter.Attribute(XName.Get("SkeletonJoint")).Value, out joint))
                    {
                        createdFilter = new CorrectionFilter(joint, correction);
                    }
                    else
                    {
                        var exception = new ArgumentException("You need to provide a SkeletonJoint to correct");

                        _log.IfError(string.Empty, exception);

                        throw exception;
                    }
                }
                else
                {
                    var exception = new ArgumentException("The provided filter isn't supported");

                    _log.IfError(string.Empty, exception);

                    throw exception;
                }

                if (createdFilter != null)
                {
                    filterCollection.Add(createdFilter);
                }
            }
            return filterCollection;
        }