This project tracks the trajectory of a Ball using OpenCV. A part of my Pyimagesearch 17 days into the deep learning program, this code tracks the trajectory of the ball.
In this project we performed ball tracking with OpenCV. The Python script was able to do the following
- Detect the presence of the colored ball.
- Track and draw the position of the ball as it moved around the screen.
The system was quite robust and able to track the ball even if it was partially occluded from view by the hand holding it. It is seen that the program runs more optimally, if there isn't any other object similar to the color of the ball in framde.
The script was also able to operate at an extremely high frame rate (> 32 FPS), indicating that color based tracking methods are very much suitable for real-time detection and tracking. The script works for both:
- A prerecorded video file.
- Webcam Footage
and both with equal precision.
python ball_detector.py --video ball_me.mp4
python ball_detector.py --video ball_adrian.mp4
python ball_detector.py //for webcam footage
from collections import deque
from imutils.video import VideoStream
import numpy as np
import argparse
import cv2
import imutils
import time