1 | initial version |
please do not use threads to implement "state logic", you don't need this, and it's a terrible idea.
also, NEVER share data between threads (w/o locks) (esp. VideoCapture is NOT thread-safe), and NEVER have global
variables in your program
all you need here, is a timer, not a seperate thread, you could use recording
to keep the time like:
recording = 0 # not recording
in your contours loop:
if area > 1000 and recording == 0:
out = cv2.VideoWriter(path, fcc, fps, (width, height))
recording = time.time() # start timer
then, later:
if recording > 0:
out.write(frame)
if time.time() - recording >= 10: # 10 seconds have passed
recording = 0 # reset timer
out.release()