Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help in understanding the code from the LEAP motion SDK files. I've been planning to create a separate Graphical User Interface (GUI) along

I need help in understanding the code from the LEAP motion SDK files. I've been planning to create a separate Graphical User Interface (GUI) along with it. So for example, I'd like to display the coordinates of an object being tracked/detected by the LEAP motion controller. I don't know how to integrate this code with a GUI. My confusion begins with the "def main()" until the end, please provide a detailed explanation of each line if possible. Many thanks, cheers!

 import Leap, sys, thread, time class LeapMotionListener(Leap.Listener): def on_init(self, controller): print "Initialized" def on_connect(self, controller): print "Motion Sensor Connected" def on_disconnect(self, controller): print "Motion Sensor Disconnected" def on_exit(self, controller): print "Exited" def on_frame(self, controller): frame = controller.frame() for hand in frame.hands: normal = hand.palm_normal direction = hand.direction radius = hand.sphere_radius if hand.is_left: if direction.pitch * Leap.RAD_TO_DEG < -20: print " Forward " elif direction.pitch * Leap.RAD_TO_DEG < -10: if normal.roll * Leap.RAD_TO_DEG > 20: print " Forward Left " if normal.roll * Leap.RAD_TO_DEG < -20: print " Forward Right " elif direction.pitch * Leap.RAD_TO_DEG > 40: print " Backward " elif direction.pitch * Leap.RAD_TO_DEG > 30: if normal.roll * Leap.RAD_TO_DEG > 20: print " Backward Left " if normal.roll * Leap.RAD_TO_DEG < -20: print " Backward Right " elif normal.roll * Leap.RAD_TO_DEG < -40: print " Right " elif normal.roll * Leap.RAD_TO_DEG > 40: print " Left " else: print " Hover " if not hand.is_left: if radius < 40: print " Hold " else: print " Fire " 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() 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions