@@ -65,27 +65,58 @@ namespace cv
65
65
return p;
66
66
}
67
67
68
+ double TLDDetector::computeSminus (const Mat_<uchar>& patch) const
69
+ {
70
+ double sminus = 0.0 ;
71
+ Mat_<uchar> modelSample (STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE);
72
+ for (int i = 0 ; i < *negNum; i++)
73
+ {
74
+ modelSample.data = &(negExp->data [i * 225 ]);
75
+ sminus = std::max (sminus, 0.5 * (tracking_internal::computeNCC (modelSample, patch) + 1.0 ));
76
+ }
77
+ return sminus;
78
+ }
79
+
68
80
// Calculate Relative similarity of the patch (NN-Model)
69
81
double TLDDetector::Sr (const Mat_<uchar>& patch) const
70
82
{
71
83
double splus = 0.0 , sminus = 0.0 ;
72
- Mat_<uchar> modelSample (STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE);
84
+ Mat_<uchar> modelSample (STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE);
73
85
for (int i = 0 ; i < *posNum; i++)
74
86
{
75
87
modelSample.data = &(posExp->data [i * 225 ]);
76
88
splus = std::max (splus, 0.5 * (tracking_internal::computeNCC (modelSample, patch) + 1.0 ));
77
89
}
78
- for (int i = 0 ; i < *negNum; i++)
79
- {
80
- modelSample.data = &(negExp->data [i * 225 ]);
81
- sminus = std::max (sminus, 0.5 * (tracking_internal::computeNCC (modelSample, patch) + 1.0 ));
82
- }
90
+ sminus = computeSminus (patch);
83
91
84
92
if (splus + sminus == 0.0 )
85
93
return 0.0 ;
86
94
return splus / (sminus + splus);
87
95
}
88
96
97
+ std::pair<double , double > TLDDetector::SrAndSc (const Mat_<uchar>& patch) const
98
+ {
99
+ double splusC = 0.0 , sminus = 0.0 , splus = 0.0 ;
100
+ Mat_<uchar> modelSample (STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE);
101
+ int med = tracking_internal::getMedian ((*timeStampsPositive));
102
+ for (int i = 0 ; i < *posNum; i++)
103
+ {
104
+ modelSample.data = &(posExp->data [i * 225 ]);
105
+ double s = 0.5 * (tracking_internal::computeNCC (modelSample, patch) + 1.0 );
106
+
107
+ if ((int )(*timeStampsPositive)[i] <= med)
108
+ splusC = std::max (splusC, s);
109
+
110
+ splus = std::max (splus, s);
111
+ }
112
+ sminus = computeSminus (patch);
113
+
114
+ double sr = (splus + sminus == 0.0 ) ? 0 . : splus / (sminus + splus);
115
+ double sc = (splusC + sminus == 0.0 ) ? 0 . : splusC / (sminus + splusC);
116
+
117
+ return std::pair<double , double >(sr, sc);
118
+ }
119
+
89
120
#ifdef HAVE_OPENCL
90
121
double TLDDetector::ocl_Sr (const Mat_<uchar>& patch)
91
122
{
@@ -205,11 +236,7 @@ namespace cv
205
236
splus = std::max (splus, 0.5 * (tracking_internal::computeNCC (modelSample, patch) + 1.0 ));
206
237
}
207
238
}
208
- for (int i = 0 ; i < *negNum; i++)
209
- {
210
- modelSample.data = &(negExp->data [i * 225 ]);
211
- sminus = std::max (sminus, 0.5 * (tracking_internal::computeNCC (modelSample, patch) + 1.0 ));
212
- }
239
+ sminus = computeSminus (patch);
213
240
214
241
if (splus + sminus == 0.0 )
215
242
return 0.0 ;
@@ -317,9 +344,9 @@ namespace cv
317
344
resample (detectorF->resized_imgs [detectorF->ensScaleIDs [ind]],
318
345
Rect2d (detectorF->ensBuffer [ind], initSizeF),
319
346
detectorF->standardPatches [ind]);
320
-
321
- detectorF->scValues [ind] = detectorF-> Sc (detectorF-> standardPatches [ind]) ;
322
- detectorF->srValues [ind] = detectorF-> Sr (detectorF-> standardPatches [ind]) ;
347
+ std::pair< double , double > values = detectorF-> SrAndSc (detectorF-> standardPatches [ind]);
348
+ detectorF->scValues [ind] = values. second ;
349
+ detectorF->srValues [ind] = values. first ;
323
350
}
324
351
}
325
352
@@ -413,15 +440,17 @@ namespace cv
413
440
LabeledPatch labPatch;
414
441
double curScale = pow (SCALE_STEP, ensScaleIDs[i]);
415
442
labPatch.rect = Rect2d (ensBuffer[i].x *curScale, ensBuffer[i].y *curScale, initSize.width * curScale, initSize.height * curScale);
443
+ labPatch.Sc = scValues[i];
444
+ // printf("max sc %f\n", labPatch.Sc);
416
445
417
446
const double srValue = srValues[i];
418
447
const double scValue = scValues[i];
419
448
420
449
// //To fix: Check the paper, probably this cause wrong learning
421
450
//
422
- labPatch.isObject = srValue > THETA_NN;
451
+ labPatch.isObject = srValue > THETA_NN;
423
452
labPatch.shouldBeIntegrated = abs (srValue - THETA_NN) < CLASSIFIER_MARGIN;
424
- patches.push_back (labPatch);
453
+ patches.push_back (labPatch);
425
454
//
426
455
427
456
if (!labPatch.isObject )
@@ -441,7 +470,7 @@ namespace cv
441
470
}
442
471
}
443
472
444
- if (maxSc < 0 )
473
+ if (maxSc < 0 )
445
474
return false ;
446
475
else
447
476
{
0 commit comments