@@ -32,7 +32,9 @@ def create_background_subtractor() -> cv2.BackgroundSubtractor:
3232 True
3333 """
3434 # history=500, varThreshold=16 are common defaults; detectShadows adds robustness
35- return cv2 .createBackgroundSubtractorMOG2 (history = 500 , varThreshold = 16 , detectShadows = True )
35+ return cv2 .createBackgroundSubtractorMOG2 (
36+ history = 500 , varThreshold = 16 , detectShadows = True
37+ )
3638
3739
3840def preprocess_frame (frame : cv2 .Mat ) -> cv2 .Mat :
@@ -73,7 +75,9 @@ def frame_difference(prev_gray: cv2.Mat, curr_gray: cv2.Mat) -> cv2.Mat:
7375 return closed
7476
7577
76- def background_subtraction_mask (subtractor : cv2 .BackgroundSubtractor , frame : cv2 .Mat ) -> cv2 .Mat :
78+ def background_subtraction_mask (
79+ subtractor : cv2 .BackgroundSubtractor , frame : cv2 .Mat
80+ ) -> cv2 .Mat :
7781 """
7882 Apply background subtraction to obtain a motion mask. Includes morphology.
7983
@@ -107,7 +111,9 @@ def annotate_motion(frame: cv2.Mat, motion_mask: cv2.Mat) -> cv2.Mat:
107111 >>> np.any(annotated[..., 1] == 255) # green channel from rectangle
108112 True
109113 """
110- contours , _ = cv2 .findContours (motion_mask , cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_SIMPLE )
114+ contours , _ = cv2 .findContours (
115+ motion_mask , cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_SIMPLE
116+ )
111117 annotated = frame .copy ()
112118 for contour in contours :
113119 if cv2 .contourArea (contour ) < MIN_CONTOUR_AREA :
@@ -182,5 +188,3 @@ def main() -> None:
182188if __name__ == "__main__" :
183189 main ()
184190 print ("DONE ✅" )
185-
186-
0 commit comments