Skip to content

Commit 62939e2

Browse files
committed
tracking: slightly rewrite main loop in TLD
1 parent a0896c7 commit 62939e2

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

modules/tracking/src/tldTracker.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,37 +140,35 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
140140
std::vector<Rect2d> candidates;
141141
std::vector<double> candidatesRes;
142142
bool trackerNeedsReInit = false;
143-
bool DETECT_FLG = false;
144-
for( int i = 0; i < 2; i++ )
143+
bool DETECT_FLG = false;
144+
145+
//run tracker
146+
Rect2d tmpCandid = boundingBox;
147+
if(!data->failedLastTime && trackerProxy->update(image, tmpCandid))
145148
{
146-
Rect2d tmpCandid = boundingBox;
149+
candidates.push_back(tmpCandid);
150+
resample(image_gray, tmpCandid, standardPatch);
151+
candidatesRes.push_back(tldModel->detector->Sc(standardPatch));
152+
}
153+
else
154+
trackerNeedsReInit = true;
147155

148-
if (i == 1)
149-
{
156+
//run detector
157+
tmpCandid = boundingBox;
150158
#ifdef HAVE_OPENCL
151-
if (false)//ocl::useOpenCL())
152-
{
153-
DETECT_FLG = tldModel->detector->ocl_detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
154-
}
155-
else
159+
if (false)//ocl::useOpenCL())
160+
DETECT_FLG = tldModel->detector->ocl_detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
161+
else
156162
#endif
157-
DETECT_FLG = tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
158-
}
159-
if( ( (i == 0) && !data->failedLastTime && trackerProxy->update(image, tmpCandid) ) || ( DETECT_FLG))
160-
{
161-
candidates.push_back(tmpCandid);
162-
if( i == 0 )
163-
resample(image_gray, tmpCandid, standardPatch);
164-
else
165-
resample(imageForDetector, tmpCandid, standardPatch);
166-
candidatesRes.push_back(tldModel->detector->Sc(standardPatch));
167-
}
168-
else
169-
{
170-
if( i == 0 )
171-
trackerNeedsReInit = true;
172-
}
163+
DETECT_FLG = tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
164+
165+
if(DETECT_FLG)
166+
{
167+
candidates.push_back(tmpCandid);
168+
resample(imageForDetector, tmpCandid, standardPatch);
169+
candidatesRes.push_back(tldModel->detector->Sc(standardPatch));
173170
}
171+
174172
std::vector<double>::iterator it = std::max_element(candidatesRes.begin(), candidatesRes.end());
175173

176174
if( it == candidatesRes.end() ) //candidates are empty

0 commit comments

Comments
 (0)