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!



2 comments:

  1. As Internet is shrinking our world into a Global Village, E-commerce is growing by leaps and bounds. In fact in today's techno-savvy world, Internet and E-commerce are the two sides of the same coin olpccanada com

    ReplyDelete
  2. Coaching service of ielts, oat, english speaking, study abroad consultancy is provided by Cambridge English Academy in the name of noida, delhi, laxmi nagar etc. in which you are also given study material, notes and extra classes along with the course. You do not even have to pay extra fees. In ielts coaching in noida, you get the facility of online and offline classes in which highly educated and very professional teachers teach you so that you can fulfill your dream of knowing Abroad and create a secure future for yourself. To know or for Demo contact -
    to take a demo
    Website - https://cambridgeenglish.org.in/
    for call - 9667728146

    ReplyDelete