Leap Motion Swipe Gesture Detects More Than One Swipe


When I use the Leap Motion SwipeGesture function, a single motion of the hand could create more than 5 swipe gestures. I believe that it's because Leap Motion detects fingers instead of hand. I tried to reduce the motion detection by making the function only detects index finger. However, occasionally, the function still detects 2-3 swipe gestures. Is there anyway to make the function only detects 1 swipe gesture in a single swipe?



  • Fewer people has this experience as this technology is not as common here in the forum. Consider exploring previous posts: https://forum.processing.org/two/search?Search=leapmotion

    Can you display your leapMotion together with video streaming? Would this multiple finger detection be caused by the system getting confused and detecting the other fingers as the index finger?


  • I'm wanna do something like this:

    Leap::Frame sinceFrame;
    int currentGestureID = -1;
    Leap::Gesture currentGesture = frame.gesture(currentGestureID);
        //Update swipe action
    } else {
        // Pick a new swipe
        Leap::GestureList gestures = frame.gestures(sinceFrame);
        for(auto gesture : gestures){
            if(gesture.type() == Leap::Gesture::TYPE_SWIPE
               && gesture.durationSeconds() < .1){
                currentGestureID = gesture.id();
    sinceFrame = frame;

    I got this code from this Leap Motion forum: https://forums.leapmotion.com/t/increase-range-and-decrease-sensitivity-for-swipe-gesture/3064/4

    But I am unable to convert this code to use it in Processing due to my poor programming skill.

  • edited April 2018

    Can you post the Processing code that you have at the moment?

    I have more experience with Processing than with the Leap Motion--I confess I've had the Leap Motion for over a year now, but it was only today that I discovered that Processing has the "Leap Motion for Processing" library. :-bd

    EDIT: Ok, after getting a bit more up to speed on the "Leap Motion for Processing" library I think I can offer a solution. The confusing part is that your source code snippet is in C++ and for a completely different Leap Motion library. :-(

    The code below is borrowed from the example sketch "LM_2_Gestures", based on the code snippet you posted it looks like it testing to determine the duration of the swipe.

    As for getting only one reading, I have to use millis() to record the time between when the swipe gestures stop. Though, I occasionally still see duplicates, try reducing the allow number of milliseconds (see if ( (currentTime - previousTime) < 100)) until it works the way you want it to. :-??

    // LM_2_Gestures Modified
    // Only report swipe gestures. Distinguish between slow and quick swipes (less than 0.1 seconds)
    import de.voidplus.leapmotion.*;
    // ======================================================
    // Table of Contents:
    // ├─ 1. Swipe Gesture
    // ├─ 2. Circle Gesture (REMOVED FOR BREVITY)
    // ├─ 3. Screen Tap Gesture (REMOVED FOR BREVITY)
    // └─ 4. Key Tap Gesture (REMOVED FOR BREVITY)
    // ======================================================
    LeapMotion leap;
    int previousTime;
    void setup() {
      size(800, 500);
      // ...
      previousTime = millis();
      leap = new LeapMotion(this).allowGestures("swipe");  // Leap detects only swipe gestures
    void draw() {
      // ...
    // ======================================================
    // 1. Swipe Gesture
    void leapOnSwipeGesture(SwipeGesture g, int state) {
      int     id               = g.getId();
      Finger  finger           = g.getFinger();
      PVector position         = g.getPosition();
      PVector positionStart    = g.getStartPosition();
      PVector direction        = g.getDirection();
      float   speed            = g.getSpeed();
      long    duration         = g.getDuration();
      float   durationSeconds  = g.getDurationInSeconds();
      int currentTime = millis();
      boolean flagDuplicateSwipe = false;
      switch(state) {
      case 1: // Start
      case 2: // Update
      case 3: // Stop
        if ( (currentTime - previousTime) < 100) {
          flagDuplicateSwipe = true;
        if (durationSeconds < 0.1) {
          println( (flagDuplicateSwipe ? "IGNORE " : "") + "Quick Swipe Gesture: " + id + " [duration = " + durationSeconds + "]");
        } else {
          println( (flagDuplicateSwipe ? "IGNORE " : "") + "Slow Swipe Gesture: " + id + " [duration = " + durationSeconds + "]");
        previousTime = currentTime; // Refresh time stamp
Sign In or Register to comment.