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

allow checkouts detection

parent 5479c5dd
No related branches found
No related tags found
1 merge request!49improve cameras
......@@ -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
}
]
}
]
......
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment