Get Fingers Position with LeapMotion


I got a leapmotion, i've installed the software from their website and tested it, it works. Then i installed the leapmotion2 service, and typed this script as explain in the leapmotion page :


#this simple script will print in the python tab the grab strength of your left hand
from __future__ import division
leap = Runtime.createAndStart("leap","LeapMotion2")
def onFrame(frame):
strength = ((frame.hands().leftmost().grabStrength())*100)
print strength
And i would get this error : 4982 [Thread-6] ERROR class org.myrobotlab.framework.Service  - did not find method - onInit(Controller)
Then i checked the python tab and it was showing a number between 0 and 100 and i was wondering if it possible to get the fingers position or not ?
Thanks in advance
Herzeh's picture

I'm not even sure if the SDK

I'm not even sure if the SDK is fully supported, i'm trying to do this 


frame.hands().rightmost().fingers().is_empty and it says : 

AttributeError: 'com.leapmotion.leap.FingerList' object has no attribute 'is_empty'
It does however exist in the SDK api Documentation :
Herzeh's picture

Ok to answer myself, i found

Ok to answer myself, i found out that the Java Leap DLL was used in MRL, and i was reading the Python API documentation. So if you wanna use LeapMotion with MRL, use the JAVA LeapMotion API documentation here :

GroG's picture

Correct its Java, but you can

Correct its Java, but you can access the Java methods "through" Python - but they will have the Java format of the method.

Did you get what you needed?

In MRL on a frame you should be able to do this method..




Herzeh's picture

I can't identify the fingers

I can't identify the fingers in MRL, it's so weird i use this : 


finger_list = frame.hands().get(0).fingers()

for finger in finger_list:

   if finger.type() == TYPE_THUMB:

      print "thumb"


but it says that it doesn't know TYPE_THUMB, so i tried Finger.TYPE_THUMB as there is an enum in the Finger class with TYPE_THUMB, TYPE_INDEX, etc..I don't understand this.

GroG's picture

upper case usually stands for

upper case usually stands for constants - quick google search on TYPE_THUMB, LeapMotion gave me this link

Below is snippet ..  so in Python just have at the top
TYPE_THUMB = 0 etc. ..

then in your function you can have

def onFrame(frame):
  global TYPE_THUMB, etc...
 finger_list = frame.hands().get(0).fingers()

  for finger in finger_list:

    if finger.type() == TYPE_THUMB:

      print "thumb"

New in version 2.0.


Type: integer

The integer code representing the finger name.

  • 0 = TYPE_THUMB
  • 1 = TYPE_INDEX
  • 3 = TYPE_RING
  • 4 = TYPE_PINKY


Herzeh's picture

I know these are enums so

I know these are enums so instead, i tried using 0 1 2 3 4 but it doesn't go into the if code, its so strange.

GroG's picture

"doesn't go into the if code"

"doesn't go into the if code" <- does this mean there is an Error returned?

Herzeh's picture

No, anyway i've used the

No, anyway i've used the tools here :

And i manage to control the servos with leapmotion, however in order to get this working i have to upload StandardFirmata to arduino and i have an issue here. Is there a way to get StandardFirmata and the generated MRL code for arduino to coexist ? Because i want to get kinect and leapmotion working to control my InMoov.


GroG's picture

I've sent a signal for help

I've sent a signal for help ...

Herzeh's picture

So i took the javascript code

So i took the javascript code given in the Inmoov website to control hand with leapmotion, and tried to convert it to be usable in MRL, but i have an issue : 

That javascript code expects to have 40 frames/s and not capture every frame like it is the case in MRL, so i wanna implement LeapMotion so that you can use both methods (The listener and the while version where you process as much frames as you want and not every frame whenever there is one) since i dont need to be as precise as onFrame function allows me to be (it causes a problem where my servo doesn't have enough time to move, but moves all direction too fast and gives me a weird result).


So my question here is how do i recompile (easily if possible) MRL if i wanted to (i want to modify the file) ?

kwatters's picture

TYPE_THUMB example leap motion

In python land, you've gotta import the java classes to they are known locally.  

At the top of your script, you can add the following line:


import com.leapmotion.leap.Finger.Type as Type
# Then you can see the type is defined
if Type.TYPE_THUMB == myFinger:
  print "It's a thumb!"
The enum is defined as following:
Hope this helps!
Herzeh's picture

Well it says that  there is

Well it says that  there is no module such as : com.leapmotion.leap.Finger.Type

kwatters's picture

jar file missing in the classpath?

Hmm.. That's strange. so when you do

"import com.leapmotion.leap.Finger.Type as Type"   it no worky..
I wonder if the LeapJava.jar is in your classpath...  Check if you have it in your libraries/jar directory...  That's where it's defined..

Herzeh's picture

I have that in the jar folder

I have that in the jar folder

kwatters's picture

java vs python syntax oops.. .

Sorry, my bad.  The example I gave was some strange hybrid of java syntax and python syntax. 



"from com.leapmotion.leap.Finger import Type"

that should work for you.  
then you can reference  Type.TYPE_THUMB in your python code  (I hope)