Search code examples
javaswipeleap-motion

motion leap - swipe detection not working


 @Override
    public void onFrame(Controller arg0) {
        Frame frame = arg0.frame();
        for (int i = 0; i < frame.gestures().count(); i++) {
            Gesture gesture = frame.gesture(i);
            if (gesture.type() != Type.TYPE_INVALID)
                System.out.println(gesture.type().toString());
        }
    }

I get no message in console. If i remove that if, i will get a lot of invalid swipes. I've tried doing a lot of types of swipes but nothing seems to work. Example of swipe that i tried: https://www.youtube.com/watch?v=dj1q8Bjn-ukenter image description here


Solution

  • The function frame.gesture(id) searches the frame's gesture list for a gesture object with the specified id, i.e. so that you can track a particular gesture across frames. The function returns an invalid frame if it doesn't find one. Change your code to use frame.gestures(), which gives you the gesture list:

    @Override
    public void onFrame(Controller arg0) {
        Frame frame = arg0.frame();
        for (int i = 0; i < frame.gestures().count(); i++) {
            Gesture gesture = frame.gestures().get(i);
            if (gesture.type() != Type.TYPE_INVALID)
                System.out.println(gesture.type().toString());
        }
    }
    

    You shouldn't ever get invalid gestures in the list supplied by the gestures() function, so you don't really need that check in this case.