Skip to content

Commit 94c09fe

Browse files
committed
tracking:fix rounding and grayscale for KCF
1 parent a30fb44 commit 94c09fe

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

modules/tracking/src/trackerKCF.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ namespace cv{
212212
*/
213213
bool TrackerKCFImpl::initImpl( const Mat& image, const Rect2d& boundingBox ){
214214
frame=0;
215-
roi = boundingBox;
215+
roi.x = cvRound(boundingBox.x);
216+
roi.y = cvRound(boundingBox.y);
217+
roi.width = cvRound(boundingBox.width);
218+
roi.height = cvRound(boundingBox.height);
216219

217220
//calclulate output sigma
218221
output_sigma=std::sqrt(static_cast<float>(roi.width*roi.height))*params.output_sigma_factor;
@@ -242,8 +245,8 @@ namespace cv{
242245

243246
// create gaussian response
244247
y=Mat::zeros((int)roi.height,(int)roi.width,CV_32F);
245-
for(int i=0;i<roi.height;i++){
246-
for(int j=0;j<roi.width;j++){
248+
for(int i=0;i<int(roi.height);i++){
249+
for(int j=0;j<int(roi.width);j++){
247250
y.at<float>(i,j) =
248251
static_cast<float>((i-roi.height/2+1)*(i-roi.height/2+1)+(j-roi.width/2+1)*(j-roi.width/2+1));
249252
}
@@ -255,6 +258,10 @@ namespace cv{
255258
// perform fourier transfor to the gaussian response
256259
fft2(y,yf);
257260

261+
if (image.channels() == 1) { // disable CN for grayscale images
262+
params.desc_pca &= ~(CN);
263+
params.desc_npca &= ~(CN);
264+
}
258265
model=Ptr<TrackerKCFModel>(new TrackerKCFModel(params));
259266

260267
// record the non-compressed descriptors

modules/tracking/tutorials/tutorial_introduction_to_tracker.markdown

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ Explanation
4444

4545
@snippet tracking/samples/tutorial_introduction_to_tracker.cpp create
4646

47-
There are at least 5 types of tracker algorithms that can be used:
47+
There are at least 7 types of tracker algorithms that can be used:
4848
+ MIL
4949
+ BOOSTING
5050
+ MEDIANFLOW
5151
+ TLD
5252
+ KCF
53+
+ GOTURN
54+
+ MOSSE
5355

5456
Each tracker algorithm has their own advantages and disadvantages, please refer the documentation of @ref cv::Tracker for more detailed information.
5557

@@ -64,8 +66,8 @@ Explanation
6466

6567
@snippet tracking/samples/tutorial_introduction_to_tracker.cpp init
6668

67-
Tracker algorithm should be initialized with the provided image data as well as the bounding box of the tracked object.
68-
Make sure that the bounding box is not valid (size more than zero) to avoid the initialization process failed.
69+
Any tracker algorithm should be initialized with the provided image data, and an initial bounding box of the tracked object.
70+
Make sure that the bounding box is valid (size more than zero) to avoid failure of the initialization process.
6971

7072
-# **Update**
7173

0 commit comments

Comments
 (0)