Tracking pedestrians
Up to this point, we have familiarized ourselves with the concepts of motion detection, object detection, and object tracking. You are probably anxious to put this newfound knowledge to good use in a real-life scenario. Let's do just that by tracking pedestrians in a video from a surveillance camera.
You can find a surveillance video inside the OpenCV repository at
samples/data/vtest.avi
. A copy of this video is located inside this book's GitHub repository atvidoesvidoes/pedestrians.avi
.
Let's lay out a plan and then implement the application!
Planning the flow of the application
The application will adhere to the following logic:
- Capture frames from a video file.
- Use the first 20 frames to populate the history of a background subtractor.
- Based on background subtraction, use the 21st frame to identify moving foreground objects. We will treat these as pedestrians. For each pedestrian, assign an ID and an initial tracking window, and then calculate...