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.boundingRect();
    rectangle(img, found_rect, Scalar(0,255,0),3);
}

This function structure is very similar to the one in the preceding section; the only difference is that a bounding rectangle is returned from CamShift().

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset