Coder Social home page Coder Social logo

leapmotionp5's Introduction

LeapMotionP5

A Leap Motion Library for Processing

Working with all Processing versions and all operating systems (OSX, Windows), with the newest version of the leap motion sdk. Moreover it is including a variety of gestures. Just download the library archive at the bottom of this readme and extract it into the libraries folder of your processing sketchbook and your're ready to go.

Check http://www.onformative.com/lab/leapmotionp5 for additional information about the library.

Download

Download from here https://github.com/mrzl/LeapMotionP5/archive/master.zip extract the folder in the archive into your processing libraries folder and rename it from LeapMotionP5-master to LeapMotionP5. After that restart Processing and the library should be included. Check the examples within the library.

Examples

Basic Example

import com.onformative.leap.LeapMotionP5;
import com.leapmotion.leap.Finger;

LeapMotionP5 leap;

public void setup() {
  size(500, 500);
  leap = new LeapMotionP5(this);
}

public void draw() {
  background(0);
  fill(255);
  for (Finger finger : leap.getFingerList()) {
    PVector fingerPos = leap.getTip(finger);
    ellipse(fingerPos.x, fingerPos.y, 10, 10);
  }
}

public void stop() {
  leap.stop();
}

Gesture Recognition

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;

LeapMotionP5 leap;
String lastGesture =
"enabling gestures: \n'c' for CircleGesture\n's' for SwipeGesture\n'k' for KeyTapGesture\n't' for ScreenTapGesture";

public void setup() {
  size(500, 500);
  textSize(17);

  leap = new LeapMotionP5(this);
}

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) {
    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.convertVectorToPVector(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.convertVectorToPVector(gesture.center()) + "\n";
    lastGesture += "Duration: " + gesture.durationSeconds() + "s" + "\n";
  } 
  else if (gesture.state() == State.STATE_START) {
  } 
  else if (gesture.state() == State.STATE_UPDATE) {
  }
}

public void swipeGestureRecognized(SwipeGesture gesture) {
  if (gesture.state() == State.STATE_STOP) {
    System.out.println("//////////////////////////////////////");
    System.out.println("Gesture type: " + gesture.type());
    System.out.println("ID: " + gesture.id());
    System.out.println("Position: " + leap.convertVectorToPVector(gesture.position()));
    System.out.println("Direction: " + gesture.direction());
    System.out.println("Duration: " + gesture.durationSeconds() + "s");
    System.out.println("Speed: " + gesture.speed());
    System.out.println("//////////////////////////////////////");
    lastGesture = "Gesture type: " + gesture.type().toString() + "\n";
    lastGesture += "ID: " + gesture.id() + "\n";
    lastGesture += "Position: " + leap.convertVectorToPVector(gesture.position()) + "\n";
    lastGesture += "Direction: " + gesture.direction() + "\n";
    lastGesture += "Speed: " + gesture.speed() + "\n";
    lastGesture += "Duration: " + gesture.durationSeconds() + "s" + "\n";
  } 
  else if (gesture.state() == State.STATE_START) {
  } 
  else if (gesture.state() == State.STATE_UPDATE) {
  }
}

public void screenTapGestureRecognized(ScreenTapGesture gesture) {
  if (gesture.state() == State.STATE_STOP) {
    System.out.println("//////////////////////////////////////");
    System.out.println("Gesture type: " + gesture.type());
    System.out.println("ID: " + gesture.id());
    System.out.println("Position: " + leap.convertVectorToPVector(gesture.position()));
    System.out.println("Direction: " + gesture.direction());
    System.out.println("Duration: " + gesture.durationSeconds() + "s");
    System.out.println("//////////////////////////////////////");
    lastGesture = "Gesture type: " + gesture.type().toString() + "\n";
    lastGesture += "ID: " + gesture.id() + "\n";
    lastGesture += "Position: " + leap.convertVectorToPVector(gesture.position()) + "\n";
    lastGesture += "Direction: " + gesture.direction() + "\n";
    lastGesture += "Duration: " + gesture.durationSeconds() + "s" + "\n";
  } 
  else if (gesture.state() == State.STATE_START) {
  } 
  else if (gesture.state() == State.STATE_UPDATE) {
  }
}

public void KeyTapGestureRecognized(KeyTapGesture gesture) {
  if (gesture.state() == State.STATE_STOP) {
    System.out.println("//////////////////////////////////////");
    System.out.println("Gesture type: " + gesture.type());
    System.out.println("ID: " + gesture.id());
    System.out.println("Position: " + leap.convertVectorToPVector(gesture.position()));
    System.out.println("Direction: " + gesture.direction());
    System.out.println("Duration: " + gesture.durationSeconds() + "s");
    System.out.println("//////////////////////////////////////");
    lastGesture = "Gesture type: " + gesture.type().toString() + "\n";
    lastGesture += "ID: " + gesture.id() + "\n";
    lastGesture += "Position: " + leap.convertVectorToPVector(gesture.position()) + "\n";
    lastGesture += "Direction: " + gesture.direction() + "\n";
    lastGesture += "Duration: " + gesture.durationSeconds() + "s" + "\n";
  } 
  else if (gesture.state() == State.STATE_START) {
  } 
  else if (gesture.state() == State.STATE_UPDATE) {
  }
}

public void keyPressed() {
  if (key == 'c') {
    if (leap.isEnabled(Type.TYPE_CIRCLE)) {
      leap.disableGesture(Type.TYPE_CIRCLE);
      lastGesture = "Circle Gesture disabled.";
    } 
    else {
      leap.enableGesture(Type.TYPE_CIRCLE);
      lastGesture = "Circle Gesture enabled.";
    }
  }

  if (key == 's') {
    if (leap.isEnabled(Type.TYPE_SWIPE)) {
      leap.disableGesture(Type.TYPE_SWIPE);
      lastGesture = "Swipe Gesture disabled.";
    } 
    else {
      leap.enableGesture(Type.TYPE_SWIPE);
      lastGesture = "Swipe Gesture enabled.";
    }
  }

  if (key == 'k') {
    if (leap.isEnabled(Type.TYPE_KEY_TAP)) {
      leap.disableGesture(Type.TYPE_KEY_TAP);
      lastGesture = "KeyTap Gesture disabled.";
    } 
    else {
      leap.enableGesture(Type.TYPE_KEY_TAP);
      lastGesture = "KeyTap Gesture enabled.";
    }
  }

  if (key == 't') {
    if (leap.isEnabled(Type.TYPE_SCREEN_TAP)) {
      leap.disableGesture(Type.TYPE_SCREEN_TAP);
      lastGesture = "ScreenTap Gesture disabled. ";
    } 
    else {
      leap.enableGesture(Type.TYPE_SCREEN_TAP);
      lastGesture = "ScreenTap Gesture enabled. ";
    }
  }
}
public void stop() {
  leap.stop();
}


License

LeapMotionP5 library for Processing.
Copyright (c) 2012-2013 held jointly by the individual authors.

LeapMotionP5 library for Processing is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

LeapMotionP5 library for Processing is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with LeapMotionP5 library for Processing.  If not, see http://www.gnu.org/licenses/.
Leap Developer SDK.
Copyright (C) 2012-2013 Leap Motion, Inc. All rights reserved.

NOTICE: This developer release of Leap Motion, Inc. software is confidential
and intended for very limited distribution. Parties using this software must
accept the SDK Agreement prior to obtaining this software and related tools.
This software is subject to copyright.

leapmotionp5's People

Contributors

onformative avatar schwittlick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leapmotionp5's Issues

x and y values for getNormal() and getDirection()

The x and y values for leap.getNormal() and leap.getDirection() seems to be always around the same value (~600) regardless of what the hand position is.

direction: [ 599.8891, 599.4454, -5.1703267 ]
normal: [ 600.1245, 601.0216, -2.9786503 ]
direction: [ 599.68604, 599.3616, -5.032427 ]
normal: [ 599.88165, 601.01434, -3.192268 ]
direction: [ 599.67926, 599.3613, -5.0309515 ]
normal: [ 599.87476, 601.0144, -3.1915004 ]
direction: [ 599.6721, 599.36145, -5.0303807 ]
normal: [ 599.867, 601.0147, -3.1883 ]
direction: [ 599.6749, 599.3633, -5.038344 ]
normal: [ 599.83813, 601.01636, -3.1691191 ]
direction: [ 599.6968, 599.3513, -5.0060773 ]
normal: [ 599.75183, 601.0064, -3.2183874 ]
direction: [ 599.73267, 599.30475, -4.849902 ]
normal: [ 599.62695, 600.96704, -3.453796 ]
direction: [ 599.7609, 599.20953, -4.466412 ]
normal: [ 599.5357, 600.8824, -3.9391432 ]
direction: [ 599.77747, 599.1443, -4.162846 ]
normal: [ 599.4974, 600.821, -4.2475247 ]
direction: [ 599.7829, 599.1191, -4.041683 ]
normal: [ 599.4956, 600.8046, -4.331498 ]
direction: [ 599.7618, 599.1734, -4.312445 ]
normal: [ 599.52

Retrieve ID of when fingers exist/active/removed

To return an ID (much like a TUIO cursor) to suggest when a finger has been detected and to allocate it an ID

Method to check if finger exists still by passing into it the ID perhaps

Method to check if finger has been removed

I see in the notes something about onFingerEnterand onFingerLeave

Can yu possibly explain if this is what im asking for ?

Is it possible to have a basic runnable snippet?

Hello,

I have found this library and I found it amazingly interesting as LeapMotion, currently, lacks of any gesture recognition.

I have tried to use your 'Basic Example' but I did not manage to actually run it.

Would it be possible to have a basic runnable snippet? Just a snippet where 1 or 2 gestures work; with a proper class definition, a main and so on.

Thanks!

/N.

getFingerList() not returning any data

Processing v1.5.1 (Windows 8)
Leap SDK v0.7.6

When I run the example active_fingers, I'm always getting an empty array returned by getFingerList. I have the Leap visualiser running at the same time, and there is definitely data being displayed there.

Any idea why this might be?

Transfer to OpenLeap

Hey @Mrzl!

This is an awesome project! I remember you recently asked me about it and OpenLeap.

I wanted to take a look at it this weekend (and from what I've seen it's pretty awesome) but it looks like you forked it (rather than transferred it) to OpenLeap. If this was because you don't know how (the process isn't all that intuitive) an explanation is available at https://developer.leapmotion.com/forums/forums/projects-and-collaborations/topics/leap-open-source-github midway down the page.

If this was because you wanted admin rights, fear not! You can transfer a repo to OpenLeap and still have complete admin rights (which include the option to transfer the repo back to yourself if you so choose.) Just email [email protected] or comment anywhere asking for them to get them!

I've deleted the fork so now you can transfer this repo at will.

-Owen

Processing 3 Compatility

Hi,
Functions like getVelocity() and getNormal() do not work in Processing 3, while they work in Processing 2. Can this be fixed please?

Access to screen calibration?

There's an example by Glchriste, using another Leap Processing library:
https://github.com/Glchriste/Leap-Circles
...where she accesses the screen calibration using:
Screen screen = controller.calibratedScreens().get(0);

Have you got an equivalent for this in LeapMotionP5?

Thanks! It's a huge help that you've made an actually cross-platform library. :)

Library Doesnt Appear in Processing

I followed he instructions of downloading and unziping the file then putting it into the Processing library folder after renaming it but it still doesn't show up in my list of available libraries?

No library found for com.leapmotion.leap.Gesture

Hello,

When i test gesture_recognition.pde i have some messages

No library found for com.leapmotion.leap.Gesture
No library found for com.leapmotion.leap.Gesture
Leap Motion Initialized
Leap Motion Connected

active_fingers.pde for example is Ok

I use the leapmotion with Leap_Motion_Installer_release_public_win_x86_1.0.2+7287_ah730.exe
in windows XP and Processing 2.0.1

Thank you for your work in leap motion processing support

best regards
Alain

getAcceleration(Hand hand)

when returning the acceleration of a hand, return the average of all pointables attached to that hand. this should provide a little more stable and reliable acceleration value.

Receiving tracking data while running in background.

I am using LeapMotionP5 for a project and every time I change (Cmd+Tab) the window on another application (under OS X 10.9.2), leaving the Processing sketch running in the background, it seems the sketch doesn't get any data from the Leap Sensor.

I looked at the LEAP visualiser which seems to work in the background. Also found this https://leapmotion.zendesk.com/entries/39981046-Testing-Background-Leap-Applications ...but not sure how to implement it.

Any help on this would be amasing.
Thank you,

finger gestures only work with one finger

currently the gesture recognition only works if there is one and only one finger tracked. this should be changed so the gesture recognition can be 'attached' to one specific finger.

include wiigee as gesture recognition library

wiigee seems to be a way metter choice than the 1$ library. the wiigee library is under LGPL and therefore the code maybe be used and distributed, but not changed. it is not neccessary to change the library, it is neccessary to make it work with different input though. wrapping around it might do the trick? http://www.wiigee.org

ID finger

Hello, I just receive my leap motion today and I try to create a particule when the finger go in the scene, and my idea is detect the ID of finger to create or not a particule, but I don't find an instruction like finger.getID() or something like that in the library.
You know if it's possible to catch the ID, because when I write the println(finger), I've the ID but not possible to catch.

Thx

Stan

Can't find dependent libraries

I´ve been using the library pefectly fine until i changed my operating system from a 32 bits Win7 to a 64bits win7.. and now the library fails to load.
I updated de sdk to the 0.7.9.

here the log of processing.

Display 0 does not exist, using the default display instead. Native code library failed to load. java.lang.UnsatisfiedLinkError: C:\Users\internet\Documents\Processing\libraries\LeapMotionP5\library\windows\LeapJava.dll: Can't find dependent libraries

Problems with the library - missing files

When I run the gesture_recognition files I get the following errors:

No library found for com.leapmotion.leap.Gesture
No library found for com.leapmotion.leap.Gesture
Leap Motion Initialized
Leap Motion Connected

I saw others had this problem, no solution was offered and the issue was closed. Any idea how to resolve?

Many thanks

update to leap sdk version 0.74

ill update the gesture recognition part and everything else that came with the new sdk update when i get back from vacation in 2-3 days.

Number of Fingers Recognition

Hi,

Thank you for your contribution to Processing community. I was looking for best way to recognize number of fingers using the LeapMotionP5 library to activate gesture recognition. Please advise. Thank You!

Managing arraylist of objects with the getFingerList() arraylist

I have a question concerning the management of an arraylist in LeapMotion p5. I would like to compare my arraylist of objects with the one given by the getFingerList () function to add the new fingers and remove those that are no longer visible. Also, when a finger is no longer visible, I wish there was a fade effect and keeps the position when the finger is no longer detected . And, if I reposition the finger, another object is created and follow the finger. A strategy that I've used is to make the comparison between the arraylist of fingers, obtained with getFingerList () function, from the previous frame to the current frame with getFrameBeforeFrame () and getFrame () functions. So, if there is a difference between them, I delete or add an object in my arraylist. This strategy does not work very well, I have difficulty to manage my arraylist. So, I wanted to know if you know a better technique.

I have a version with a hashmap(with the comparison of the arraylist of fingers of two different frames) and another with an arraylist(comparison between the arraylist of finger and my arraylist of objects).


MAIN (with a hashmap)

import com.onformative.leap.LeapMotionP5;
import com.leapmotion.leap.Finger;
import java.util.*;
LeapMotionP5 leap;
HashMap <Integer, Objet> tObjets;

public void setup() {
size(500, 500, P3D);
leap = new LeapMotionP5(this);
tObjets = new HashMap <Integer, Objet>();
}

public void draw() {
background(0);
fill(255);
for (Finger finger : leap.getFingerList()) {
PVector fingerPos = leap.getTip(finger);
ellipse(fingerPos.x, fingerPos.y, 10, 10);
}

if (leap.getFrameBeforeFrame(leap.getFrame()) != null) {
//size of the arraylist of the previous frame
int nbFP = leap.getFingerList(leap.getFrameBeforeFrame(leap.getFrame())).size();
//size of the arraylist of the current frame
int nbFC = leap.getFingerList(leap.getFrame()).size();

for (Finger f : leap.getFingerList()) {
  PVector fingerPos = leap.getTip(f);
  if (!(tObjets.containsKey(f.id()))) {
    tObjets.put(f.id(), new Objet(fingerPos));
  }
}
// if the previous frame contain more than the current frame
if (nbFP > nbFC) {
  for (Finger f : leap.getFingerList(leap.getFrameBeforeFrame(leap.getFrame()))) {
    if (tObjets.containsKey(f.id()) && !(tObjets.containsKey(f.id()))) {
      tObjets.remove(f.id());
      //break;
    }
  }
}

}

for (Finger f : leap.getFingerList()) {
Objet o = (Objet)tObjets.get(f.id());
PVector fingerPos = leap.getTip(f);
if (o != null) {
o.setPosition(fingerPos);
}
}

// draw the object from the arraylist objets
Iterator i = tObjets.entrySet().iterator();
while (i.hasNext ()) {
Map.Entry o = (Map.Entry)i.next();
tObjets.get(o.getKey()).display();
}
}


MAIN (with an arrayList)

import com.onformative.leap.LeapMotionP5;
import com.leapmotion.leap.Finger;

LeapMotionP5 leap;
ArrayList objets;
void setup() {
size(600, 600, P3D);
leap = new LeapMotionP5(this);
objets = new ArrayList();
}

void draw() {
background(0);
int nbFingers = leap.getFingerList().size();
int nbObjets = objets.size();
ArrayList listeFingers = leap.getFingerList();

// add objects in the arraylist objets
if (nbFingers > nbObjets) {
for (Finger finger : leap.getFingerList()) {
PVector fingerPos = leap.getTip(finger);
objets.add(new Objet(fingerPos, finger.id()));
}
}
else if (nbFingers == 0) {
objets.clear();
}

else if (nbFingers <= nbObjets) {
int c = 0;
for (int i=0; i<leap.getFingerList().size(); i++) {
Finger finger = leap.getFingerList().get(i);
Objet o = objets.get(c);
if (finger.id() != o.getId()) {
objets.remove(c);
break;
}
c++;
}
}

int c = 0;
for (Finger finger : leap.getFingerList()) {
PVector fingerPos = leap.getTip(finger);
Objet o = objets.get(c);
o.setPosition(fingerPos);
o.draw();
}
println(objets.size());
}


CLASS Objet (same for both)

public class Objet {
private PVector position;
private color couleur;
private float opacite, cible, facteur;

public Objet(PVector _position) {
position = _position;
couleur = color(255, 0, 0);
opacite = 255;
cible = 255;
facteur = 0.1;
}
public void display() {
// for the fadeout
opacite = (cible - opacite) * facteur + opacite;
pushMatrix();
translate(position.x, position.y, 0);
pushStyle();
stroke(255, 0, 0, opacite);
noFill();
sphereDetail(int(random(3, 5)));
sphere(20);
popStyle();
popMatrix();
}

public boolean mort() {
if (opacite <= 0) {
return true;
}
else {
return false;
}
}

public PVector getPosition() {
return position;
}
public void setPosition(PVector pos) {
position = pos.get();
}

// for the fadeout
public void setCible(float _cible) {
cible = _cible;
}
public float getOpacite() {
return opacite;
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.