Skip to content
Snippets Groups Projects
Commit d8cec90f authored by Aymeric Chaumont's avatar Aymeric Chaumont
Browse files

allow checkouts detection

parent c6ac6171
Branches
No related tags found
1 merge request!49improve cameras
...@@ -21,6 +21,21 @@ restaurants = [ ...@@ -21,6 +21,21 @@ restaurants = [
[450, 550], [450, 550],
[130, 350] [130, 350]
] ]
],
"caisses":
[
{
"x1": 380,
"x2": 435,
"y1": 740,
"y2": 780
},
{
"x1": 300,
"x2": 350,
"y1": 830,
"y2": 880
}
] ]
} }
] ]
......
...@@ -25,7 +25,6 @@ async def handle_cameras(): ...@@ -25,7 +25,6 @@ async def handle_cameras():
start_timestamp = time.time() start_timestamp = time.time()
current_date = datetime.fromtimestamp(start_timestamp) current_date = datetime.fromtimestamp(start_timestamp)
print(current_date)
weekday, current_time = current_date.weekday(), current_date.time() weekday, current_time = current_date.weekday(), current_date.time()
for restaurant in restaurants: for restaurant in restaurants:
...@@ -39,11 +38,12 @@ async def handle_cameras(): ...@@ -39,11 +38,12 @@ async def handle_cameras():
if is_open: if is_open:
count_prediction = 0 count_prediction = 0
open_checkouts = 0
cams_working = True cams_working = True
for camera in restaurant["cameras"]: for camera in restaurant["cameras"]:
cap = cv2.VideoCapture(f'rtsp://{camera["user"]}:{camera["password"]}@{camera["IP"]}/{camera["stream"]}') 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() _, frame = cap.read()
masked_img = cv2.bitwise_and( masked_img = cv2.bitwise_and(
frame.astype(np.float32), camera["mask"]) frame.astype(np.float32), camera["mask"])
...@@ -54,8 +54,13 @@ async def handle_cameras(): ...@@ -54,8 +54,13 @@ async def handle_cameras():
np.array( np.array(
[treated_img]))), [treated_img]))),
axis=0) 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) 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: else:
cams_working = False cams_working = False
cap.release() cap.release()
...@@ -64,7 +69,7 @@ async def handle_cameras(): ...@@ -64,7 +69,7 @@ async def handle_cameras():
waiting_time = timedelta( waiting_time = timedelta(
seconds=restaurant['b_factor'] + seconds=restaurant['b_factor'] +
int(count_prediction * int(count_prediction *
restaurant['a_factor'])) restaurant['a_factor'] / max(open_checkouts, 1)))
db_record = models.Records( db_record = models.Records(
place=restaurant['restaurant'], place=restaurant['restaurant'],
date=current_date, date=current_date,
...@@ -73,5 +78,4 @@ async def handle_cameras(): ...@@ -73,5 +78,4 @@ async def handle_cameras():
db.add(db_record) db.add(db_record)
db.commit() db.commit()
await manager.broadcast(json.dumps({"type": "data"})) await manager.broadcast(json.dumps({"type": "data"}))
print("owarida")
time.sleep(60 - time.time() + start_timestamp) time.sleep(60 - time.time() + start_timestamp)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment