-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
89 lines (63 loc) · 1.89 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from flask import Flask, render_template, Response, request, jsonify, after_this_request
from flask_ngrok import run_with_ngrok
from camera import VideoCamera
from models.predict import recognize
from cv2 import cv2
import numpy as np
import os
import json
from flask_cors import CORS, cross_origin
frames = []
# Initializing flask application
app = Flask(__name__)
run_with_ngrok(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/testing')
def pengujian():
return render_template('testing.html')
@app.route('/help')
def bantuan():
return render_template('help.html')
@app.route('/video_feed')
def video_feed():
frame = gen(VideoCamera())
return Response(frame,
mimetype='multipart/x-mixed-replace; boundary=frame')
# return Response(predict(VideoCamera()))
@app.route('/recognize', methods=['POST'])
def startRecognize():
print('start recognizing')
global frames
data = recognize(frames)
results = []
for d in data:
result = np.argmax(d[0], axis=-1)
print(result)
results.append(result)
print('hasil : ')
print(results)
result = np.bincount(results)
result = np.argmax(result)
print('hasil kelas : ')
print(result)
listdata = np.array(result).tolist()
result = json.dumps(listdata)
return jsonify(isError= False,
message= "Success",
statusCode= 200,
data= result), 200
def gen(camera):
global frames
while True:
frame = camera.get_frame()
frames.append(frame)
if(len(frames) == 20):
frames = []
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')
if __name__ == '__main__':
port = int(os.environ.get('PORT', 3000))
app.run()