Feature : * Uploading results to the server
* Uploading results to the server
@33dd35952df8d58c0634c343f9834fd74e31a0fc
--- ITS/api.py
+++ ITS/api.py
... | ... | @@ -80,7 +80,7 @@ |
80 | 80 |
# df.to_csv(f"result/pohang/listofcctv_포항_{x}_{y}.csv", index=False) |
81 | 81 |
time.sleep(1) |
82 | 82 |
print(f"{i}, {j}") |
83 |
- # all_data_df.to_csv(f"result/{xmin}_{xmax}_y{ymin}_{ymax}.csv") |
|
83 |
+ all_data_df.to_csv(f"result/{xmin}_{xmax}_y{ymin}_{ymax}.csv") |
|
84 | 84 |
return all_data_df |
85 | 85 |
|
86 | 86 |
def get_jpeg(url): |
... | ... | @@ -92,6 +92,6 @@ |
92 | 92 |
|
93 | 93 |
|
94 | 94 |
if __name__ == "__main__": |
95 |
- df = gather_cctv_list(129.2, 129.3, 35.9, 36.07, 1, "its", 1) |
|
95 |
+ df = gather_cctv_list(127.9, 128.3, 35.9, 36.07, 1, "its", 1) |
|
96 | 96 |
pass |
97 | 97 |
# get_jpeg("http://cctvsec.ktict.co.kr:8090/74236/IM2NQs4/uHZcgnvJo3V/mjo3tswwgUj87kpcYZfR/BPxaQ4lk9agnl8ARIB9lhlgOD87VBx6RDHFl423kLkqHQ==")(파일 끝에 줄바꿈 문자 없음) |
--- ITS_api_test.py
+++ ITS_api_test.py
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 |
lat = df.loc[0]["coordx"] |
9 | 9 |
lon = df.loc[0]["coordy"] |
10 | 10 |
apiKey = os.getenv("ITS_API") |
11 |
-lat_lon_interval = 0.000001 |
|
11 |
+lat_lon_interval = 0.00001 |
|
12 | 12 |
api_result = gather_cctv_list(xmin=lat-lat_lon_interval, ymin=lon-lat_lon_interval, xmax=lat+lat_lon_interval, ymax=lon+lat_lon_interval, intervals=1, roadType="its", cctvType=1) |
13 | 13 |
|
14 | 14 |
name_of_requested = api_result.loc[0]["cctvname"] |
--- config_files/cctv_list.csv
+++ config_files/cctv_list.csv
... | ... | @@ -1,3 +1,5 @@ |
1 |
-,roadsectionid,coordx,coordy,cctvresolution,filecreatetime,cctvtype,cctvformat,cctvname,cctvurl |
|
2 |
-0,,129.245312,35.920346,,,1,HLS,[국도 7호선] 모아초교,http://cctvsec.ktict.co.kr/4463/6SqphQj32sxeB2nYIMerulhkk0HdDKP/aSEgp7hHbUY9iwTDb+UQZfTbag9pXmM/yo3a7l1usm64GwBH77/SCVEel3JF3g9BZDc+ws1es2w= |
|
3 |
-1,,129.2005,35.921825,,,1,HLS,[국도20호선] 검단산업단지,http://cctvsec.ktict.co.kr/71187/bWDrL7fpStZDeDZgCybpJH8gagWJOynbaA/l91ExpmUPKzc3bCsHJtIblDkzG3TfmkwkLj7+PPdYAHSYBXxem4SZJpaAYFU0CtDtr5rz7DY=(파일 끝에 줄바꿈 문자 없음) |
|
1 |
+roadsectionid,coordx,coordy,cctvresolution,filecreatetime,cctvtype,cctvformat,cctvname,cctvurl |
|
2 |
+,129.245312,35.920346,,,1,HLS,[국도 7호선] 모아초교,http://cctvsec.ktict.co.kr/4463/6SqphQj32sxeB2nYIMerulhkk0HdDKP/aSEgp7hHbUY9iwTDb+UQZfTbag9pXmM/yo3a7l1usm64GwBH77/SCVEel3JF3g9BZDc+ws1es2w= |
|
3 |
+,129.2005,35.921825,,,1,HLS,[국도20호선] 검단산업단지,http://cctvsec.ktict.co.kr/71187/bWDrL7fpStZDeDZgCybpJH8gagWJOynbaA/l91ExpmUPKzc3bCsHJtIblDkzG3TfmkwkLj7+PPdYAHSYBXxem4SZJpaAYFU0CtDtr5rz7DY= |
|
4 |
+,128.06396,36.047108,,,1,HLS,[국도3호선] 송죽교차로,http://cctvsec.ktict.co.kr/71208/Z9Acztz6CYwzuUXQFreRR0Kdewba8Ml4CNxR0Jsp9uSCWmvL9W/BO1w2XIPxtxs9kn58qVvtHREs6vU305JaRa40F1m/P6f13gpiz9C+46M= |
|
5 |
+,128.2671,35.91457,,,1,HLS,[국도33호선] 대흥교차로,http://cctvsec.ktict.co.kr/72593/mTZfGWopuLSKGZsBABx2whdCW4FLmBl6wi4dCvp0MxMpKF6c6ydtf40G8dVXQcAGlDug1DIE/E4MVUyoa3UuD18aYxP6ZCMD5zISEiDxXTQ=(파일 끝에 줄바꿈 문자 없음) |
--- inference_endpoint.py
+++ inference_endpoint.py
... | ... | @@ -1,3 +1,5 @@ |
1 |
+import copy |
|
2 |
+ |
|
1 | 3 |
import numpy as np |
2 | 4 |
import os |
3 | 5 |
import cv2 |
... | ... | @@ -83,15 +85,15 @@ |
83 | 85 |
|
84 | 86 |
# timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") |
85 | 87 |
|
86 |
- image = self.image.read() |
|
88 |
+ self.image = self.image.read() |
|
87 | 89 |
# self.image.seek(0) |
88 |
- self.image_binary = image |
|
89 |
- image = np.frombuffer(image, np.uint8) |
|
90 |
- image = cv2.imdecode(image, cv2.IMREAD_COLOR) |
|
90 |
+ self.image_binary = copy.deepcopy(self.image) |
|
91 |
+ self.image = np.frombuffer(self.image, np.uint8) |
|
92 |
+ self.image = cv2.imdecode(self.image, cv2.IMREAD_COLOR) |
|
91 | 93 |
# filename = f"{timestamp}_{self.cctv_name}.png" |
92 | 94 |
|
93 | 95 |
t1 = time.time() |
94 |
- detections, self.mask = inference_engine.run_inference(cv2.resize(image, model_input_shape)) |
|
96 |
+ detections, self.mask = inference_engine.run_inference(cv2.resize(self.image, model_input_shape)) |
|
95 | 97 |
t2 = time.time() |
96 | 98 |
print(t2 - t1) |
97 | 99 |
|
... | ... | @@ -103,13 +105,13 @@ |
103 | 105 |
if self.flag_detected: |
104 | 106 |
print(image.shape) |
105 | 107 |
print(self.mask.shape) |
106 |
- self.mask = cv2.resize(self.mask, (image.shape[1], image.shape[0])) # cv2 saves image with w,h order |
|
108 |
+ self.mask = cv2.resize(self.mask, (self.image.shape[1], self.image.shape[0])) # cv2 saves image with w,h order |
|
107 | 109 |
self.mask = self.mask[..., np.newaxis] |
108 | 110 |
print(self.mask.shape) |
109 | 111 |
self.mask_blob = cv2.imencode('.png', self.mask) |
110 | 112 |
self.mask_blob = self.mask.tobytes() |
111 |
- self.seg_image = overlay_mask(image, self.mask[:,:,0], color=(0, 255, 0), alpha=0.3) |
|
112 |
- self.area_percent = np.sum(self.mask) / image.shape[0] * image.shape[1] |
|
113 |
+ self.seg_image = overlay_mask(self.image, self.mask[:,:,0], color=(0, 255, 0), alpha=0.3) |
|
114 |
+ self.area_percent = np.sum(self.mask) / self.image.shape[0] * self.image.shape[1] |
|
113 | 115 |
else : |
114 | 116 |
self.area_percent = 0 |
115 | 117 |
|
... | ... | @@ -131,7 +133,8 @@ |
131 | 133 |
'X-Flag-Detected' : str(self.flag_detected) #"True" or "False" |
132 | 134 |
} |
133 | 135 |
session = requests.Session() |
134 |
- |
|
136 |
+ image_binary = cv2.imencode('.png', self.image) |
|
137 |
+ image_binary = image_binary[1].tobytes() |
|
135 | 138 |
try: |
136 | 139 |
if self.flag_detected: |
137 | 140 |
seg_binary = cv2.imencode('.png', self.seg_image) |
... | ... | @@ -140,14 +143,14 @@ |
140 | 143 |
fields={ |
141 | 144 |
'image': ( |
142 | 145 |
f'frame_{self.cctv_name}.{self.image_type}', |
143 |
- self.image_binary, |
|
146 |
+ image_binary, |
|
144 | 147 |
f'image/{self.image_type}' |
145 | 148 |
), |
146 |
- 'mask' : ( |
|
147 |
- f'frame_mask_{self.cctv_name}.{self.image_type}', |
|
148 |
- self.mask_blob, |
|
149 |
- f'image/{self.image_type}' |
|
150 |
- ), |
|
149 |
+ # 'mask' : ( |
|
150 |
+ # f'frame_mask_{self.cctv_name}.{self.image_type}', |
|
151 |
+ # self.mask_blob, |
|
152 |
+ # f'image/{self.image_type}' |
|
153 |
+ # ), |
|
151 | 154 |
'seg_mask' : ( |
152 | 155 |
f'frame_seg_{self.cctv_name}.{self.image_type}', |
153 | 156 |
seg_binary, |
... | ... | @@ -163,14 +166,18 @@ |
163 | 166 |
fields={ |
164 | 167 |
'image': ( |
165 | 168 |
f'frame_{self.cctv_name}.{self.image_type}', |
166 |
- self.image_binary, |
|
169 |
+ image_binary, |
|
167 | 170 |
f'image/{self.image_type}' |
168 | 171 |
), |
169 | 172 |
} |
170 | 173 |
) |
171 | 174 |
header["Content-Type"] = multipart_data.content_type |
172 | 175 |
response = session.post(self.endpoint, headers=header, data=multipart_data) |
173 |
- print(response) |
|
176 |
+ # def print_request(req): |
|
177 |
+ # from requests_toolbelt.utils import dump |
|
178 |
+ # data = dump.dump_all(req) |
|
179 |
+ # print(data.decode('utf-8')) |
|
180 |
+ # print_request(response) |
|
174 | 181 |
|
175 | 182 |
except Exception as e: |
176 | 183 |
print(e) |
--- postprocess_draft.py
+++ postprocess_draft.py
... | ... | @@ -1,7 +1,9 @@ |
1 |
+import random |
|
2 |
+ |
|
1 | 3 |
import numpy as np |
2 | 4 |
from flask import Flask, request, jsonify |
3 | 5 |
from flask_restx import Api, Resource, fields |
4 |
-import os |
|
6 |
+import datetime |
|
5 | 7 |
import psycopg2 |
6 | 8 |
import time |
7 | 9 |
import base64 |
... | ... | @@ -97,23 +99,23 @@ |
97 | 99 |
def __call__(self): |
98 | 100 |
return self.sources |
99 | 101 |
|
100 |
- def add_status(self, source, status, cctv_info, image, seg_image): |
|
101 |
- assert status in ["OK", "FAIL"],\ |
|
102 |
- f"Invalid status was given!, status must be one of 'OK' or 'FAIL', but given '{status}'!" |
|
103 |
- |
|
102 |
+ def add_status(self, source, status, cctv_info): |
|
103 |
+ assert status in ["N", "Y"],\ |
|
104 |
+ f"Invalid status was given!, status must be one of 'N'(== 'OK') or 'Y'(==== 'Fail'), but given '{status}'!" |
|
105 |
+ |
|
104 | 106 |
if source not in self.sources: |
105 | 107 |
raise ValueError(f"No key found for source. Did you forgot to add it? \n source : {source}") |
106 | 108 |
|
107 | 109 |
flag_send_event = False |
108 | 110 |
|
109 |
- status_value = 1 if status == "OK" else 0 |
|
111 |
+ status_value = 1 if status == "N" else 0 |
|
110 | 112 |
|
111 | 113 |
self.cache_cctv_info = cctv_info |
112 | 114 |
|
113 | 115 |
self.sources[source]["status_counts"].append(status_value) |
114 | 116 |
if len(self.sources[source]["status_counts"]) > self.buffer_size: |
115 | 117 |
self.sources[source]["status_counts"].pop(0) |
116 |
- print(len(self.sources[source]["status_counts"])) |
|
118 |
+ # print(len(self.sources[source]["status_counts"])) |
|
117 | 119 |
|
118 | 120 |
if self.sources[source]["force_send_mode"]: |
119 | 121 |
seek_n_recent_memory = min(len(self.sources[source]["status_counts"]), self.failure_mode_check_past_n) |
... | ... | @@ -143,15 +145,15 @@ |
143 | 145 |
self.sources[source]["normal_to_failure_mode_change_alert"] = True |
144 | 146 |
|
145 | 147 |
# regular interval message logic |
146 |
- if self.sources[source]["last_send_before"] > self.normal_send_interval: |
|
148 |
+ if self.sources[source]["last_send_before"] >= self.normal_send_interval: |
|
147 | 149 |
flag_send_event =True |
148 | 150 |
else : |
149 | 151 |
self.sources[source]["last_send_before"] += 1 |
150 | 152 |
|
151 | 153 |
print(f"ok_counts : {self.sources[source]['ok_counts']}") |
154 |
+ print(f"last_send_before : {self.sources[source]['last_send_before']}") |
|
155 |
+ |
|
152 | 156 |
if flag_send_event: |
153 |
- self.sources[source]["most_recent_image"] = image |
|
154 |
- self.sources[source]["most_recent_seg_image"] = seg_image |
|
155 | 157 |
self.send_event(source) |
156 | 158 |
|
157 | 159 |
# alert alarms only once |
... | ... | @@ -164,57 +166,57 @@ |
164 | 166 |
def send_event(self, source): |
165 | 167 |
print(f"{source} is now sending data!") |
166 | 168 |
source_data = self.sources[source] |
167 |
- try: |
|
168 |
- # Connect to the database |
|
169 |
- conn = psycopg2.connect(**db_config) |
|
170 |
- cursor = conn.cursor() |
|
171 | 169 |
|
172 |
- # Set the search path for the schema |
|
173 |
- cursor.execute("SET search_path TO ai_camera_v0_1;") |
|
170 |
+ # Connect to the database |
|
171 |
+ conn = psycopg2.connect(**db_config) |
|
172 |
+ cursor = conn.cursor() |
|
174 | 173 |
|
175 |
- # Prepare the SQL query |
|
176 |
- insert_sql = """ |
|
177 |
- INSERT INTO flooding_detect_event ( |
|
178 |
- ocrn_dt, |
|
179 |
- eqpmn_nm, |
|
180 |
- flooding_result, |
|
181 |
- flooding_per, |
|
182 |
- image, |
|
183 |
- image_seg, |
|
184 |
- eqpmn_lat, |
|
185 |
- eqpmn_lon, |
|
186 |
- norm_to_alert_flag, |
|
187 |
- alert_to_norm_flag |
|
188 |
- ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s); |
|
189 |
- """ |
|
174 |
+ # Set the search path for the schema |
|
175 |
+ cursor.execute("SET search_path TO ai_camera_v0_1;") |
|
190 | 176 |
|
191 |
- # Prepare data to insert |
|
192 |
- data_tuple = ( |
|
193 |
- time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(source_data["last_send_before"])), |
|
194 |
- source_data["cctv_info"]["cctv_name"], |
|
195 |
- "FAIL" if source_data["failure_counts"] >= self.failure_mode_thres else "OK", |
|
196 |
- source_data["cctv_info"]["area_percent"], |
|
197 |
- source_data["most_recent_image"], |
|
198 |
- source_data["most_recent_seg_image"], |
|
199 |
- source_data["cctv_info"]["cctv_latitude"], |
|
200 |
- source_data["cctv_info"]["cctv_longitude"], |
|
201 |
- source_data["normal_to_failure_mode_change_alert"], |
|
202 |
- source_data["failure_to_normal_mode_change_alert"] |
|
203 |
- ) |
|
177 |
+ # Prepare the SQL query |
|
178 |
+ insert_sql = """ |
|
179 |
+ INSERT INTO flooding_detect_event ( |
|
180 |
+ ocrn_dt, |
|
181 |
+ eqpmn_nm, |
|
182 |
+ flooding_result, |
|
183 |
+ flooding_per, |
|
184 |
+ image, |
|
185 |
+ image_seg, |
|
186 |
+ eqpmn_lat, |
|
187 |
+ eqpmn_lon, |
|
188 |
+ norm_to_alert_flag, |
|
189 |
+ alert_to_norm_flag |
|
190 |
+ ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s); |
|
191 |
+ """ |
|
192 |
+ # Prepare data to insert |
|
193 |
+ print(self.cache_cctv_info["time_sent"]) |
|
194 |
+ data_tuple = ( |
|
195 |
+ self.cache_cctv_info["time_sent"], |
|
196 |
+ source_data["cctv_info"]["cctv_name"], |
|
197 |
+ self.cache_cctv_info["detected"], |
|
198 |
+ self.cache_cctv_info["area_percent"], |
|
199 |
+ self.cache_cctv_info["source_frame"], |
|
200 |
+ self.cache_cctv_info["seg_frame"], |
|
201 |
+ source_data["cctv_info"]["cctv_latitude"], |
|
202 |
+ source_data["cctv_info"]["cctv_longitude"], |
|
203 |
+ "Y" if source_data["normal_to_failure_mode_change_alert"] else "N", |
|
204 |
+ "Y" if source_data["failure_to_normal_mode_change_alert"] else "N", |
|
205 |
+ ) |
|
206 |
+ # print(hash(self.cache_cctv_info["source_frame"])) |
|
207 |
+ # print(self.cache_cctv_info["source_frame"][:100]) |
|
208 |
+ # print(self.cache_cctv_info["source_frame"][-100:]) |
|
204 | 209 |
|
205 |
- # Execute the query |
|
206 |
- cursor.execute(insert_sql, data_tuple) |
|
207 |
- conn.commit() |
|
210 |
+ # Execute the query |
|
211 |
+ cursor.execute(insert_sql, data_tuple) |
|
212 |
+ conn.commit() |
|
208 | 213 |
|
209 |
- print(f"EVENT: Sent for {source} - Data inserted successfully.") |
|
214 |
+ print(f"EVENT: Sent for {source} - Data inserted successfully.") |
|
210 | 215 |
|
211 |
- except Exception as e: |
|
212 |
- print(f"Database operation failed: {e}") |
|
213 |
- finally: |
|
214 |
- if cursor: |
|
215 |
- cursor.close() |
|
216 |
- if conn: |
|
217 |
- conn.close() |
|
216 |
+ if cursor: |
|
217 |
+ cursor.close() |
|
218 |
+ if conn: |
|
219 |
+ conn.close() |
|
218 | 220 |
|
219 | 221 |
# Reset the image data after sending to avoid re-sending the same image |
220 | 222 |
source_data["most_recent_image"] = None |
... | ... | @@ -224,7 +226,7 @@ |
224 | 226 |
|
225 | 227 |
memory = StreamSources( |
226 | 228 |
buffer_size=15, |
227 |
- normal_send_interval=10, |
|
229 |
+ normal_send_interval=1, |
|
228 | 230 |
failure_mode_thres=8, |
229 | 231 |
failure_mode_check_past_n=12, |
230 | 232 |
normal_mode_thres=8, |
... | ... | @@ -237,7 +239,7 @@ |
237 | 239 |
image = cv2.imdecode(image, cv2.IMREAD_COLOR) |
238 | 240 |
_, image = cv2.imencode('.jpg', image) |
239 | 241 |
image = image.tobytes() |
240 |
- image = base64.b64encode(image) |
|
242 |
+ image = base64.b64encode(image).decode('utf-8') |
|
241 | 243 |
return image |
242 | 244 |
|
243 | 245 |
|
... | ... | @@ -262,53 +264,58 @@ |
262 | 264 |
@ns.response(200, 'Success') |
263 | 265 |
@ns.response(400, 'Validation Error') |
264 | 266 |
def post(self): |
267 |
+ # try: |
|
268 |
+ # Gathering values |
|
269 |
+ self.image_type = request.headers.get('Content-Type') |
|
270 |
+ self.cctv_name = base64.b64decode(request.headers.get('x-cctv-name', '')).decode('UTF-8') |
|
271 |
+ self.time_sent = request.headers.get('x-time-sent', '') |
|
272 |
+ self.time_sent = datetime.datetime.strptime(self.time_sent, '%Y-%m-%dT%H:%M:%SZ') |
|
273 |
+ # self.time_sent = self.time_sent.timestamp() |
|
274 |
+ self.cctv_latitude = request.headers.get('x-cctv-latitude', 'Not provided') |
|
275 |
+ self.cctv_longitude = request.headers.get('x-cctv-longitude', 'Not provided') |
|
276 |
+ self.detected = request.headers.get('X-Flag-Detected') |
|
277 |
+ |
|
278 |
+ if self.detected == "True": |
|
279 |
+ self.detected = True |
|
280 |
+ elif self.detected == "False": |
|
281 |
+ self.detected = False |
|
282 |
+ else: |
|
283 |
+ raise ValueError(f"Invalid value for x-flag-detected: {self.detected}") |
|
284 |
+ |
|
285 |
+ self.area_percent = request.headers.get('x-area-percentage') |
|
265 | 286 |
try: |
266 |
- # Gathering values |
|
267 |
- self.image_type = request.headers.get('Content-Type') |
|
268 |
- self.cctv_name = base64.b64decode(request.headers.get('x-cctv-name', '')).decode('UTF-8') |
|
269 |
- self.time_sent = request.headers.get('x-time-sent', '') |
|
270 |
- self.cctv_latitude = request.headers.get('x-cctv-latitude', 'Not provided') |
|
271 |
- self.cctv_longitude = request.headers.get('x-cctv-longitude', 'Not provided') |
|
272 |
- self.detected = request.headers.get('X-Flag-Detected') |
|
287 |
+ self.area_percent = float(self.area_percent) |
|
288 |
+ except (TypeError, ValueError) as e: |
|
289 |
+ raise ValueError(f"Invalid value for x-area-percentage: {self.area_percent}") |
|
273 | 290 |
|
274 |
- if self.detected == "True": |
|
275 |
- self.detected = True |
|
276 |
- elif self.detected == "False": |
|
277 |
- self.detected = False |
|
278 |
- else: |
|
279 |
- raise ValueError(f"Invalid value for x-flag-detected: {self.detected}") |
|
291 |
+ # gathering files |
|
292 |
+ try: |
|
293 |
+ self.image = request.files['image'].read() |
|
294 |
+ except: |
|
295 |
+ raise ValueError("Error reading 'image!'") |
|
280 | 296 |
|
281 |
- self.area_percent = request.headers.get('x-area-percentage') |
|
297 |
+ |
|
298 |
+ if self.detected: |
|
282 | 299 |
try: |
283 |
- self.area_percent = float(self.area_percent) |
|
284 |
- except (TypeError, ValueError) as e: |
|
285 |
- raise ValueError(f"Invalid value for x-area-percentage: {self.area_percent}") |
|
286 |
- |
|
287 |
- # gathering files |
|
288 |
- try: |
|
289 |
- self.image = request.files.get('image') |
|
300 |
+ self.mask = request.files['mask'].read() |
|
301 |
+ self.seg_image = request.files['seg_image'].read() |
|
290 | 302 |
except: |
291 |
- raise ValueError("Error reading 'image!'") |
|
303 |
+ raise ValueError("Error reading 'mask' and 'seg_mask'") |
|
292 | 304 |
|
293 |
- if self.detected: |
|
294 |
- try: |
|
295 |
- self.mask = request.files.get('mask') |
|
296 |
- self.seg_image = request.files.get('seg_mask') |
|
297 |
- except: |
|
298 |
- raise ValueError("Error reading 'mask' and 'seg_mask'") |
|
305 |
+ if debug: |
|
306 |
+ pass |
|
307 |
+ # self.image.save(f"network_test/image_p{time.time()}.png") |
|
308 |
+ # if self.detected : |
|
309 |
+ # self.mask.save(f"network_test/mask_p{time.time()}.png") |
|
310 |
+ # self.seg_image.save(f"network_test/seg_p{time.time()}.png") |
|
299 | 311 |
|
312 |
+ image_b64 = get_base64_encoded_image_from_file_binary(self.image) |
|
313 |
+ if self.detected: |
|
314 |
+ seg_image_b64 = get_base64_encoded_image_from_file_binary(self.seg_image) |
|
300 | 315 |
|
301 |
- if debug: |
|
302 |
- self.image.save(f"network_test/image_p{time.time()}.png") |
|
303 |
- if self.detected : |
|
304 |
- self.mask.save(f"network_test/mask_p{time.time()}.png") |
|
305 |
- self.seg_image.save(f"network_test/seg_p{time.time()}.png") |
|
316 |
+ pass_fail = self.pass_fail() |
|
306 | 317 |
|
307 |
- image_b64 = get_base64_encoded_image_from_file_binary(self.image) |
|
308 |
- seg_image_b64 = get_base64_encoded_image_from_file_binary(self.seg_image.read()) |
|
309 |
- |
|
310 |
- self.time_sent = time.time() |
|
311 |
- |
|
318 |
+ if self.detected: |
|
312 | 319 |
self.cctv_info = { |
313 | 320 |
'cctv_name': self.cctv_name, |
314 | 321 |
'cctv_latitude': self.cctv_latitude, |
... | ... | @@ -316,32 +323,51 @@ |
316 | 323 |
'source_frame': image_b64, |
317 | 324 |
# 'frame_mask': self.mask, |
318 | 325 |
'seg_frame': seg_image_b64, |
319 |
- 'time_sent': self.time_sent |
|
326 |
+ 'time_sent': self.time_sent, |
|
327 |
+ 'area_percent' : self.area_percent, |
|
328 |
+ 'detected' : pass_fail |
|
320 | 329 |
} |
321 |
- # if self.cctv_name in memory: |
|
322 |
- try : |
|
323 |
- memory[self.cctv_info['cctv_name']] = self.cctv_info |
|
324 |
- except : |
|
325 |
- pass |
|
326 |
- pass_fail = self.pass_fail() |
|
330 |
+ else : |
|
331 |
+ self.cctv_info = { |
|
332 |
+ 'cctv_name': self.cctv_name, |
|
333 |
+ 'cctv_latitude': self.cctv_latitude, |
|
334 |
+ 'cctv_longitude': self.cctv_longitude, |
|
335 |
+ 'source_frame': image_b64, |
|
336 |
+ # 'frame_mask': self.mask, |
|
337 |
+ 'seg_frame': None, |
|
338 |
+ 'time_sent': self.time_sent, |
|
339 |
+ 'area_percent': self.area_percent, |
|
340 |
+ 'detected': pass_fail |
|
341 |
+ } |
|
342 |
+ # if self.cctv_name in memory: |
|
327 | 343 |
|
328 |
- memory.add_status(self.cctv_name, pass_fail, self.cctv_info, image_b64, seg_image_b64) |
|
344 |
+ try : |
|
345 |
+ memory[self.cctv_info['cctv_name']] = self.cctv_info |
|
346 |
+ except: |
|
347 |
+ pass |
|
329 | 348 |
|
330 |
- if debug: |
|
331 |
- print(memory()) |
|
349 |
+ if self.detected: |
|
350 |
+ memory.add_status(self.cctv_name, pass_fail, self.cctv_info) |
|
351 |
+ else : |
|
352 |
+ memory.add_status(self.cctv_name, pass_fail, self.cctv_info) |
|
332 | 353 |
|
333 |
- except ValueError as e: |
|
334 |
- print(e) |
|
335 |
- except Exception as e: |
|
336 |
- print(e) |
|
354 |
+ # if debug: |
|
355 |
+ # print(memory()) |
|
356 |
+ # |
|
357 |
+ # except ValueError as e: |
|
358 |
+ # print(e) |
|
359 |
+ # except Exception as e: |
|
360 |
+ # print(e) |
|
337 | 361 |
|
338 | 362 |
def pass_fail(self): |
339 | 363 |
thres = 0.1 |
340 | 364 |
#TODO temporal pass_fail threshold |
341 | 365 |
if self.area_percent > thres: |
342 |
- ret = 'FAIL' |
|
366 |
+ # ret = 'FAIL' |
|
367 |
+ ret = 'Y' |
|
343 | 368 |
else: |
344 |
- ret = 'OK' |
|
369 |
+ # ret = 'OK' |
|
370 |
+ ret = 'N' |
|
345 | 371 |
return ret |
346 | 372 |
|
347 | 373 |
|
--- streaming_url_updator.py
+++ streaming_url_updator.py
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 |
from flask_cors import CORS |
10 | 10 |
from apscheduler.schedulers.background import BackgroundScheduler |
11 | 11 |
from apscheduler.triggers.interval import IntervalTrigger |
12 |
-from requests_toolbelt.utils import dump |
|
12 |
+ |
|
13 | 13 |
|
14 | 14 |
API_ENDPOINT = "http://165.229.169.148:8080/EquipmentUrlChanger.json" |
15 | 15 |
|
... | ... | @@ -26,6 +26,7 @@ |
26 | 26 |
|
27 | 27 |
|
28 | 28 |
def print_request(req): |
29 |
+ from requests_toolbelt.utils import dump |
|
29 | 30 |
data = dump.dump_all(req) |
30 | 31 |
print(data.decode('utf-8')) |
31 | 32 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?