Reputation: 1
I use Leap motion controller for hand gesture data acquisition. I use below python code but faced some problems. First, Leap library only works for python 2 therefor, I made an environment of version 2 in my anaconda to use my code. secondly, it just save a frame.data file which I think is empty. because it does not takes any time. also I don't think that my program even connects to LMC device.
import sys
import os
import Leap
import ctypes
controller = Leap.Controller()
frame = controller.frame()
hands = frame.hands
pointables = frame.pointables
fingers = frame.fingers
tools = frame.tools
serialized_tuple = frame.serialize
serialized_data = serialized_tuple[0]
serialized_length = serialized_tuple[1]
data_address = serialized_data.cast().__long__()
buffer = (ctypes.c_ubyte * serialized_length).from_address(data_address)
with open(os.path.realpath('frame.data'), 'wb') as data_file:
data_file.write(buffer)
Upvotes: -1
Views: 1214
Reputation: 26
I recommend reading through the Python documentation that is available on our developer site here and looking at the samples available within the Python binding which will help you to get started with accessing the hand tracking data using Python.
To resolve your issue you will need to wait until the controller tells you that a frame is ready. This is doable by declaring an event listener by extending the Leap.Listener class and attaching it to the controller with controller.add_listener(my_listener)
.
class SampleListener(Leap.Listener):
def on_init(self, controller):
pass
def on_connect(self, controller):
pass
def on_disconnect(self, controller):
# Note: not dispatched when running in a debugger.
pass
def on_exit(self, controller):
pass
def on_frame(self, controller):
# Get the most recent frame and report some basic information
frame = controller.frame()
# do things with the frame
...
# Create a sample listener and controller
listener = SampleListener()
controller = Leap.Controller()
# Have the sample listener receive events from the controller
controller.add_listener(listener)
If you do not wish to use listeners and event, then I recommend having a look at this section of the documentation here which shows the same snippet of code as above but indicates that the program should "wait until Controller.isConnected() evaluates to true".
Upvotes: 0