February 2020
Intermediate to advanced
372 pages
9h 26m
English
By modifying just five lines of code in our MOG background subtraction script, we can use a different background subtraction algorithm, different morphology parameters, and a different video as input. Thanks to the high-level interface that OpenCV provides, even such simple changes enable us to successfully handle a wide variety of background subtraction tasks.
Just by replacing cv2.createBackgroundSubtractorMOG2 with cv2.createBackgroundSubtractorKNN, we can we use a background subtractor based on KNN clustering instead of MOG clustering:
bg_subtractor = cv2.createBackgroundSubtractorKNN(detectShadows=True)
Note that despite the change in algorithm, the detectShadows parameter is still supported. Additionally, ...