A simple way to get started tracking an object in a video stream is to determine the color range of an object.

To do this, we define the lower and upper boundaries of the object color in a particular color space, such as RGB, HSV, or L*a*b*.

But how do we go about actually determining what the lower and upper boundaries should be? The following section addresses this question.

Defining your color range

The code in this chapter focused on how to track a blue object in a video stream.

But what if you wanted to track a red one? Or a green one?

What would you do then?

Personally, I would suggest utilizing the range-detector  script from my imutils library.

This script can be used to help you determine the appropriate lower and upper color boundaries for a particular object.

Tracking location

Once you are able to detect and localize an object in a frame, you can also track its location as well:

http://www.pyimagesearch.com/2015/09/21/opencv-track-object-movement/

Applying this method will allow you to track the (x, y)-coordinates of the object in the video stream and determine the path it moves along the frame sequence.

Extending your object tracker

More advanced object detection systems take into account more than just the color of an object — they also utilize the shape and gradient.

A great example of such a detector is the Histogram of Oriented Gradients + Linear SVM detector.

This detector does not incorporate color, but instead utilizes the overall shape of the object which is computed via the gradient magnitude and orientation representation of the image.

I provided a detailed implementation and review of the HOG + Linear SVM detector inside the PyImageSearch Gurus course.

0% Complete
0/18 Steps