Opencv_contrib: KCF tracker returns wrong bounding box in Python

Created on 21 Apr 2016  Â·  2Comments  Â·  Source: opencv/opencv_contrib

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.

bug tracking

All 2 comments

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 & objects, double scaleFactor = 1.1, int minNeighbors = 3, int flags = 0, Size minSize = Size (), Size maxSize = Size ()Where the target is vector type, however,the tracking function MultiTracker :: add (const String & trackerType, const Mat & image, const Rect2d & boundingBox) is the target of the Rect2d type. Do you know how to deal with it?
thank you very much

Was this page helpful?
0 / 5 - 0 ratings