Commit 895a9143 authored by Vladislav Sovrasov's avatar Vladislav Sovrasov

tracking: fix unitialized memory access in TLD

parent a6215264
......@@ -87,9 +87,9 @@ namespace cv
//Generate initial positive samples and put them to the model
positiveExamples.reserve(200);
for (int i = 0; i < (int)closest.size(); i++)
for (size_t i = 0; i < closest.size(); i++)
{
for (int j = 0; j < 20; j++)
for (size_t j = 0; j < 20; j++)
{
Point2f center;
Size2f size;
......@@ -102,13 +102,15 @@ namespace cv
resample(scaledImg, RotatedRect(center, size, angle), standardPatch);
for (int y = 0; y < standardPatch.rows; y++)
{
for (int x = 0; x < standardPatch.cols; x++)
{
standardPatch(x, y) += (uchar)rng.gaussian(5.0);
}
}
for( int y = 0; y < standardPatch.rows; y++ )
{
uchar* patchRow = standardPatch.ptr(y);
for( int x = 0; x < standardPatch.cols; x++ )
{
int newValue = patchRow[x] + cvRound(rng.gaussian(5.0));
patchRow[x] = saturate_cast<uchar>(newValue);
}
}
#ifdef BLUR_AS_VADIM
GaussianBlur(standardPatch, blurredPatch, GaussBlurKernelSize, 0.0);
......
......@@ -41,7 +41,6 @@
#include "tldTracker.hpp"
namespace cv
{
......@@ -156,7 +155,7 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
else
#endif
DETECT_FLG = tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
}
}
if( ( (i == 0) && !data->failedLastTime && trackerProxy->update(image, tmpCandid) ) || ( DETECT_FLG))
{
candidates.push_back(tmpCandid);
......@@ -174,7 +173,7 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
}
std::vector<double>::iterator it = std::max_element(candidatesRes.begin(), candidatesRes.end());
if( it == candidatesRes.end() )
if( it == candidatesRes.end() ) //candidates are empty
{
data->confident = false;
data->failedLastTime = true;
......@@ -259,6 +258,7 @@ int TrackerTLDImpl::Pexpert::additionalExamples(std::vector<Mat_<uchar> >& examp
double scale = scaleAndBlur(img_, cvRound(log(1.0 * resultBox_.width / (initSize_.width)) / log(SCALE_STEP)),
scaledImg, blurredImg, GaussBlurKernelSize, SCALE_STEP);
TLDDetector::generateScanGrid(img_.rows, img_.cols, initSize_, scanGrid);
getClosestN(scanGrid, Rect2d(resultBox_.x / scale, resultBox_.y / scale, resultBox_.width / scale, resultBox_.height / scale), 10, closest);
......@@ -275,21 +275,24 @@ int TrackerTLDImpl::Pexpert::additionalExamples(std::vector<Mat_<uchar> >& examp
size.height = (float)(closest[i].height * rng.uniform((double)0.99, (double)1.01));
float angle = (float)rng.uniform(-5.0, 5.0);
resample(scaledImg, RotatedRect(center, size, angle), standardPatch);
for( int y = 0; y < standardPatch.rows; y++ )
{
uchar* patchRow = standardPatch.ptr(y);
for( int x = 0; x < standardPatch.cols; x++ )
{
standardPatch(x, y) += (uchar)rng.gaussian(5.0);
int newValue = patchRow[x] + cvRound(rng.gaussian(5.0));
patchRow[x] = saturate_cast<uchar>(newValue);
}
}
#ifdef BLUR_AS_VADIM
examplesForModel.push_back(standardPatch);
#if defined BLUR_AS_VADIM
GaussianBlur(standardPatch, blurredPatch, GaussBlurKernelSize, 0.0);
resize(blurredPatch, blurredPatch, initSize_);
#else
resample(blurredImg, RotatedRect(center, size, angle), blurredPatch);
#endif
resample(scaledImg, RotatedRect(center, size, angle), standardPatch);
examplesForModel.push_back(standardPatch);
examplesForEnsemble.push_back(blurredPatch);
}
}
......
......@@ -112,7 +112,7 @@ private:
};
#define BLUR_AS_VADIM
#undef BLUR_AS_VADIM
#undef CLOSED_LOOP
class TrackerTLDImpl : public TrackerTLD
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment