@@ -27,7 +27,9 @@ def create_background_subtractor() -> cv2.BackgroundSubtractor:
2727 Create and return a MOG2 background subtractor with sensible defaults.
2828 """
2929 # history=500, varThreshold=16 are common defaults; detectShadows adds robustness
30- return cv2 .createBackgroundSubtractorMOG2 (history = 500 , varThreshold = 16 , detectShadows = True )
30+ return cv2 .createBackgroundSubtractorMOG2 (
31+ history = 500 , varThreshold = 16 , detectShadows = True
32+ )
3133
3234
3335def preprocess_frame (frame : cv2 .Mat ) -> cv2 .Mat :
@@ -52,7 +54,9 @@ def frame_difference(prev_gray: cv2.Mat, curr_gray: cv2.Mat) -> cv2.Mat:
5254 return closed
5355
5456
55- def background_subtraction_mask (subtractor : cv2 .BackgroundSubtractor , frame : cv2 .Mat ) -> cv2 .Mat :
57+ def background_subtraction_mask (
58+ subtractor : cv2 .BackgroundSubtractor , frame : cv2 .Mat
59+ ) -> cv2 .Mat :
5660 """
5761 Apply background subtraction to obtain a motion mask. Includes morphology.
5862 """
@@ -69,7 +73,9 @@ def annotate_motion(frame: cv2.Mat, motion_mask: cv2.Mat) -> cv2.Mat:
6973 """
7074 Find contours on the motion mask and draw bounding boxes on the frame.
7175 """
72- contours , _ = cv2 .findContours (motion_mask , cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_SIMPLE )
76+ contours , _ = cv2 .findContours (
77+ motion_mask , cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_SIMPLE
78+ )
7379 annotated = frame .copy ()
7480 for contour in contours :
7581 if cv2 .contourArea (contour ) < MIN_CONTOUR_AREA :
@@ -131,5 +137,3 @@ def main() -> None:
131137if __name__ == "__main__" :
132138 main ()
133139 print ("DONE ✅" )
134-
135-
0 commit comments