Hi,
I am trying to use the interaction box to scale down the coordinates captured by the leap using the normalized_point(). I followed the steps from here: https://developer-archive.leapmotion.com/documentation/python/api/Leap.InteractionBox.html.
However, I have the following error:
File "/home/eeyms8/Leap/Leap.py", line 66, in swiggetattr_nondynamic
return object.getattr(self, name)
AttributeError: type object 'object' has no attribute 'getattr'
This is the code i am running:
import Leap, sys, thread, time, ctypes
from Leap import KeyTapGesture
class LeapMotionListener(Leap.Listener):
finger_names = ['Thumb', 'Index', 'Middle', 'Ring', 'Pinky']
bone_names = ['Metacarpal', 'Proximal', 'Intermediate', 'Distal']
state_names = ['STATE-INVALID', 'STATE_START', 'STATE_UPDATE', 'STATE_END']
def on_init(self, controller):
print "Initialized"
#opens file in write mode which clears the previous data saved on the file
data_file = open('data.txt', 'w')
data_file.close()
def on_exit(self, controller):
print "Exited"
def on_connect(self, controller):
print "Connected"
controller.enable_gesture(Leap.Gesture.TYPE_KEY_TAP);
def on_disconnect(self, controller):
print "Disconnected"
def on_frame(self, controller):
frame = controller.frame()
print "Frame ID: " + str(frame.id)
# checks for the numbers of hands detected by the leap and issues a warning if more than one hand is detected
numofHands = str(len(frame.hands))
if numofHands == "2":
print "Please only use one hand"
for hand in frame.hands:
handType = "Left Hand" if hand.is_left else "Right Hand"
#averages the palm postion from the last 10 frames
count = 0
average = Leap.Vector()
hand_to_average = frame.hands[0]
for i in range(0,9):
hand_from_frame = controller.frame(i).hand(hand_to_average.id)
if(hand_from_frame.is_valid):
average = average + hand_from_frame.palm_position
count +=1
average = average/count
#print average
iBox = frame.interaction_box
if iBox.is_valid:
end_point = hand.palm_position
normalizedPoint = iBox.normalized_point(end_point, True)
print normalizedPoint
def main():
listener = LeapMotionListener()
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()
I am using LeapMotion SDK Version 2.3.1+31549 with python 2.7.17 on Linux Ubuntu 18.04.4 LTS. I tried the solution mentined here: https://forums.leapmotion.com/t/leap-py-line-66-in--swig-getattr-nondynamic/5324
But it still doesn't work.
Thanks for your help in advance!