Implementing the main function

Now that we have a Pedestrian class to maintain data about the tracking of each pedestrian, let's implement our program's main function. We will look at the parts of the implementation sequentially:

  1. We begin by loading a video file, initializing a background subtractor, and setting the background subtractor's history length (that is, the number of frames affecting the background model):
def main():    cap = cv2.VideoCapture('pedestrians.avi')    # Create the KNN background subtractor.    bg_subtractor = cv2.createBackgroundSubtractorKNN()    history_length = 20    bg_subtractor.setHistory(history_length)
  1. Then, we define morphology kernels:
erode_kernel = cv2.getStructuringElement(    cv2.MORPH_ELLIPSE, (3, 3))dilate_kernel ...

Get Learning OpenCV 4 Computer Vision with Python 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.