opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.42k stars 5.76k forks source link

KCF tracker: calcResponse returns all NaNs #1625

Open wolfatfb opened 6 years ago

wolfatfb commented 6 years ago

The split_coeff version of calcResponse can return all NaNs (caused by a division by zero).

In that case the subsequent call to minMaxLoc in updateImpl returns maxVal = NaN and maxLoc = { -1, -1 }, causing the roi center to be erroneously moved by roi.size()/2. This results in jarring tacking errors (object quickly jumps far to the left and up).

Potential solution: in calcResponse, add a small regularization constant to the denominator prior to the division.

https://github.com/opencv/opencv_contrib/blob/fbc4d82fd36009e02af4f6391312e3a9325051e0/modules/tracking/src/trackerKCF.cpp#L458

berak commented 6 years ago

just for clarification (and to reproduce it): this is the NON split_coeff version, and you had to explicitly set TrackerParams::split_coeff=false , right ?

wolfatfb commented 6 years ago

Oops. I'm sorry, I pointed you to the wrong line in the code. I did mean the split_coef version, but of another loop: the issue is inside calcResponse. The correct line for that is 880.

[EDIT] Please note that the proposed fix can work, if implemented correctly: the divisor on line 458 (as well as 880) is a sum of two squares, i.e. cannot be negative. Adding a constant to the divisor will make it positive.