@@ -31,7 +31,9 @@ def create_background_subtractor() -> cv2.BackgroundSubtractor:
3131 True
3232 """
3333 # history=500, varThreshold=16 are common defaults; detectShadows adds robustness
34- return cv2 .createBackgroundSubtractorMOG2 (history = 500 , varThreshold = 16 , detectShadows = True )
34+ return cv2 .createBackgroundSubtractorMOG2 (
35+ history = 500 , varThreshold = 16 , detectShadows = True
36+ )
3537
3638
3739def preprocess_frame (frame : cv2 .Mat ) -> cv2 .Mat :
@@ -72,7 +74,9 @@ def frame_difference(prev_gray: cv2.Mat, curr_gray: cv2.Mat) -> cv2.Mat:
7274 return closed
7375
7476
75- def background_subtraction_mask (subtractor : cv2 .BackgroundSubtractor , frame : cv2 .Mat ) -> cv2 .Mat :
77+ def background_subtraction_mask (
78+ subtractor : cv2 .BackgroundSubtractor , frame : cv2 .Mat
79+ ) -> cv2 .Mat :
7680 """
7781 Apply background subtraction to obtain a motion mask. Includes morphology.
7882
@@ -106,7 +110,9 @@ def annotate_motion(frame: cv2.Mat, motion_mask: cv2.Mat) -> cv2.Mat:
106110 >>> np.any(annotated[..., 1] == 255) # green channel from rectangle
107111 True
108112 """
109- contours , _ = cv2 .findContours (motion_mask , cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_SIMPLE )
113+ contours , _ = cv2 .findContours (
114+ motion_mask , cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_SIMPLE
115+ )
110116 annotated = frame .copy ()
111117 for contour in contours :
112118 if cv2 .contourArea (contour ) < MIN_CONTOUR_AREA :
@@ -181,5 +187,3 @@ def main() -> None:
181187if __name__ == "__main__" :
182188 main ()
183189 print ("DONE ✅" )
184-
185-
0 commit comments