Leap Motion在不同的手势类型之间混淆。如何优化?

时间:2016-06-10 14:27:28

标签: c# visual-studio-2015 gestures leap-motion

滑动手势Left,Right,Up和Down未优化。如果必须使用向上滑动执行任务,它将与左滑动混淆并仍然执行它。请建议我优化的参数以区分滑动。或完美滑动识别的命令 它也与圆圈和滑动相混淆。  我添加了我的代码。在一个帧中,只能检测到一个手势。我如何限制它。

public MainWindow()
{
InitializeComponent();

        this.controller = new Controller();

        this.listener = new LeapListener(this);
        controller.AddListener(listener);

        for (int iCount = 1; iCount < 23; iCount++)
        {
            images[iCount] = new BitmapImage();
            images[iCount].BeginInit();
            images[iCount].UriSource = new Uri("Images/" + iCount + ".png", UriKind.Relative);
            images[iCount].EndInit();
        }
        image.Source = images[1];
    }



    delegate void LeapEventDelegate(string EventName);




    public void LeapEventNotification(string EventName)
    {
        if (this.CheckAccess())
        {
            switch (EventName)
            {
                case "onInit":

                    break;
                case "onConnect":

                    this.connectHandler();
                    break;
                case "onFrame":

                    this.checkGestures(this.controller.Frame());

                    break;
            }
        }
        else
        {
            Dispatcher.Invoke(new LeapEventDelegate(LeapEventNotification
                ), new object[] { EventName });
        }
    }

    public void connectHandler()
    {
        controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE);
        this.controller.EnableGesture(Gesture.GestureType.TYPE_CIRCLE);
        this.controller.EnableGesture(Gesture.GestureType.TYPE_KEY_TAP);
        this.controller.EnableGesture(Gesture.GestureType.TYPE_SCREEN_TAP);


        // controller.Config.SetFloat("Gesture.Swipe.Speed", 4000.0f);
        controller.Config.SetFloat("Gesture.Swipe.MinVelocity", 750f);
        controller.Config.SetFloat("Gesture.Swipe.MinLength", 200f);

        controller.Config.SetFloat("Gesture.KeyTap.MinDownVelocity", 40.0f);
        controller.Config.SetFloat("Gesture.KeyTap.HistorySeconds", .2f);
        controller.Config.SetFloat("Gesture.KeyTap.MinDistance", 40.0f);

        controller.Config.SetFloat("Gesture.Circle.MinRadius", 15.0f);
        controller.Config.SetFloat("Gesture.Circle.MinArc", 15f);

        controller.Config.SetFloat("InteractionBox.Width", 1600.0f);
        controller.Config.SetFloat("InteractionBox.Height", 1600.0f);

        controller.Config.Save();
    }


    public void checkGestures(Frame frame)
    {


        GestureList gestures = frame.Gestures();
        foreach (Gesture gesture in gestures)
        {

            // For Image 1
            if (image.Source.Equals(images[1]))
            {



                if (gesture.Type == Gesture.GestureType.TYPE_SWIPE)
                {

                    SwipeGesture swipe = new SwipeGesture(gesture);
                    if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.x > 0 && Math.Abs(swipe.Direction.y) < 5)
                    {

                        image.Source = images[2];
                        //   Console.WriteLine("Second");
                    }

                }

            }

            // For Image 2
            else if (image.Source.Equals(images[2]))
            {

                if (gesture.Type == Gesture.GestureType.TYPE_SWIPE)
                {
                    SwipeGesture swipe = new SwipeGesture(gesture);

                    if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.y > 0)

                    {
                        image.Source = images[3];
                    }
                   else  if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.x > 0 && Math.Abs(swipe.Direction.y) < 5)
                    {
                        image.Source = images[7];
                    }
                }
                 if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
                {
                    KeyTapGesture TapGesture = new KeyTapGesture(gesture);
                    image.Source = images[1];
                    Console.WriteLine("Circle");
                }
            }
            // For Image 3
            else if (image.Source.Equals(images[3]))
            {

                if (gesture.Type == Gesture.GestureType.TYPE_SWIPE)
                {
                    SwipeGesture swipe = new SwipeGesture(gesture);

                    if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.y < 0)

                    {
                        image.Source = images[4];
                    }
                 else   if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.x < 0 && Math.Abs(swipe.Direction.y) < 5)
                    {
                        image.Source = images[16];
                    }

                }
                if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
                {
                    KeyTapGesture TapGesture = new KeyTapGesture(gesture);
                    image.Source = images[1];

                }
            }

            }//foreach
        }
    }
}

1 个答案:

答案 0 :(得分:0)

开箱即用的手势在3.x(猎户座)中被弃用,因为它们不可靠。 最好的办法是了解SDK并只创建自己的手势,你可以超越已经开箱即用,更可靠。 一切都与3d定位有关,所以要注意你的Y,X,Z,使用debuger指针或创建自己的调试系统来看它的行为。