-
Notifications
You must be signed in to change notification settings - Fork 2
/
Application.py
189 lines (165 loc) · 4.97 KB
/
Application.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import os
import socket
from flask import Flask, render_template, request, Response, jsonify
from flask_bootstrap import Bootstrap
from gevent import monkey
from gevent.pywsgi import WSGIServer
monkey.patch_all()
from src.VideoStream import *
model_config = {
"model_path": 'models/yolov8n-seg-coco_fp16.onnx', # model path
"classes_path" : 'models/coco_label.txt', # classes path
"box_score" : 0.4,
"box_nms_iou" : 0.45,
"box_aspect_ratio" : None,
"box_stretch" : None,
}
cam_config = {
"cam_id" : 0,
'exposure': -2, # init cam exposure
'contrast': 50 # init cam contrast
}
VIDEO = VideoStreaming(cam_config=cam_config, model_config=model_config)
application = Flask(__name__,
static_folder='./src/templates/static',
template_folder='./src/templates')
Bootstrap(application)
@application.route('/')
def home():
TITLE = 'Object Segmentation App'
CAM_CONFIG = cam_config.copy()
CAM_CONFIG["sensor_h"] = int(VIDEO.sensorH)
CAM_CONFIG["sensor_w"] = int(VIDEO.sensorW)
CAM_CONFIG["display_h"] = int(VIDEO.displayH)
CAM_CONFIG["display_w"] = int(VIDEO.displayW)
MODLE_CONFIG = model_config.copy()
for key, value in model_config.items():
if type(value) == str:
MODLE_CONFIG[key] = os.path.basename(value)
CLASSES_CONFIG = VIDEO.MODEL.colors_dict.copy()
STYLE_CONFIG = VIDEO.style_dict.copy()
return render_template('index.html', TITLE=TITLE,
CAM_CONFIG = CAM_CONFIG,
MODEL_CONFIG = MODLE_CONFIG,
TARGETLIST = CLASSES_CONFIG,
STYLELIST = STYLE_CONFIG)
@application.route('/video_feed')
def video_feed():
'''
Video streaming route.
'''
return Response(
VIDEO.show(),
mimetype='multipart/x-mixed-replace; boundary=frame'
)
@application.route('/request_target_display')
def request_target_display():
targets_list = request.args.get('targetList')
print('*'*10)
print("display targets :", targets_list)
print('*'*10)
VIDEO.setViewTarget(targets_list)
return "nothing"
# Button requests called from ajax
@application.route('/request_preview_switch')
def request_preview_switch():
active = request.args.get('active')
VIDEO.preview = active
print('*'*10)
print("display preview :", VIDEO.preview)
print('*'*10)
return "nothing"
@application.route('/request_background_video')
def request_background_video():
# url = "https://youtu.be/LtrtLL_8mLM" # testing url
url = request.args.get('url')
print('*'*10)
print("video url or path :", url)
print('*'*10)
VIDEO.setBackGround(url)
return "nothing"
@application.route('/request_background_switch')
def request_background_switch():
active = request.args.get('active')
VIDEO.background = active
print('*'*10, VIDEO.background)
return "nothing"
@application.route('/request_flipH_switch')
def request_flipH_switch():
active = request.args.get('active')
VIDEO.flipH = active
print('*'*10)
print("display flip :", VIDEO.flipH)
print('*'*10)
return "nothing"
@application.route('/request_model_switch')
def request_model_switch():
type = request.args.get('type')
VIDEO.detect = type
print('*'*10)
print("display type :", type)
print('*'*10)
return "nothing"
@application.route('/request_style_switch')
def request_style_switch():
type = request.args.get('type')
VIDEO.setViewStyle(type)
print('*'*10)
print("display style :", type)
print('*'*10)
return "nothing"
@application.route('/request_exposure')
def request_exposure():
value = request.args.get('value')
VIDEO.exposure = value
print('*'*10)
print("display exposure :", VIDEO.exposure)
print('*'*10)
return "nothing"
@application.route('/request_contrast')
def request_contrast():
value = request.args.get('value')
VIDEO.contrast = value
print('*'*10)
print("display contrast :",VIDEO.contrast)
print('*'*10)
return "nothing"
@application.route('/request_blur')
def request_blur():
value = request.args.get('value')
VIDEO.blur = value
print('*'*10)
print("display blur (kernel):",VIDEO.blur)
print('*'*10)
return "nothing"
@application.route('/reset_camera')
def reset_camera():
STATUS =VIDEO.initCamSettings()
active = request.args.get('active')
VIDEO.flipH = active
type = request.args.get('type')
VIDEO.detect = type
print('*'*10)
print("reset :",STATUS)
print('*'*10)
return "nothing"
if __name__ == "__main__":
DEBUG = False
while(DEBUG):
VIDEO.detect = "Basic Mode"
# VIDEO.setViewStyle("AnimeGANv2_Shinkai_fp16")
snap = next(VIDEO.show(DEBUG))
cv2.imshow("debug view", snap)
if cv2.waitKey(1)==27 : # Esc key to stop
break
else:
hostname=socket.gethostname()
IPAddr=socket.gethostbyname(hostname)
print("Your Computer Name is:"+hostname)
print("Your Computer IP Address is:"+IPAddr)
http_server = WSGIServer(('0.0.0.0', 8080), application)
print("==============================================================")
print("The server will be accessible at [ http://"+ IPAddr +":8080 ].")
print("Use Docker will be accessible at [ http://localhost:8080 ].")
print("==============================================================")
http_server.serve_forever()