Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KCF tracker returns wrong bounding box in Python #640

Closed
alessiodore opened this issue Apr 21, 2016 · 2 comments
Closed

KCF tracker returns wrong bounding box in Python #640

alessiodore opened this issue Apr 21, 2016 · 2 comments

Comments

@alessiodore
Copy link
Contributor

alessiodore commented Apr 21, 2016

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.

@alessiodore
Copy link
Contributor Author

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.

@HaiyangLiu711
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants