O'Reilly logo

Computer Vision with Python 3 by Saurabh Kapur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Kernelized Correlation Filter (KCF)

How does KCF work? Given the initial set of points, a tracker tries to calculate the motion of these points by looking at the direction of change in the next frame. In every consecutive frame, we try to look for the same set of points in the neighborhood. Once the new positions of these points are identified, we can move the bounding box over the new set of points. There is mathematics involved in making the search faster and more efficient, which is beyond the scope of this book:

import cv2tracker = cv2.Tracker_create("KCF")cam = cv2.VideoCapture(0)for i in range(5):    ret, frame = cam.read()obj = cv2.selectROI("Tracking",frame)ok = tracker.init(frame, obj)while True:    ret, frame = cam.read() upd, obj = tracker.update(frame) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required