-3

I'm working on Gesture detection of my right hand with the Kinect v2 and got my hands on a good sample that I could use, but got stuck with the converting of the code when the error: "The best overloaded method match for ... has some invalid arguments" shows up at several but similar code lines. I've checked earlier problems with this error but couldn't find a solution for this specific one. Some help would be very appreciated!

// Gesture detection

    public enum HandPosition { Unknown, Up, Center, Down, Left, Right, Backwards, Forwards }

    public class HandPositionChangedArgs
    {
        public HandPosition Position { get; set; }
    }

    public delegate void HandPositionChangedDelegate(object sender, HandPositionChangedArgs args);

    public static class GestureDetection
    {
        public static void FrameReady(Microsoft.Kinect.Body skeleton)
        {
            ProcessRightHand(skeleton);
        }

        // Right Hand
        private static Dictionary<int, HandPosition> rightHandUpDownDictionary = new Dictionary<int, HandPosition>();
        private static Dictionary<int, HandPosition> rightHandLeftRightDictionary = new Dictionary<int, HandPosition>();
        private static Dictionary<int, HandPosition> rightHandBackForwardsDictionary = new Dictionary<int, HandPosition>();

        public static event HandPositionChangedDelegate RightHandUpDownChanged;
        public static event HandPositionChangedDelegate RightHandLeftRightChanged;
        public static event HandPositionChangedDelegate RightHandBackForwardsChanged;

        public static void ProcessRightHand(Microsoft.Kinect.Body skeleton)
        {
            Joint rightHand = skeleton.Joints[Microsoft.Kinect.JointType.HandRight];
            Joint rightShoulder = skeleton.Joints[Microsoft.Kinect.JointType.ShoulderRight];

            CameraSpacePoint rightHandPoint = rightHand.Position;
            CameraSpacePoint rightShoulderPoint = rightShoulder.Position;

            HandPosition previousRightHandUpDownPosition = (rightHandUpDownDictionary.ContainsKey(skeleton.TrackingId)) ? rightHandUpDownDictionary[skeleton.TrackingId] : HandPosition.Unknown; // Here's the error
            HandPosition newRightHandUpDownPosition = HandPosition.Unknown;

            HandPosition previousRightHandLeftRightPosition = (rightHandLeftRightDictionary.ContainsKey(skeleton.TrackingId)) ? rightHandLeftRightDictionary[skeleton.TrackingId] : HandPosition.Unknown; // Here's the error
            HandPosition newRightHandLeftRightPosition = HandPosition.Unknown;

            HandPosition previousRightHandBackForwardsPosition = (rightHandBackForwardsDictionary.ContainsKey(skeleton.TrackingId)) ? rightHandBackForwardsDictionary[skeleton.TrackingId] : HandPosition.Unknown;// Here's the error
            HandPosition newRightHandBackForwardsPosition = HandPosition.Unknown;

            if ((rightHand.TrackingState == TrackingState.NotTracked) || (rightShoulder.TrackingState == TrackingState.NotTracked)) // From JointTrackingState to TrackingState?
            {
                newRightHandUpDownPosition = HandPosition.Unknown;
                newRightHandLeftRightPosition = HandPosition.Unknown;
                newRightHandBackForwardsPosition = HandPosition.Unknown;
            }
            else
            {
                // Up/Down
                if (rightHandPoint.Y - rightShoulderPoint.Y > 0.2)
                {
                    newRightHandUpDownPosition = HandPosition.Up;
                }
                else if (Math.Abs(rightHandPoint.Y - rightShoulderPoint.Y) > 0.2)
                {
                    newRightHandUpDownPosition = HandPosition.Down;
                }
                else
                {
                    newRightHandUpDownPosition = HandPosition.Center;
                }

                // Left/Right
                if (rightHandPoint.X - rightShoulderPoint.X > 0.2)
                {
                    newRightHandLeftRightPosition = HandPosition.Right;
                }
                else if (Math.Abs(rightHandPoint.X - rightShoulderPoint.X) > 0.2)
                {
                    newRightHandLeftRightPosition = HandPosition.Left;
                }
                else
                {
                    newRightHandLeftRightPosition = HandPosition.Center;
                }

                // Backwards/Forwards
                if (rightShoulderPoint.Z - rightHandPoint.Z > 0.5)
                {
                    newRightHandBackForwardsPosition = HandPosition.Forwards;
                }
                else if (rightShoulderPoint.Z - rightHandPoint.Z < 0.25)
                {
                    newRightHandBackForwardsPosition = HandPosition.Backwards;
                }
                else
                {
                    newRightHandBackForwardsPosition = HandPosition.Center;
                }
            }

            if (previousRightHandUpDownPosition != newRightHandUpDownPosition)
            {
                rightHandUpDownDictionary[skeleton.TrackingId] = newRightHandUpDownPosition; // Here's the error
                if (RightHandUpDownChanged != null)
                {
                    RightHandUpDownChanged(skeleton, new HandPositionChangedArgs() { Position = newRightHandUpDownPosition });
                }
            }

            if (previousRightHandLeftRightPosition != newRightHandLeftRightPosition)
            {
                rightHandLeftRightDictionary[skeleton.TrackingId] = newRightHandLeftRightPosition; // Here's the error
                if (RightHandLeftRightChanged != null)
                {
                    RightHandLeftRightChanged(skeleton, new HandPositionChangedArgs() { Position = newRightHandLeftRightPosition });
                }
            }

            if (previousRightHandBackForwardsPosition != newRightHandBackForwardsPosition)
            {
                rightHandBackForwardsDictionary[skeleton.TrackingId] = newRightHandBackForwardsPosition; // Here's the error
                if (RightHandBackForwardsChanged != null)
                {
                    RightHandBackForwardsChanged(skeleton, new HandPositionChangedArgs() { Position = newRightHandBackForwardsPosition });
                }
            }
        }
    }
Nocu
  • 3
  • 1
  • "The best overloaded method match for ... has some invalid arguments" The part where you have "..." is the most important part of the message, please state it. – Bernd Linde Apr 14 '15 at 15:19
  • 1
    What it most probably is, is you are calling `Dictionary.ContainsKey(skeleton.TrackingId)`, but your dictionaries are defined as ``. skeleton.TrackingId is a ulong. – Bernd Linde Apr 14 '15 at 15:21

1 Answers1

0

You defined your various dictionaries as Dictionary<int, HandPosition>, but inside your code you are using the skeleton.TrackingId to reference the keys of your dictionaries.
According to MSDN, Body.TrackingId is a ulong.

You will either need to redefined your dictionaries to Dictionary<ulong, HandPosition> or convert skeleton.TrackingId to an Int variable to use it.

Bernd Linde
  • 2,098
  • 2
  • 16
  • 22