2023-08-23 11:02:25 +00:00
|
|
|
from flask import Flask, render_template, Response
|
2020-09-21 20:44:29 +00:00
|
|
|
from camera import VideoCamera
|
2023-08-23 11:02:25 +00:00
|
|
|
from util import list_files_in_dir, generate_url
|
2020-10-03 18:46:38 +00:00
|
|
|
|
2023-08-23 11:02:25 +00:00
|
|
|
camera = VideoCamera(flip=False)
|
2020-10-03 18:46:38 +00:00
|
|
|
|
2020-09-21 20:44:29 +00:00
|
|
|
app = Flask(__name__)
|
2020-10-03 18:46:38 +00:00
|
|
|
|
2020-09-21 20:44:29 +00:00
|
|
|
@app.route('/')
|
|
|
|
def index():
|
2023-08-23 11:02:25 +00:00
|
|
|
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-10-03 18:46:38 +00:00
|
|
|
|
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-10-03 18:46:38 +00:00
|
|
|
|
2020-09-21 20:44:29 +00:00
|
|
|
@app.route('/video_feed')
|
|
|
|
def video_feed():
|
2023-08-23 11:02:25 +00:00
|
|
|
return Response(gen(camera),
|
2020-09-21 20:44:29 +00:00
|
|
|
mimetype='multipart/x-mixed-replace; boundary=frame')
|
2020-10-03 18:46:38 +00:00
|
|
|
|
2022-05-05 11:08:12 +00:00
|
|
|
@app.route('/picture')
|
|
|
|
def take_picture():
|
2023-08-23 11:02:25 +00:00
|
|
|
camera.take_picture()
|
2022-05-05 11:08:12 +00:00
|
|
|
return "None"
|
|
|
|
|
2023-08-23 11:02:25 +00:00
|
|
|
@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"
|
2020-10-03 18:46:38 +00:00
|
|
|
|
2023-08-23 11:02:25 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(host='0.0.0.0', debug=False)
|