Friday, February 6, 2015

First day with Leap Motion Controller

I was pretty excited to receive my Leap Motion Controller last week, finally had some time to unbox it late last night and go thru the Python SDK HelloWorld example today.

I don't know how this can tie into Network engineering, perhaps we can build the network thru motion gestures like virtual lego? :)

Here is my knock off code of the tutorial, won't repeat what was already explained in detail on the page. The only difference is between line 14 to 16 that when detecting 10 fingers on the controller, it prints out the message, otherwise the screen sits idle:

    def on_frame(self, controller):
        frame = controller.frame()
        if len(frame.fingers) == 10:
            print "10 Little Monkeys Jumping on the Bed"


Here is a screenshot of the cool playground software that came with the controller. For the record, it tracks the hand to peel off a petal off the flower.


Here is the full code of the HelloWorld:

import sys
sys.path.insert(0, "./lib")
import Leap

from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture

class SampleListener(Leap.Listener):
 
    def on_connect(self, controller):
        print "Connected"
        controller.enable_gesture(Leap.Gesture.TYPE_SWIPE);
 
    def on_frame(self, controller):
        frame = controller.frame()
        if len(frame.fingers) == 10:
            print "10 Little Monkeys Jumping on the Bed"
         
        #Some other things the frame can track
        #print "Frame id: %d, timestamp: %d, hands: %d, fingers: %d, tools: %d, gestures: %d" % (
        #          frame.id, frame.timestamp, len(frame.hands), len(frame.fingers), len(frame.tools), len(frame.gestures()))      

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_listner(listener)
 
if __name__ == "__main__":
    main()
 

Happy coding!



No comments:

Post a Comment