joaofaro / KCFcpp

C++ Implementation of KCF Tracker
BSD 3-Clause "New" or "Revised" License
895 stars 446 forks source link

Fix crash with zero map size #22

Open ysolovyov opened 6 years ago

ysolovyov commented 6 years ago

This is workaround for crash caused by _tmpl_sz.width or _tmpl_sz.height be equal to 2*cell_size. Later in getFeatureMaps(&z_ipl, cell_size, &map) dimensions of the CvLSVMFeatureMapCaskade *map will be set to [_tmpl_sz.width / cell_size, _tmpl_sz.height / cell_size] and in normalizeAndTruncate(map, 0.2f) they will be changed to map.sizeX -= 2 and map.sizeY -= 2, so if, for example, _tmpl_sz.height == 2*cell_size then final map dimension will be map.sizeY == 0, that does not make sense and there will be crash in createHanningMats() during multiplacation of two matrixes.

Actual assert in OpenCV

OpenCV Error: Assertion failed (type == (((6) & ((1 << 3) - 1)) + (((2)-1) << 3))) in gemmImpl, file /opencv/modules/core/src/matmul.cpp, line 1218

in

cv::Mat hann2d = hann2t * hann1t; because hann2t has size [1 x 0]