When using the KCF tracker from Python the returned bounding box always has size=(0,0) and the position is wrong. For example:
import cv2
firstFrame = True
pathVid = '<path to vid or im seq>' # e.g. vidName.mp4 or images/%04.jpg (if image name is 0001.jpg...)
vidReader = cv2.VideoCapture(pathVid)
initBbox = (30, 60, 60, 70 ) # (x_tl, y_tl, w, h)
tracker = cv2.Tracker_create('KCF')
while vidReader.isOpened():
ok, image=vidReader.read()
if firstFrame:
ok = tracker.init(image, initBbox)
firstFrame = False
ok, bbox = tracker.update(image)
print ok, bbox
prints wrong bbox coordinates and width and height are always 0. The same code with:
tracker = cv2.Tracker_create('MIL')
works.
The problem is in the updateImpl function. When the function is called from Python from:
tracker.update(image)
the variable boundingBox which is the output of the tracker is initialize with 0s whereas in the C++ implementation the variable is passed by reference. Therefore the bounding box update implemented as:
// update the bounding box
boundingBox.x=(resizeImage?roi.x*2:roi.x)+boundingBox.width/2;
boundingBox.y=(resizeImage?roi.y*2:roi.y)+boundingBox.height/2;
will give wrong values in Python as width and height are 0s.
DetectMultiScale (InputArray image, vector
thank you very much