Well, to begin with, I should admit that it is a pretty long question and I failed to find possible solutions through googling
I have a video in which an intruder tr
adding cv2.waitKey(0) will pause your while loop indefinitely! It will resume only after any key press.
I think what you're trying to achieve is object tracking using Background Subtraction. Refer Here and see if it fits your requirements.
EDIT:
I guess you want to draw a freehand shape for intrusion area! This Link will guide you to do it. I hope this helps