mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
wait 5 seconds to clear the motion flag
This commit is contained in:
parent
c12e19349e
commit
de9c3f4d74
@ -12,11 +12,21 @@ def detect_motion(shared_arr, shared_frame_time, frame_lock, frame_ready, motion
|
|||||||
|
|
||||||
avg_frame = None
|
avg_frame = None
|
||||||
avg_delta = None
|
avg_delta = None
|
||||||
|
last_motion = -1
|
||||||
frame_time = 0.0
|
frame_time = 0.0
|
||||||
motion_frames = 0
|
motion_frames = 0
|
||||||
while True:
|
while True:
|
||||||
now = datetime.datetime.now().timestamp()
|
now = datetime.datetime.now().timestamp()
|
||||||
|
|
||||||
|
# if it has been long enough since the last motion, clear the flag
|
||||||
|
if last_motion > 0 and (now - last_motion) > 5:
|
||||||
|
last_motion = -1
|
||||||
|
if motion_detected.is_set():
|
||||||
|
motion_detected.clear()
|
||||||
|
with motion_changed:
|
||||||
|
motion_changed.notify_all()
|
||||||
|
|
||||||
|
|
||||||
with frame_ready:
|
with frame_ready:
|
||||||
# if there isnt a frame ready for processing or it is old, wait for a signal
|
# if there isnt a frame ready for processing or it is old, wait for a signal
|
||||||
if shared_frame_time.value == frame_time or (now - shared_frame_time.value) > 0.5:
|
if shared_frame_time.value == frame_time or (now - shared_frame_time.value) > 0.5:
|
||||||
@ -95,14 +105,11 @@ def detect_motion(shared_arr, shared_frame_time, frame_lock, frame_ready, motion
|
|||||||
motion_detected.set()
|
motion_detected.set()
|
||||||
with motion_changed:
|
with motion_changed:
|
||||||
motion_changed.notify_all()
|
motion_changed.notify_all()
|
||||||
|
last_motion = now
|
||||||
else:
|
else:
|
||||||
# when no motion, just keep averaging the frames together
|
# when no motion, just keep averaging the frames together
|
||||||
cv2.accumulateWeighted(gray, avg_frame, 0.01)
|
cv2.accumulateWeighted(gray, avg_frame, 0.01)
|
||||||
motion_frames = 0
|
motion_frames = 0
|
||||||
if motion_detected.is_set():
|
|
||||||
motion_detected.clear()
|
|
||||||
with motion_changed:
|
|
||||||
motion_changed.notify_all()
|
|
||||||
|
|
||||||
if debug and motion_frames == 3:
|
if debug and motion_frames == 3:
|
||||||
cv2.imwrite("/lab/debug/motion-{}-{}-{}.jpg".format(region_x_offset, region_y_offset, datetime.datetime.now().timestamp()), cropped_frame)
|
cv2.imwrite("/lab/debug/motion-{}-{}-{}.jpg".format(region_x_offset, region_y_offset, datetime.datetime.now().timestamp()), cropped_frame)
|
||||||
|
Loading…
Reference in New Issue
Block a user