Tech Off Thread

4 posts

Kinect Wave Gesture Recognition

Back to Forum: Tech Off
  • Yovi

    I'm using the code from a textbook "Beginning Kinect Programming with the Microsoft Kinect SDK" from chapter 6 wave gesture part. However, I've got 2 errors: 

    1. Inconsistent accessibility: parameter type 'WaveGesture.MainWindow.WaveGestureState' is less accessible than method 'WaveGesture.MainWindow.UpdateState (WaveGesture.MainWindow.WaveGestureState, long)'

    2. Inconsistent accessibility: parameter type 'WaveGesture.MainWindow.WavePosition' is less accessible than method 'WaveGesture.MainWindow.UpdatePosition (WaveGesture.MainWindow.WavePosition, long)'

    If I change those enumerations to public, I get so many errors. Can anyone please tell me whats wrong?

    The code:

    private enum WavePosition
            {
                None = 0,
                Left = 1,
                Right = 2,
                Neutral = 3
            }
    
            private enum WaveGestureState
            {
                None = 0,
                Success = 1,
                Failure = 2,
                InProgress = 3
            }
    
            private struct WaveGestureTracker
            {
                public void Reset()
                {
                    IterationCount = 0;
                    State = GestureState.None;
                    Timestamp = 0;
                    StartPosition = WavePosition.None;
                    CurrentPosition = WavePosition.None;
                }
    
                public int IterationCount;
                public WaveGestureState State;
                public long Timestamp;
            }
    
            public class WaveGesture
            {
                private const float WAVE_THRESHOLD = 0.1f;
                private const int WAVE_MOVEMENT_TIMEOUT = 5000;
                private const int REQUIRED_ITERATIONS = 4;
                private WaveGestureTracker[,] _PlayerWaveTracker = new WaveGestureTracker[6, 2];
                public event EventHandler GestureDetected;
    
                public void Update(Skeleton[] skeletons, long frameTimestamp)
                {
                    if (skeletons != null)
                    {
                        Skeleton skeleton;
                        for (int i = 0; i < skeletons.Length; i++)
                        {
                            skeleton = skeletons[i];
                            if (skeleton.TrackingState != SkeletonTrackingState.NotTracked)
                            {
                                TrackWave(skeleton, true,
                                ref this._PlayerWaveTracker[i, LEFT_HAND], frameTimestamp);
                                TrackWave(skeleton, false,
                                ref this._PlayerWaveTracker[i, RIGHT_HAND], frameTimestamp);
                            }
                            else
                            {
                                this._PlayerWaveTracker[i, LEFT_HAND].Reset();
                                this._PlayerWaveTracker[i, RIGHT_HAND].Reset();
                            }
                        }
                    }
                }
    
            }
    
            private void TrackWave(Skeleton skeleton, bool isLeft, ref WaveGestureTracker 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 == WaveGestureState.InProgress && tracker.Timestamp + WAVE_MOVEMENT_TIMEOUT < timestamp)
                    {
                        tracker.UpdateState(WaveGestureState.Failure, timestamp);
                    }
                    else if (hand.Position.Y > elbow.Position.Y)
                    {
                        //Using the raw values where (0, 0) is the middle of the screen.
                        //From the user's perspective, the X-Axis grows more negative left
                        //and more positive right.
                        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 != WaveGestureState.Success && tracker.IterationCount == REQUIRED_ITERATIONS)
                        {
                            tracker.UpdateState(WaveGestureState.Success, timestamp);
    
                            if (GestureDetected != null)
                            {
                                GestureDetected(this, new EventArgs());
                            }
                        }
                    }
                    else
                    {
                        if (tracker.State == WaveGestureState.InProgress)
                        {
                            tracker.UpdateState(WaveGestureState.Failure, timestamp);
                        }
                        else
                        {
                            tracker.Reset();
                        }
                    }
                }
                else
                {
                    tracker.Reset();
                }
            }
    
            public void UpdateState(WaveGestureState state, long timestamp)
            {
                state = State;
                timestamp = Timestamp;
            }
    
            public void Reset()
            {
                IterationCount = 0;
                State = WaveGestureState.None;
                Timestamp = 0;
                StartPosition = WavePosition.None;
                CurrentPosition = WavePosition.None;
            }
    
            public void UpdatePosition(WavePosition position, long timestamp)
            {
    
                if (CurrentPosition != position)
                {
                    if (position == WavePosition.Left || position == WavePosition.Right)
                    {
                        if (State != WaveGestureState.InProgress)
                        {
                            State = WaveGestureState.InProgress;
                            IterationCount = 0;
                            StartPosition = position;
                        }
    
                        IterationCount++;
                    }
    
                    position = CurrentPosition;
                    timestamp = Timestamp;
                }
            }

  • gduncan411

    Have you contacted the authors of the book directly? I believe James Avery's contact information is in the "About the Authors" section?

  • Yovi

    @gduncan411: I just emailed him. Hopefully he'll reply. Thank you.

  • jamesashley

    @Yovi:  The code should go into a WaveGesture class instead of just straight into your MainWindow class.  I think you'll find that the compile issues go away if you do this.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.