Get Leap Motion data in Python.

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.

Development environment

The environment for development is here.

Environment

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.

Directory structure

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.

Run

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

Get Leap Motion data in Python.
Leap Motion in Python 3
Get data from Quandl in Python
Try using Leap Motion in Python
Get additional data in LDAP with python
Get Google Fit API data in Python
Get Youtube data in Python using Youtube Data API
Get date in Python
Get time series data from k-db.com in Python
How to run Leap Motion in non-Apple Python
Get YouTube Comments in Python
Handle Ambient data in Python
Get last month in python
Display UTM-30LX data in Python
Get Youtube data with python
Get Terminal size in Python
Explicitly get EOF in python
Get Evernote notes in Python
Get Japanese synonyms in Python
Get LEAD data using Marketo's REST API in Python
Get data from GPS module at 10Hz in Python
Read Protocol Buffers data in Python3
Get the desktop path in Python
Handle NetCDF format data in Python
[Python] Get economic data with DataReader
Get the script path in Python
Hashing data in R and Python
Get, post communication memo in Python
Hit REST in Python to get data from New Relic
Get the desktop path in Python
Get the host name in Python
Get started with Python in Blender
Get exchange rates from open exchange rates in Python
[Note] Get data from PostgreSQL with Python
Data input / output in Python (CSV, JSON)
Get Suica balance in Python (using libpafe)
Ant book in python: Sec. 2-4, data structures
Try working with binary data in Python
How to get a stacktrace in python
Python: Preprocessing in machine learning: Data acquisition
Get battery level from SwitchBot in Python
Easily graph data in shell and Python
Get a token for conoha in python
Get Started with TopCoder in Python (2020 Edition)
Python: Preprocessing in machine learning: Data conversion
Get the EDINET code list in Python
Get Precipitation Probability from XML in Python
Get Cloud Logging available in Python in 10 minutes
Double pendulum equation of motion in python
Get rid of DICOM images in Python
Get metric history from MLflow in Python
Get your own IP address in Python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python