LeapmotionP5 gesture recognition example

edited December 2013 in Library Questions

Hi,

I'm trying to get the gesture recognition example that accompanies Onformative's library for the leapmotion controller to compile. For some reason it can't find the com.leapmotion.leap.Gesture library.

I would appreciate any advice on this. Do I need to locate and install the Gesture library myself?

I'm running Processing v2.1 on Windows 8.

Thanks, d.

Answers

  • Hi,

    I get a similar error, but the sketch works fine. Can you try to run an example sketch to see if it works, even when displaying the error? Sorry, can't test atm as I don't have a Leap at hand.

  • Hi,

    I can compile the sketch if change the import libraries, but then when it recognises a gesture it generates an error:

    dmn_leap_P5_gestureRecognition_121213_01_pde.keyTapGestureRecognized(com.leapmotion.leap.KeyTapGesture) CALLBACK ERROR

    best, d.

  • I'm not sure where your problem is, but here is some stripped down sample code that should work. Probably exactly the same as the provided example...

    import com.leapmotion.leap.CircleGesture;
    import com.leapmotion.leap.Gesture.State;
    import com.leapmotion.leap.Gesture.Type;
    import com.leapmotion.leap.Hand;
    import com.leapmotion.leap.KeyTapGesture;
    import com.leapmotion.leap.ScreenTapGesture;
    import com.leapmotion.leap.SwipeGesture;
    import com.onformative.leap.LeapMotionP5;
    import com.leapmotion.leap.Controller.PolicyFlag;
    
    LeapMotionP5 leap;
    String lastGesture = "";
    float start = 0.0;
    float stop = 1.0;
    float clckwsnss = 0;
    
    public void setup() {
      size(500, 500);
      textSize(17);
      leap = new LeapMotionP5(this);
      leap.enableGesture(Type.TYPE_CIRCLE);
      leap.getController().setPolicyFlags(PolicyFlag.POLICY_BACKGROUND_FRAMES); //This enables the Leap to send commands to Processing even while the window is not active
    
    }
    
    public void draw() {
      background(0);
      for (Hand hand : leap.getHandList()) {
        PVector handPos = leap.getPosition(hand);
        ellipse(handPos.x, handPos.y, 20, 20);
      }
      text(lastGesture, 30, 30);
    }
    
    
    
    public void circleGestureRecognized(CircleGesture gesture, String clockwiseness) {
      if (gesture.state() == State.STATE_STOP) {
        start = 0;
        stop = 1;
        System.out.println("//////////////////////////////////////");
        System.out.println("Gesture type: " + gesture.type().toString());
        System.out.println("ID: " + gesture.id());
        System.out.println("Radius: " + gesture.radius());
        System.out.println("Normal: " + gesture.normal());
        System.out.println("Clockwiseness: " + clockwiseness);
        System.out.println("Turns: " + gesture.progress());
        System.out.println("Center: " + leap.vectorToPVector(gesture.center()));
        System.out.println("Duration: " + gesture.durationSeconds() + "s");
        System.out.println("//////////////////////////////////////");
        lastGesture = "Gesture type: " + gesture.type().toString() + "\n";
        lastGesture += "ID: " + gesture.id() + "\n";
        lastGesture += "Radius: " + gesture.radius() + "\n";
        lastGesture += "Normal: " + gesture.normal() + "\n";
        lastGesture += "Clockwiseness: " + clockwiseness + "\n";
        lastGesture += "Turns: " + gesture.progress() + "\n";
        lastGesture += "Center: " + leap.vectorToPVector(gesture.center()) + "\n";
        lastGesture += "Duration: " + gesture.durationSeconds() + "s" + "\n";
    
      } 
      else if (gesture.state() == State.STATE_START) {
        lastGesture = "circling";
        start = 1;
        stop = 0;
        if( clockwiseness == "clockwise")
        {
          clckwsnss = 1;
        }
        else
        {
          clckwsnss = -1;
        }
    
      } 
      else if (gesture.state() == State.STATE_UPDATE) {
      }
    }
    
    public void stop() {
      leap.stop();
    }
    
Sign In or Register to comment.