forked from EbenKouao/pi-camera-stream-flask
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (59 loc) · 2.23 KB
/
Copy pathmain.py
File metadata and controls
71 lines (59 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask, render_template, Response, request, send_from_directory, redirect, url_for
from picamera import Picamera
import os
import datetime
import time
write_sleep_interval = 0.1 # interval to allow file IO to finish before attempting to send
try:
camera = Picamera(hflip=1, vflip=1, res='full')
app = Flask(__name__)
@app.route('/')
@app.route('/index')
def index():
try:
size = os.path.getsize('static/latest-image.jpg')
size = size/1024.
mtime = os.path.getmtime('static/latest-image.jpg')
mtime = datetime.datetime.fromtimestamp(mtime)
except Exception as msg:
size = 'no image found'
mtime = 'no image found'
print(msg)
print(os.listdir('.'))
return render_template('index.html', size=size, mtime=mtime)
@app.route('/getpicture')
def get_picture():
# take picutre and send jpg with current configuration
camera.take_picture()
time.sleep(write_sleep_interval)
return send_from_directory(directory='static', filename='latest-image.jpg')
@app.route('/getfull')
def get_picture_full():
# configure as full res, take picture and send as jpeg
camera.res = 'full'
camera.configure()
camera.take_picture()
time.sleep(write_sleep_interval)
return send_from_directory(directory='static', filename='latest-image.jpg')
@app.route('/getlow')
def get_picture_low():
# configure as full res, take picture and send as jpeg
camera.res = 'low'
camera.configure()
camera.take_picture()
time.sleep(write_sleep_interval)
return send_from_directory(directory='static', filename='latest-image.jpg')
@app.route('/getmedium')
def get_picture_medium():
# configure as full res, take picture and send as jpeg
camera.res= 'medium'
camera.configure()
camera.take_picture()
time.sleep(write_sleep_interval)
return send_from_directory(directory='static', filename='latest-image.jpg')
except RuntimeError:
raise
except KeyboardInterrupt:
camera.close()
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=False)