質問内容
OpenCVとLeap Motionを同時に使いたいのでpython3でLeap Motionを使えるように調べたところ「Python3でLeap Motion」というサイトを発見しました。サイトの作成者の方に質問させていただいたり自分なりにやってみたりしたのですがよくわからないエラーが出てしまいました。
もしわかる方がいらっしゃったら解決していただきたいです。
###期待結果
anaconda仮想環境python2.7
python
1 ・ 2 ・ 3 ・ 4Frame id:10683, timestamp: 50514813528, hands:0, fingers:0 5Frame id:10680, timestamp: 50514813538, hands:0, fingers:0 6Frame id:10675, timestamp: 50514813549, hands:0, fingers:0 7Frame id:10674, timestamp: 50514813555, hands:0, fingers:0 8Frame id:10668, timestamp: 50514813566, hands:0, fingers:0 9Frame id:10664, timestamp: 50514813573, hands:0, fingers:0 10Frame id:10659, timestamp: 50514813589, hands:0, fingers:0 11 ・ 12 ・ 13 ・
エラーメッセージ
以下のエラーが繰り返されます
anaconda仮想環境python3.7
python
1 ・ 2 ・ 3 ・ 4Frame id:10683, timestamp: 50514813528, hands:0, fingers:0 5StopIteration 6 7The above exception was the direct cause of the following exception: 8 9Traceback (most recent call last): 10 File "sample.py", line 37, in on_frame 11 for hand in frame.hands: 12SystemError: <built-in function delete_HandList>returned a result with an error set 13 ・ 14 ・ 15 ・
###ソースコード
LeapmotionをダウンロードしたときについてきたSample.pyです。
元はimport Leap, sys, thread, time
でしたが、thread
でエラーが出てしまいました。しかしpython2.7環境でthread
抜きでも期待どおりの結果が出たので抜きました。
Sample.py
python
1import Leap, sys, time 2 3 4class SampleListener(Leap.Listener): 5 finger_names = ['Thumb', 'Index', 'Middle', 'Ring', 'Pinky'] 6 bone_names = ['Metacarpal', 'Proximal', 'Intermediate', 'Distal'] 7 8 def on_init(self, controller): 9 print ("Initialized") 10 11 def on_connect(self, controller): 12 print ("Connected") 13 14 def on_disconnect(self, controller): 15 # Note: not dispatched when running in a debugger. 16 print ("Disconnected") 17 18 def on_exit(self, controller): 19 print ("Exited") 20 21 def on_frame(self, controller): 22 # Get the most recent frame and report some basic information 23 frame = controller.frame() 24 25 print ("Frame id: %d, timestamp: %d, hands: %d, fingers: %d" % ( 26 frame.id, frame.timestamp, len(frame.hands), len(frame.fingers))) 27 28 # Get hands 29 for hand in frame.hands: 30 31 handType = "Left hand" if hand.is_left else "Right hand" 32 33 print (" %s, id %d, position: %s" % ( 34 handType, hand.id, hand.palm_position)) 35 36 # Get the hand's normal vector and direction 37 normal = hand.palm_normal 38 direction = hand.direction 39 40 # Calculate the hand's pitch, roll, and yaw angles 41 print (" pitch: %f degrees, roll: %f degrees, yaw: %f degrees" % ( 42 direction.pitch * Leap.RAD_TO_DEG, 43 normal.roll * Leap.RAD_TO_DEG, 44 direction.yaw * Leap.RAD_TO_DEG)) 45 46 # Get arm bone 47 arm = hand.arm 48 print (" Arm direction: %s, wrist position: %s, elbow position: %s" % ( 49 arm.direction, 50 arm.wrist_position, 51 arm.elbow_position)) 52 53 # Get fingers 54 for finger in hand.fingers: 55 56 print (" %s finger, id: %d, length: %fmm, width: %fmm" % ( 57 self.finger_names[finger.type], 58 finger.id, 59 finger.length, 60 finger.width)) 61 62 # Get bones 63 for b in range(0, 4): 64 bone = finger.bone(b) 65 print (" Bone: %s, start: %s, end: %s, direction: %s" % ( 66 self.bone_names[bone.type], 67 bone.prev_joint, 68 bone.next_joint, 69 bone.direction)) 70 71 if not frame.hands.is_empty: 72 print ("") 73 74def main(): 75 # Create a sample listener and controller 76 listener = SampleListener() 77 controller = Leap.Controller() 78 79 # Have the sample listener receive events from the controller 80 controller.add_listener(listener) 81 82 # Keep this process running until Enter is pressed 83 print ("Press Enter to quit...") 84 try: 85 sys.stdin.readline() 86 except KeyboardInterrupt: 87 pass 88 finally: 89 # Remove the sample listener when done 90 controller.remove_listener(listener) 91 92 93if __name__ == "__main__": 94 main() 95
あなたの回答
tips
プレビュー