52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
from flask import Flask, render_template, Response
|
|
from camera import VideoCamera
|
|
from util import list_files_in_dir, generate_url
|
|
|
|
camera = VideoCamera(flip=False)
|
|
|
|
app = Flask(__name__)
|
|
|
|
@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)
|
|
|
|
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')
|
|
|
|
@app.route('/video_feed')
|
|
def video_feed():
|
|
return Response(gen(camera),
|
|
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) |