-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
65 lines (41 loc) · 1.59 KB
/
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
62
63
64
65
import time
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
from flask_cors import CORS
import io
import base64
from PIL import Image
import cv2
import numpy as np
from flask import Flask, render_template
from webcam_detect import sign_detection
app = Flask(__name__)
socketio = SocketIO(app, cors_allowed_origins="*")
@socketio.on('image')
def image(data_image):
# decode and convert into image
b = io.BytesIO(base64.b64decode(data_image))
pimg = Image.open(b)
## converting RGB to BGR, as opencv standards
frame = cv2.cvtColor(np.array(pimg), cv2.COLOR_RGB2BGR)
#Detection
frame, letter, prediction_score = sign_detection(frame)
frame = cv2.putText(frame, 'CV', (480,390), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0) , 2, cv2.LINE_AA)
# Encode the frame as base64 string
retval, buffer = cv2.imencode('.jpg', frame)
jpg_as_text = base64.b64encode(buffer).decode('utf-8')
#Dictionary to be emitted
info = {'frame': jpg_as_text, 'letter' : letter, 'prediction_score' : prediction_score}
# Emit the frame data back to JavaScript client
socketio.emit('processed_frame', info)
@app.route('/detect', methods=['POST', 'GET'])
def detect():
return render_template('index.html')
@app.route('/about', methods=['POST', 'GET'])
def about():
return render_template('about.html')
@app.route('/', methods=['POST', 'GET'])
def landing():
return render_template('landing.html')
if __name__ == '__main__':
socketio.run(app, port = '5000', debug=True)