Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, Response
- # emulated camera
- from camera import Camera
- import cherrypy
- # Raspberry Pi camera module (requires picamera package)
- # from camera_pi import Camera
- app = Flask(__name__)
- @app.route('/')
- def index():
- """Video streaming home page."""
- return render_template('index.html')
- def gen(camera):
- """Video streaming generator function."""
- while True:
- frame = camera.get_frame()
- yield (b'--frame\r\n'
- b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
- @app.route('/video_feed')
- def video_feed():
- """Video streaming route. Put this in the src attribute of an img tag."""
- return Response(gen(Camera()),
- mimetype='multipart/x-mixed-replace; boundary=frame')
- def run_server():
- cherrypy.tree.graft(app, '/')
- cherrypy.config.update({
- 'log.screen': True,
- 'engine.autoreload_on': True,
- 'server.socket_port': 5000,
- 'server.socket_host': '10.0.2.114'
- })
- try:
- cherrypy.engine.start()
- cherrypy.engine.block()
- except KeyboardInterrupt:
- cherrypy.engine.stop()
- if __name__ == '__main__':
- run_server()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement