FlaskCameraLiveStream/main.py

52 lines
1.3 KiB
Python
Raw Permalink Normal View History

from flask import Flask, render_template, Response
2020-09-21 20:44:29 +00:00
from camera import VideoCamera
from util import list_files_in_dir, generate_url
camera = VideoCamera(flip=False)
2020-09-21 20:44:29 +00:00
app = Flask(__name__)
2020-09-21 20:44:29 +00:00
@app.route('/')
def index():
return render_template('index.html')
@app.route('/images')
def images_view():
file_directory = 'images'
url_list = list()
for file in list_files_in_dir('static/'+file_directory):
url_list.append(generate_url(file_directory, file))
return render_template('images.html', urls=url_list)
2020-09-21 20:44:29 +00:00
def gen(camera):
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
2020-09-21 20:44:29 +00:00
@app.route('/video_feed')
def video_feed():
return Response(gen(camera),
2020-09-21 20:44:29 +00:00
mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/picture')
def take_picture():
camera.take_picture()
return "None"
@app.route('/moreexposure')
def more_exposure():
exposure = camera.get_exposure()
camera.set_exposure(exposure + 1)
return "None"
@app.route('/lessexposure')
def less_exposure():
exposure = camera.get_exposure()
camera.set_exposure(exposure - 1)
return "None"
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=False)