Unity3D中的Leap Motion手势识别始终返回TYPEINVALID和STATEINVALID

时间:2013-08-17 18:40:43

标签: c# unity3d leap-motion

尝试使用Controller.EnableGesture启用任何/所有手势,尝试从当前帧获取>手势(0)或来自新的CircleGesture(或任何其他类型)。 总是得到无效的手势...... 这是代码,我在Unity示例中使用LeapInput静态类(它只是保存控制器并更新当前帧)。

 void Update()
    {
        LeapInput.Update();
        Frame thisFrame = LeapInput.Frame;
        for (int i = 0; i < thisFrame.Gestures().Count; i++)
            {
                Gesture gesture = thisFrame.Gesture(i);
            }
    }

P.S。是的,我在同一控制器实例中启用手势。

2 个答案:

答案 0 :(得分:1)

你有最新的驱动程序吗? (截止到这篇文章的1.0.7 + 7648)这是我的处理程序类中的代码,它返回圆圈手势就好了:

更新代码(工作)

我没注意OP的原始代码。 .gestures(0)无效,只需更改为.gestures[0],请参阅下面的示例。

using UnityEngine;
using System.Collections;
using Leap;

public class LeapTest : Leap.Listener {
    public Leap.Controller Controller;

    // Use this for initialization
    public void Start () {
        Controller = new Leap.Controller(this);
        Debug.Log("Leap start");
    }

    public override void OnConnect(Controller controller){
        Debug.Log("Leap Connected");
        controller.EnableGesture(Gesture.GestureType.TYPECIRCLE,true);
    }

    public override void OnFrame(Controller controller)
    {
        Frame frame = controller.Frame();
        GestureList gestures = frame.Gestures();
        for (int i = 0; i < gestures.Count; i++)
        {
            Gesture gesture = gestures[0];
            switch(gesture.Type){
                case Gesture.GestureType.TYPECIRCLE:
                    Debug.Log("Circle");
                    break;
                default:
                    Debug.Log("Bad gesture type");
                    break;
            }
        }
    }
}

答案 1 :(得分:0)

我也要添加一个答案,因为我遇到了这个问题。看起来你解决了你的特殊问题,但我的有点不同。我在Gestures数组中根本没有收到任何数据。

我发现除了启用手势之外,我还必须回顾帧历史记录,看看事后是否有任何手势附加到旧帧。换句话说,controller.Frame()不一定具有与其相关联的任何手势数据但跳过帧,或者先前轮询的帧确实具有手势数据。所以这样的事情已经解决了(虽然记住你必须做一些long-int类型的转换):

Frame lastFrame;
Frame thisFrame;

void Update()
{
    LeapInput.Update();
    lastFrame = thisFrame;
    thisFrame = LeapInput.Frame;

    long difference = thisFrame.Id - lastFrame.Id;

    while(difference > 0){
      Frame f = controller.Frame(difference);
      GestureList gestures = f.Gestures();
      if(gestures.Count > 0){
        foreach(Gesture gesture in gestures){
          Debug.Log(gesture.Type + " found in frame " + f.Id);
        }
      }
      difference--;
    }



}

在所有跳过的帧或历史帧中找到这些手势后,可以根据需要使用它们。