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()
输出是: 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 继续,直到我终止该程序。
我希望使用flask将此输出发送到网页。我怎么能这样做?
注意:以上是leapmotion手检测程序。上面的程序只运行python 32bit和leapmotion sdk
答案 0 :(得分:1)
编写程序,以便连续输出是生成器的结果,然后将生成器提供给烧瓶响应。