Exemplo n.º 1
0
        private void TrackGesture(Skeleton skeleton, ref GestureTracker tracker, long timeStamp)
        {
            Joint leftHand = skeleton.Joints[JointType.HandLeft];
            Joint rightHand = skeleton.Joints[JointType.HandRight];

            if (leftHand.TrackingState != JointTrackingState.NotTracked && rightHand.TrackingState != JointTrackingState.NotTracked)
            {
                if (tracker.State == GestureState.InProcess && tracker.TimeStamp + _TIMEOUT <= timeStamp)
                    //响应超时
                    tracker.UpdateState(GestureState.Failure, timeStamp);
                else
                {
                    if (tracker.State == GestureState.InProcess)
                    {
                        if (Math.Abs(leftHand.Position.X - rightHand.Position.X) >= UPPER_THRESHOLD || Math.Abs(leftHand.Position.Y - rightHand.Position.Y) >= UPPER_THRESHOLD)
                        {
                            tracker.UpdateState(GestureState.Success, timeStamp);
                            if (GestureDetected != null)
                                GestureDetected(this, new EventArgs());
                        }
                    }
                    else
                    {
                        if (Math.Abs(leftHand.Position.Y - rightHand.Position.Y) < LOWER_THRESHOLD && Math.Abs(leftHand.Position.X - rightHand.Position.X) <= LOWER_THRESHOLD)
                            tracker.UpdatePosition(timeStamp);
                        else
                            tracker.Reset();
                    }
                }
            }
            else
                tracker.Reset();
        }
Exemplo n.º 2
0
        private void TrackGesture(Skeleton skeleton, ref GestureTracker tracker, long timeStamp)
        {
            Joint hand = skeleton.Joints[JointType.HandLeft];
            Joint head = skeleton.Joints[JointType.Head];

            if (hand.TrackingState != JointTrackingState.NotTracked && head.TrackingState != JointTrackingState.NotTracked)
            {
                if (tracker.State == GestureState.Success)
                {
                    if (head.Position.Y - hand.Position.Y < 0.5f)
                        tracker.Reset();
                }
                else
                {
                    if (tracker.State == GestureState.InProcess && tracker.TimeStamp + _TIMEOUT <= timeStamp)
                        //响应超时
                        tracker.UpdateState(GestureState.Failure, timeStamp);
                    else
                    {
                        if (tracker.State == GestureState.InProcess)
                        {
                            if (tracker.StartX - hand.Position.X > SIDE_THRESHOLD && tracker.StartY - hand.Position.Y > SIDE_THRESHOLD)
                            {
                                tracker.UpdateState(GestureState.Success, timeStamp);
                                if (GestureDetected != null)
                                    GestureDetected(this, new EventArgs());
                            }
                        }
                        else
                        {
                            if (hand.Position.Y - head.Position.Y >= ABOVE_THRESHOLD)
                                tracker.UpdatePosition(hand.Position.X, hand.Position.Y, timeStamp);
                            else
                                tracker.Reset();
                        }
                    }
                }
            }
            else
                tracker.Reset();
        }
Exemplo n.º 3
0
        private void TrackGesture(Skeleton skeleton,bool isLeft, ref GestureTracker tracker, long timeStamp)
        {
            JointType handJointId = (isLeft) ? JointType.HandLeft : JointType.HandRight;
            JointType elbowJointId = (isLeft) ? JointType.ElbowLeft : JointType.ElbowRight;

            Joint hand = skeleton.Joints[handJointId];
            Joint elbow = skeleton.Joints[elbowJointId];

            if (hand.TrackingState != JointTrackingState.NotTracked && elbow.TrackingState != JointTrackingState.NotTracked)
            {
                if (tracker.State == GestureState.InProcess && tracker.TimeStamp + _TIMEOUT <= timeStamp)
                    //响应超时
                    tracker.UpdateState(GestureState.Failure, timeStamp);
                else
                {
                    if (tracker.State == GestureState.InProcess)
                    {
                        if (hand.Position.X - tracker.StartX >= UPPER_THRESHOLD && Math.Abs(hand.Position.Y - tracker.StartY) <= LOWER_THRESHOLD)
                        {
                            tracker.UpdateState(GestureState.Success, timeStamp);
                            if (GestureDetected != null)
                                GestureDetected(this, new EventArgs());
                        }
                    }
                    else
                    {
                        if (Math.Abs(hand.Position.Y - elbow.Position.Y) <= LOWER_THRESHOLD && Math.Abs(hand.Position.Z - elbow.Position.Z) >= ZINDEX_THRESHOLD)
                            tracker.UpdatePosition(hand.Position.X,hand.Position.Y, timeStamp);
                        else
                            tracker.Reset();
                    }
                }
            }
            else
                tracker.Reset();
        }
Exemplo n.º 4
0
        private void TrackGesture(Skeleton skeleton, bool isLeft, ref GestureTracker tracker, long timeStamp)
        {
            JointType handJointId = (isLeft) ? JointType.HandLeft : JointType.HandRight;
            JointType elbowJointId = (isLeft) ? JointType.ElbowLeft : JointType.ElbowRight;

            Joint hand = skeleton.Joints[handJointId];
            Joint elbow = skeleton.Joints[elbowJointId];

            if (hand.TrackingState != JointTrackingState.NotTracked && elbow.TrackingState != JointTrackingState.NotTracked)
            {
                if (tracker.State == GestureState.InProcess && tracker.TimeStamp + WAVE_MOVEMENT_TIMEOUT < timeStamp)
                {
                    //超时失效
                    tracker.UpdateState(GestureState.Failure, timeStamp);

                }
                else if (hand.Position.Y > elbow.Position.Y+0.15f)
                {
                    if (hand.Position.X <= elbow.Position.X - WAVE_THRESHOLD)
                        tracker.UpdatePosition(WavePosition.Left, timeStamp);
                    else if (hand.Position.X >= elbow.Position.X + WAVE_THRESHOLD)
                        tracker.UpdatePosition(WavePosition.Right, timeStamp);
                    else
                        tracker.UpdatePosition(WavePosition.Neutral, timeStamp);

                    if (tracker.State != GestureState.Success && tracker.IterationCount == REQUIRED_ITERATIONS)
                    {
                        //手势识别成功
                        tracker.UpdateState(GestureState.Success, timeStamp);

                        if (GestureDetected != null)
                            GestureDetected(this, new EventArgs());
                    }
                }
                else
                {
                    if (tracker.State == GestureState.InProcess)
                        tracker.UpdateState(GestureState.Failure, timeStamp);
                    else
                        tracker.Reset();
                }
            }
            else
                tracker.Reset();
        }