forked from ericescobar/Chicken_Door
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
32 lines (26 loc) · 756 Bytes
/
camera.py
File metadata and controls
32 lines (26 loc) · 756 Bytes
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
from flask import (
Blueprint, jsonify, flash, g, redirect, render_template, request, url_for, send_file
)
from picamera import PiCamera
import time
import io
bp = Blueprint('camera', __name__)
@bp.route('/camera/current')
def get_picture():
stream = io.BytesIO()
camera = None
try:
camera = PiCamera()
camera.start_preview()
time.sleep(2)
camera.capture(stream, 'jpeg')
camera.stop_preview()
camera.close()
stream.seek(0)
return send_file(
io.BytesIO(stream.read()),
mimetype='image/jpg')
except:
if camera is not None:
camera.close()
raise Exception("Camera is all messed up yo!")