-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsc_app.py
61 lines (44 loc) · 1.23 KB
/
sc_app.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
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
# packages
from flask import Flask, render_template
"""
from flask import request
import base64
import cv2
import numpy as np
import threading
"""
# web app instance
app = Flask(__name__)
# root route
@app.route("/")
def index_html():
return render_template("index.html")
# update remote webcam view frame
"""
def update(frame):
# open frame in a window
cv2.imshow('Stalking', frame)
cv2.waitKey()
"""
# get video on server side
"""
@app.route('/stream', methods=['POST'])
def vc_stream():
# extract base64 encoded string from the client (web browser)
img_str = request.form.get('frame').split('data:image/png;base64,')[-1]
# convert base64 encoded string to a byte string
img_byt = base64.b64decode(img_str)
# convert a byte string to a numpy array
image = np.fromstring(img_byt, np.uint8)
# convert a numpy array to an opencv compatible image
frame = cv2.imdecode(image, cv2.IMREAD_COLOR)
# display the frame in a window
display_thread = threading.Thread(target=update, args=(frame,))
display_thread.start()
# return from the API call
return ''
"""
# main loop
if __name__ == "__main__":
# start web server
app.run(host="127.0.0.1", port=8080, debug=True)