diff --git a/backend/cameras.py.template b/backend/cameras.py.template index c44cdae451b38fcee50fedd3776f855381241db7..5d197e572134b2e9d63518bcbcd5a227ee42bde0 100644 --- a/backend/cameras.py.template +++ b/backend/cameras.py.template @@ -21,6 +21,21 @@ restaurants = [ [450, 550], [130, 350] ] + ], + "caisses": + [ + { + "x1": 380, + "x2": 435, + "y1": 740, + "y2": 780 + }, + { + "x1": 300, + "x2": 350, + "y1": 830, + "y2": 880 + } ] } ] diff --git a/backend/video_capture.py b/backend/video_capture.py index c83c95dc684675daebe78d33e0d38d372de3f504..6de64c677002651378f6f13298137373ba765fca 100644 --- a/backend/video_capture.py +++ b/backend/video_capture.py @@ -25,7 +25,6 @@ async def handle_cameras(): start_timestamp = time.time() current_date = datetime.fromtimestamp(start_timestamp) - print(current_date) weekday, current_time = current_date.weekday(), current_date.time() for restaurant in restaurants: @@ -39,11 +38,12 @@ async def handle_cameras(): if is_open: count_prediction = 0 + open_checkouts = 0 cams_working = True for camera in restaurant["cameras"]: cap = cv2.VideoCapture(f'rtsp://{camera["user"]}:{camera["password"]}@{camera["IP"]}/{camera["stream"]}') - if cap.isOpened(): + if cams_working and cap.isOpened(): _, frame = cap.read() masked_img = cv2.bitwise_and( frame.astype(np.float32), camera["mask"]) @@ -54,8 +54,13 @@ async def handle_cameras(): np.array( [treated_img]))), axis=0) - pred_map = np.squeeze(model.predict(input_image)) + pre_pred=time.time() + pred_map = np.squeeze(model.predict(input_image, verbose=0)) + print(time.time()-pre_pred) count_prediction += np.sum(pred_map) + for caisse in camera["caisses"]: + if np.sum(pred_map[caisse["x1"]//2:caisse["x2"]//2, caisse["y1"]//2:caisse["y2"]//2]) > 0.5: + open_checkouts += 1 else: cams_working = False cap.release() @@ -64,7 +69,7 @@ async def handle_cameras(): waiting_time = timedelta( seconds=restaurant['b_factor'] + int(count_prediction * - restaurant['a_factor'])) + restaurant['a_factor'] / max(open_checkouts, 1))) db_record = models.Records( place=restaurant['restaurant'], date=current_date, @@ -73,5 +78,4 @@ async def handle_cameras(): db.add(db_record) db.commit() await manager.broadcast(json.dumps({"type": "data"})) - print("owarida") time.sleep(60 - time.time() + start_timestamp)