Skip to content

Commit ceb7233

Browse files
Nuzhny007Smorodov
authored andcommitted
Control out the frame moving (Smorodov#82)
* Added hough3d sources * Calculate 3D hough trajectory lines * Added fps * Some warnings removing * Fixed warning * Added small crops in DNN detector for High resolution videos and small objects * Small refactoring * Some fix for single tracking * Added openmp flags to the compiler * Draw trajectory option * Update Readme * Fixed link * Hough3D disabled now in CMake * Added Yolo (and Tiny Yolo) detector * Update Readme * Remove unused Hybrid face detector * Extract Capture+Detection into the separate thread * Fixed potential deadlock * Points visualization * Control out the frame moving
1 parent ce36126 commit ceb7233

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

Tracker/track.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CTrack::CTrack(
2525
m_lastRegion(region),
2626
m_predictionPoint((region.m_rect.tl() + region.m_rect.br()) / 2),
2727
m_filterObjectSize(filterObjectSize),
28+
m_outOfTheFrame(false),
2829
m_externalTrackerForLost(externalTrackerForLost)
2930
{
3031
if (filterObjectSize)
@@ -162,6 +163,10 @@ bool CTrack::IsRobust(int minTraceSize, float minRawRatio, cv::Size2f sizeRatio)
162163
res &= (sr < sizeRatio.height);
163164
}
164165
}
166+
if (m_outOfTheFrame)
167+
{
168+
res = false;
169+
}
165170
return res;
166171
}
167172

@@ -203,7 +208,7 @@ void CTrack::RectUpdate(
203208

204209
bool recalcPrediction = true;
205210

206-
auto Clamp = [](int& v, int& size, int hi)
211+
auto Clamp = [](int& v, int& size, int hi) -> bool
207212
{
208213
if (size < 2)
209214
{
@@ -212,11 +217,14 @@ void CTrack::RectUpdate(
212217
if (v < 0)
213218
{
214219
v = 0;
220+
return true;
215221
}
216222
else if (v + size > hi - 1)
217223
{
218224
v = hi - 1 - size;
225+
return true;
219226
}
227+
return false;
220228
};
221229

222230
switch (m_externalTrackerForLost)
@@ -266,10 +274,12 @@ void CTrack::RectUpdate(
266274
#endif
267275

268276
inited = true;
277+
m_outOfTheFrame = false;
269278
}
270279
else
271280
{
272281
m_tracker.release();
282+
m_outOfTheFrame = true;
273283
}
274284
}
275285
cv::Rect2d newRect;
@@ -335,8 +345,9 @@ void CTrack::RectUpdate(
335345
}
336346
}
337347

338-
Clamp(m_predictionRect.x, m_predictionRect.width, currFrame.cols);
339-
Clamp(m_predictionRect.y, m_predictionRect.height, currFrame.rows);
348+
m_outOfTheFrame = false;
349+
m_outOfTheFrame |= Clamp(m_predictionRect.x, m_predictionRect.width, currFrame.cols);
350+
m_outOfTheFrame |= Clamp(m_predictionRect.y, m_predictionRect.height, currFrame.rows);
340351

341352
m_predictionPoint = (m_predictionRect.tl() + m_predictionRect.br()) / 2;
342353
}
@@ -459,17 +470,21 @@ void CTrack::PointUpdate(
459470
m_predictionPoint = m_kalman->Update(pt, dataCorrect);
460471
}
461472

462-
auto Clamp = [](track_t& v, int hi)
473+
auto Clamp = [](track_t& v, int hi) -> bool
463474
{
464475
if (v < 0)
465476
{
466477
v = 0;
478+
return true;
467479
}
468480
else if (hi && v > hi - 1)
469481
{
470482
v = static_cast<track_t>(hi - 1);
483+
return true;
471484
}
485+
return false;
472486
};
473-
Clamp(m_predictionPoint.x, frameSize.width);
474-
Clamp(m_predictionPoint.y, frameSize.height);
487+
m_outOfTheFrame = false;
488+
m_outOfTheFrame |= Clamp(m_predictionPoint.x, frameSize.width);
489+
m_outOfTheFrame |= Clamp(m_predictionPoint.y, frameSize.height);
475490
}

Tracker/track.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class CTrack
197197
cv::Rect m_predictionRect;
198198
TKalmanFilter* m_kalman;
199199
bool m_filterObjectSize;
200+
bool m_outOfTheFrame;
200201

201202
tracking::LostTrackType m_externalTrackerForLost;
202203
#ifdef USE_OCV_KCF

0 commit comments

Comments
 (0)