I wanted to use Leap Motion, so I wrote the program in Python. This time, I would like to get the number of recognized hands and the number of fingers.
The environment for development is here.
First of all, you need an SDK to use Leap Motion, so download the SDK from the developer site. When you unzip the downloaded folder, there is a folder called LeapSDK, so when you open the lib folder in it, you will use Leap.dll and Leap.lib in the Leap.py file and x64 folder.
The directory structure this time is here.
├─lib │ └─x64 └─src
Place Leap.py in src and Leap.dll and Leap.lib in x64.
This completes the preparation for handling Leap Motion in python.
Create test.py in the src folder. The contents of the file are as follows.
test.py
import sys
sys.path.insert(0,"../lib/x64")
import Leap
class SampleListener(Leap.Listener):
def on_connect(self,controller):
print "Connected"
def on_frame(self,controler):
frame = controler.frame()
print "Frame id: %d, hands: %d,fingers: %d" %(frame.id,len(frame.hands),len(frame.fingers))
def main():
listener = SampleListener()
controller = Leap.Controller()
controller.add_listener(listener)
print "Press Enter to quit...."
try:
sys.stdin.readline()
except KeyboardInterrupt:
pass
finally:
controller.remove_listener(listener)
if __name__=="__main__":
main()
Now let's run test.py. The file will run until some key is pressed.
python test.py
When executed, the number of hands and fingers recognized as Frame id will be displayed respectively.
Execution result
Frame id: 185744, hands: 2,fingers: 10
Frame id: 185745, hands: 2,fingers: 10
Frame id: 185746, hands: 2,fingers: 10
Frame id: 185747, hands: 2,fingers: 10
Frame id: 185748, hands: 2,fingers: 10
Frame id: 185749, hands: 1,fingers: 5
Frame id: 185750, hands: 1,fingers: 5
Frame id: 185751, hands: 0,fingers: 0
Frame id: 185752, hands: 0,fingers: 0
Frame id: 185753, hands: 0,fingers: 0
Frame id: 185754, hands: 0,fingers: 0
Frame id: 185755, hands: 0,fingers: 0
Now you can get the data from the basic Leap Motion.
The following is a reference site.
1.https://developer.leapmotion.com/documentation/python/devguide/Project_Setup.html 2.https://developer.leapmotion.com/documentation/python/devguide/Sample_Tutorial.html
Recommended Posts