|
|
|
@ -65,27 +65,58 @@ namespace cv |
|
|
|
|
return p; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
double TLDDetector::computeSminus(const Mat_<uchar>& patch) const |
|
|
|
|
{ |
|
|
|
|
double sminus = 0.0; |
|
|
|
|
Mat_<uchar> modelSample(STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE); |
|
|
|
|
for (int i = 0; i < *negNum; i++) |
|
|
|
|
{ |
|
|
|
|
modelSample.data = &(negExp->data[i * 225]); |
|
|
|
|
sminus = std::max(sminus, 0.5 * (tracking_internal::computeNCC(modelSample, patch) + 1.0)); |
|
|
|
|
} |
|
|
|
|
return sminus; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Calculate Relative similarity of the patch (NN-Model)
|
|
|
|
|
double TLDDetector::Sr(const Mat_<uchar>& patch) const |
|
|
|
|
{ |
|
|
|
|
double splus = 0.0, sminus = 0.0; |
|
|
|
|
Mat_<uchar> modelSample(STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE); |
|
|
|
|
Mat_<uchar> modelSample(STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE); |
|
|
|
|
for (int i = 0; i < *posNum; i++) |
|
|
|
|
{ |
|
|
|
|
modelSample.data = &(posExp->data[i * 225]); |
|
|
|
|
splus = std::max(splus, 0.5 * (tracking_internal::computeNCC(modelSample, patch) + 1.0)); |
|
|
|
|
} |
|
|
|
|
for (int i = 0; i < *negNum; i++) |
|
|
|
|
{ |
|
|
|
|
modelSample.data = &(negExp->data[i * 225]); |
|
|
|
|
sminus = std::max(sminus, 0.5 * (tracking_internal::computeNCC(modelSample, patch) + 1.0)); |
|
|
|
|
} |
|
|
|
|
sminus = computeSminus(patch); |
|
|
|
|
|
|
|
|
|
if (splus + sminus == 0.0) |
|
|
|
|
return 0.0; |
|
|
|
|
return splus / (sminus + splus); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::pair<double, double> TLDDetector::SrAndSc(const Mat_<uchar>& patch) const |
|
|
|
|
{ |
|
|
|
|
double splusC = 0.0, sminus = 0.0, splus = 0.0; |
|
|
|
|
Mat_<uchar> modelSample(STANDARD_PATCH_SIZE, STANDARD_PATCH_SIZE); |
|
|
|
|
int med = tracking_internal::getMedian((*timeStampsPositive)); |
|
|
|
|
for (int i = 0; i < *posNum; i++) |
|
|
|
|
{ |
|
|
|
|
modelSample.data = &(posExp->data[i * 225]); |
|
|
|
|
double s = 0.5 * (tracking_internal::computeNCC(modelSample, patch) + 1.0); |
|
|
|
|
|
|
|
|
|
if ((int)(*timeStampsPositive)[i] <= med) |
|
|
|
|
splusC = std::max(splusC, s); |
|
|
|
|
|
|
|
|
|
splus = std::max(splus, s); |
|
|
|
|
} |
|
|
|
|
sminus = computeSminus(patch); |
|
|
|
|
|
|
|
|
|
double sr = (splus + sminus == 0.0) ? 0. : splus / (sminus + splus); |
|
|
|
|
double sc = (splusC + sminus == 0.0) ? 0. : splusC / (sminus + splusC); |
|
|
|
|
|
|
|
|
|
return std::pair<double, double>(sr, sc); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENCL |
|
|
|
|
double TLDDetector::ocl_Sr(const Mat_<uchar>& patch) |
|
|
|
|
{ |
|
|
|
@ -205,11 +236,7 @@ namespace cv |
|
|
|
|
splus = std::max(splus, 0.5 * (tracking_internal::computeNCC(modelSample, patch) + 1.0)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for (int i = 0; i < *negNum; i++) |
|
|
|
|
{ |
|
|
|
|
modelSample.data = &(negExp->data[i * 225]); |
|
|
|
|
sminus = std::max(sminus, 0.5 * (tracking_internal::computeNCC(modelSample, patch) + 1.0)); |
|
|
|
|
} |
|
|
|
|
sminus = computeSminus(patch); |
|
|
|
|
|
|
|
|
|
if (splus + sminus == 0.0) |
|
|
|
|
return 0.0; |
|
|
|
@ -317,9 +344,9 @@ namespace cv |
|
|
|
|
resample(detectorF->resized_imgs[detectorF->ensScaleIDs[ind]], |
|
|
|
|
Rect2d(detectorF->ensBuffer[ind], initSizeF), |
|
|
|
|
detectorF->standardPatches[ind]); |
|
|
|
|
|
|
|
|
|
detectorF->scValues[ind] = detectorF->Sc (detectorF->standardPatches[ind]); |
|
|
|
|
detectorF->srValues[ind] = detectorF->Sr (detectorF->standardPatches[ind]); |
|
|
|
|
std::pair<double, double> values = detectorF->SrAndSc(detectorF->standardPatches[ind]); |
|
|
|
|
detectorF->scValues[ind] = values.second; |
|
|
|
|
detectorF->srValues[ind] = values.first; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -413,15 +440,17 @@ namespace cv |
|
|
|
|
LabeledPatch labPatch; |
|
|
|
|
double curScale = pow(SCALE_STEP, ensScaleIDs[i]); |
|
|
|
|
labPatch.rect = Rect2d(ensBuffer[i].x*curScale, ensBuffer[i].y*curScale, initSize.width * curScale, initSize.height * curScale); |
|
|
|
|
labPatch.Sc = scValues[i]; |
|
|
|
|
//printf("max sc %f\n", labPatch.Sc);
|
|
|
|
|
|
|
|
|
|
const double srValue = srValues[i]; |
|
|
|
|
const double scValue = scValues[i]; |
|
|
|
|
|
|
|
|
|
////To fix: Check the paper, probably this cause wrong learning
|
|
|
|
|
//
|
|
|
|
|
labPatch.isObject = srValue > THETA_NN; |
|
|
|
|
labPatch.isObject = srValue > THETA_NN; |
|
|
|
|
labPatch.shouldBeIntegrated = abs(srValue - THETA_NN) < CLASSIFIER_MARGIN; |
|
|
|
|
patches.push_back(labPatch); |
|
|
|
|
patches.push_back(labPatch); |
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
if (!labPatch.isObject) |
|
|
|
@ -441,7 +470,7 @@ namespace cv |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (maxSc < 0) |
|
|
|
|
if (maxSc < 0) |
|
|
|
|
return false; |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|