Book Image

OpenCV Essentials

Book Image

OpenCV Essentials

Overview of this book

Table of Contents (15 chapters)
OpenCV Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

The CamShift tracker


The CamShift (Continuously Adaptive Mean Shift) algorithm is an image segmentation method that was introduced by Gary Bradski of OpenCV fame in 1998. It differs from MeanShift in that a search window adjusts itself in size. If we have a well-segmented distribution (for example, face features that stay compact), this method will automatically adjust itself to the face sizes as the person moves closer or farther from the camera.

We will now see the following example (trackingCamShift) using this method:

void trackingCamShift(Mat& img, Rect search_window)
{
    //1-Criteria to CamShift function
    TermCriteria criteria(TermCriteria::COUNT | TermCriteria::EPS, 10, 1);

    //2-Tracking using CamShift
    RotatedRect found_object = CamShift(img, search_window, criteria);

    //3-Bounding rectangle and show the result
    Rect found_rect = found_object...