0
import Leap, sys, thread, time
from Leap import CircleGesture, KeyTapGesture, ScreenTapGesture, SwipeGesture
from flask import Flask
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"

def on_connect(self, controller):
    print "Motion Sensor Connected!"

    controller.enable_gesture(Leap.Gesture.TYPE_CIRCLE);
    controller.enable_gesture(Leap.Gesture.TYPE_KEY_TAP);
    controller.enable_gesture(Leap.Gesture.TYPE_SCREEN_TAP);
    controller.enable_gesture(Leap.Gesture.TYPE_SWIPE);

def on_disconnect(self, controller):
    print "Motion Sensor Disconnected"

def on_exit(self, controller):
    print "Existed"

 def on_frame(self, controller):
    frame = controller.frame()

    #print " Number of Hands: " + str(len(frame.hands))
    hand = str(len(frame.hands))
    print hand
    return hand
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()

The output is: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 111111 0 0 0 0 0 0 0 0 0 0 0 goes on until I terminate the program.

I want this output to be sent to webpage using flask. how can i do it?

NOTE: The above is a leapmotion hand detection program. the above program runs only with python 32bit and having leapmotion sdk

Kishan Jangam
  • 39
  • 1
  • 8
  • Could you also supply the code for your Flask application. You imported that but didn't create a Flask app, yet. Do you plan to continuously send your output to the webpage or event-driven? – MrLeeh Nov 29 '16 at 10:43

1 Answers1

1

Write your program so that the continuous output is the result of a generator, then give the generator to a flask Response.

ref: http://flask.pocoo.org/docs/0.11/patterns/streaming/

Stephane Martin
  • 1,612
  • 1
  • 17
  • 25