2016-06-10 28 views
-1

滑動手勢向左,向右,向上和向下未優化。如果任務必須以向上滑動的方式執行,它會與左側滑動混淆並仍然執行它。請向我建議要優化的參數以區分滑動。或完美滑動識別的命令 此外,它會與圈和一個輕掃。 我已添加我的代碼。在一個單一的框架中,只有一個手勢應該被檢測到。我怎麼在這裏限制這個。Leap Motion會在不同的手勢類型之間產生混淆。如何優化?

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 
     } 
    } 
} 
+0

您使用的是什麼版本的Leap Motion軟件? –

+0

軟件版本2.3.1 +31549 –

回答

0

開箱即用的手勢在3.x(Orion)中不推薦使用,因爲它們不可靠。 要做的最好的事情就是了解SDK,並創建自己的手勢,你可以超越已經開箱即用的,更可靠的。 關於3D定位的一切,所以要注意你的Y,X,Z,使用debuger的手或創建你自己的調試系統,看看它的行爲。