mopaberry.blogg.se

Red white and blue bouncing balls
Red white and blue bouncing balls






This deque allows us to draw the “contrail” of the ball, detailing its past locations. If this your first time running this script, I suggest using the -video switch to start: this will demonstrate the functionality of the Python script to you, then you can modify the script, video file, and webcam access to your liking.Ī second optional argument, -buffer is the maximum size of our deque, which maintains a list of the previous (x, y)-coordinates of the ball we are tracking. Otherwise, if this switch is not supplied, then OpenCV will try to access our webcam. If this switch is supplied, then OpenCV will grab a pointer to the video file and read frames from it. The first switch, -video is the (optional) path to our example video file.

red white and blue bouncing balls

If you don’t already have imutils installed on your system, you can grab the source from GitHub or just use pip to install it: $ pip install -upgrade imutilsįrom there, Lines 11-16 handle parsing our command line arguments. We’ll also be using imutils, my collection of OpenCV convenience functions to make a few basic tasks (like resizing) much easier. Maintaining such a queue allows us to draw the “contrail” of the ball as its being tracked. We’ll be using deque, a list-like data structure with super fast appends and pops to maintain a list of the past N (x, y)-locations of the ball in our video stream. Lines 2-8 handle importing our necessary packages. Help="path to the (optional) video file")Īp.add_argument("-b", "-buffer", type=int, default=64,

red white and blue bouncing balls

# construct the argument parse and parse the arguments Open up a new file, name it ball_tracking.py, and we’ll get coding: # import the necessary packages Looking for the source code to this post? Jump Right To The Downloads Section Ball tracking with OpenCV








Red white and blue bouncing balls