forked from isaaxug/handson-object-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.py
32 lines (24 loc) · 745 Bytes
/
sample.py
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 Flask, Response, render_template
from imutils.video.pivideostream import PiVideoStream
import cv2
import time
app = Flask(__name__)
camera = PiVideoStream(resolution=(400, 304), framerate=5).start()
time.sleep(2)
def gen(camera):
while True:
frame = camera.read()
ret, jpeg = cv2.imencode('.jpg', frame)
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + jpeg.tobytes() + b'\r\n\r\n')
@app.route('/')
def index():
return Response(gen(camera),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(
host='0.0.0.0',
debug=False,
threaded=True,
use_reloader=False
)