Don't spam notifications
This commit is contained in:
parent
ea4009c898
commit
9fb5818322
|
@ -132,6 +132,7 @@ def main():
|
||||||
"last_detection_time": None,
|
"last_detection_time": None,
|
||||||
"detection_duration": None,
|
"detection_duration": None,
|
||||||
# "first_detection_time": None,
|
# "first_detection_time": None,
|
||||||
|
"last_notification_time": None,
|
||||||
}
|
}
|
||||||
for box in r.boxes:
|
for box in r.boxes:
|
||||||
# Get the name of the object
|
# Get the name of the object
|
||||||
|
@ -158,7 +159,7 @@ def main():
|
||||||
or time.time() - object_names[class_id]["last_detection_time"] > 15
|
or time.time() - object_names[class_id]["last_detection_time"] > 15
|
||||||
or object_names[class_id]["detection_duration"] is None
|
or object_names[class_id]["detection_duration"] is None
|
||||||
):
|
):
|
||||||
print(f"First detection of {class_id}")
|
print(f"First detection of {class_id} in session")
|
||||||
# time.time() returns the number of seconds since the epoch
|
# time.time() returns the number of seconds since the epoch
|
||||||
object_names[class_id]["last_detection_time"] = time.time()
|
object_names[class_id]["last_detection_time"] = time.time()
|
||||||
# object_names[class_id]["first_detection_time"] = time.time()
|
# object_names[class_id]["first_detection_time"] = time.time()
|
||||||
|
@ -184,6 +185,9 @@ def main():
|
||||||
and time.time() - object_names[class_id]["last_detection_time"]
|
and time.time() - object_names[class_id]["last_detection_time"]
|
||||||
<= 15
|
<= 15
|
||||||
):
|
):
|
||||||
|
# If the last notification was more than 15 seconds ago, then send a notification
|
||||||
|
if object_names[class_id]["last_notification_time"] is None or time.time() - object_names[class_id]["last_notification_time"] > 15:
|
||||||
|
object_names[class_id]["last_notification_time"] = time.time()
|
||||||
print(f"Detected {class_id} for 2 seconds")
|
print(f"Detected {class_id} for 2 seconds")
|
||||||
headers = notify.construct_ntfy_headers(
|
headers = notify.construct_ntfy_headers(
|
||||||
title=f"{class_id} Detected",
|
title=f"{class_id} Detected",
|
||||||
|
@ -193,6 +197,8 @@ def main():
|
||||||
notify.send_notification(
|
notify.send_notification(
|
||||||
data=f"{class_id} Detected", headers=headers, url=args.ntfy_url
|
data=f"{class_id} Detected", headers=headers, url=args.ntfy_url
|
||||||
)
|
)
|
||||||
|
# Reset the detection duration
|
||||||
|
object_names[class_id]["detection_duration"] = 0
|
||||||
im_array = r.plot()
|
im_array = r.plot()
|
||||||
# Scale back up the coordinates of the locations of detected objects.
|
# Scale back up the coordinates of the locations of detected objects.
|
||||||
# im_array = np.multiply(im_array, 1/args.run_scale)
|
# im_array = np.multiply(im_array, 1/args.run_scale)
|
||||||
|
|
Loading…
Reference in New Issue