Leap Motion for Processing - detect left hand

edited November 2016 in Kinect

Hi, I'm trying to detect just the left hand using the Leap Motion for Processing library, but keep getting a null pointer exception and I'm not sure why. Any ideas?

My code is below:

import de.voidplus.leapmotion.*;

LeapMotion leap;
Hand hand;

void setup() {
    size(1000, 600);
    background(255);
    leap = new LeapMotion(this);
}


void draw() {
    hand = leap.getLeftHand(); 

    hand.draw();         
}

I have also tried testing for null, e.g. :

import de.voidplus.leapmotion.*;

LeapMotion leap;
Hand hand;

void setup() {
    size(1000, 600);
    background(255);
    leap = new LeapMotion(this);
}


void draw() {
    hand = leap.getLeftHand(); 
    if (hand != null) {
      hand.draw();       
   }  
}

but that only seems to draw a hand when the hand is not over the leap device.

The example code from the library includes an array list for getting both hands, but I really just want to detect one. Have also tried the following with no joy - there is no output at all in this one:

import de.voidplus.leapmotion.*;

LeapMotion leap;
Hand leftHand;

void setup() {
    size(1000, 600);
    background(255);
    leap = new LeapMotion(this);
}


void draw() {
    for (Hand hand: leap.getHands()) {
        leftHand = leap.getLeftHand(); 
        if (leftHand != null) {
            leftHand.draw();       
        }
    }
}

I'd really appreciate any help you can give here. Thanks!

Answers

Sign In or Register to comment.