Skip to content

Commit 36d2fe9

Browse files
committed
Fill batch structure
1 parent 80ea934 commit 36d2fe9

1 file changed

Lines changed: 44 additions & 24 deletions

File tree

example/VideoExample.cpp

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void VideoExample::AsyncProcess()
245245

246246
if (!m_isTrackerInitialized)
247247
{
248-
cv::UMat ufirst = frameInfo.m_frame.getUMat(cv::ACCESS_READ);
248+
cv::UMat ufirst = frameInfo.m_frames[0].getUMat(cv::ACCESS_READ);
249249
m_isTrackerInitialized = InitTracker(ufirst);
250250
if (!m_isTrackerInitialized)
251251
{
@@ -257,7 +257,7 @@ void VideoExample::AsyncProcess()
257257

258258
int64 t1 = cv::getTickCount();
259259

260-
Tracking(frameInfo.m_frame, frameInfo.m_regions);
260+
Tracking(frameInfo);
261261

262262
int64 t2 = cv::getTickCount();
263263

@@ -266,34 +266,38 @@ void VideoExample::AsyncProcess()
266266

267267
//std::cout << "Frame " << framesCounter << ": td = " << (1000 * frameInfo.m_dt / freq) << ", tt = " << (1000 * (t2 - t1) / freq) << std::endl;
268268

269-
DrawData(frameInfo.m_frame, framesCounter, currTime);
269+
int key = 0;
270+
for (size_t i = 0; i < m_batchSize; ++i)
271+
{
272+
DrawData(frameInfo.m_frames[i], framesCounter, currTime);
270273

271-
WriteFrame(writer, frameInfo.m_frame);
274+
WriteFrame(writer, frameInfo.m_frames[i]);
272275

273-
int k = 0;
276+
++framesCounter;
277+
274278
#ifndef SILENT_WORK
275-
cv::imshow("Video", frameInfo.m_frame);
279+
cv::imshow("Video", frameInfo.m_frames[0]);
276280

277-
int waitTime = manualMode ? 0 : 1;// std::max<int>(1, cvRound(1000 / m_fps - currTime));
278-
k = cv::waitKey(waitTime);
279-
if (k == 'm' || k == 'M')
280-
{
281-
manualMode = !manualMode;
282-
}
281+
int waitTime = manualMode ? 0 : 1;// std::max<int>(1, cvRound(1000 / m_fps - currTime));
282+
key = cv::waitKey(waitTime);
283+
if (key == 'm' || key == 'M')
284+
manualMode = !manualMode;
285+
else
286+
break;
283287
#else
284-
std::this_thread::sleep_for(std::chrono::milliseconds(1));
288+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
285289
#endif
290+
}
286291

287292
{
288293
std::unique_lock<std::mutex> lock(frameInfo.m_mutex);
289294
frameInfo.m_captured = false;
290295
}
291296
frameInfo.m_cond.notify_one();
292297

293-
if (k == 27)
298+
if (key == 27)
294299
break;
295300

296-
++framesCounter;
297301
if (m_endFrame && framesCounter > m_endFrame)
298302
{
299303
std::cout << "Process: riched last " << m_endFrame << " frame" << std::endl;
@@ -330,6 +334,8 @@ void VideoExample::CaptureAndDetect(VideoExample* thisPtr, std::atomic<bool>& st
330334
return;
331335
}
332336

337+
int framesCounter = 0;
338+
333339
int trackingTimeOut = thisPtr->m_trackingTimeOut;
334340
size_t processCounter = 0;
335341
for (; !stopCapture.load();)
@@ -346,17 +352,31 @@ void VideoExample::CaptureAndDetect(VideoExample* thisPtr, std::atomic<bool>& st
346352
}
347353
}
348354

349-
capture >> frameInfo.m_frame;
350-
if (frameInfo.m_frame.empty())
351-
{
352-
std::cerr << "CaptureAndDetect: frame is empty!" << std::endl;
353-
frameInfo.m_cond.notify_one();
354-
break;
355-
}
355+
if (frameInfo.m_frames.size() < frameInfo.m_batchSize)
356+
{
357+
frameInfo.m_frames.resize(frameInfo.m_batchSize);
358+
frameInfo.m_frameInds.resize(frameInfo.m_batchSize);
359+
}
360+
361+
for (size_t i = 1; i < frameInfo.m_batchSize; ++i)
362+
{
363+
capture >> frameInfo.m_frames[i];
364+
if (frameInfo.m_frames[i].empty())
365+
{
366+
std::cerr << "CaptureAndDetect: frame is empty!" << std::endl;
367+
frameInfo.m_cond.notify_one();
368+
break;
369+
}
370+
frameInfo.m_frameInds.emplace_back(framesCounter);
371+
372+
++framesCounter;
373+
}
374+
if (frameInfo.m_frames.size() < frameInfo.m_batchSize)
375+
break;
356376

357377
if (!thisPtr->m_isDetectorInitialized)
358378
{
359-
cv::UMat ufirst = frameInfo.m_frame.getUMat(cv::ACCESS_READ);
379+
cv::UMat ufirst = frameInfo.m_frames[0].getUMat(cv::ACCESS_READ);
360380
thisPtr->m_isDetectorInitialized = thisPtr->InitDetector(ufirst);
361381
if (!thisPtr->m_isDetectorInitialized)
362382
{
@@ -367,7 +387,7 @@ void VideoExample::CaptureAndDetect(VideoExample* thisPtr, std::atomic<bool>& st
367387
}
368388

369389
int64 t1 = cv::getTickCount();
370-
thisPtr->Detection(frameInfo.m_frame, frameInfo.m_regions);
390+
thisPtr->Detection(frameInfo);
371391
int64 t2 = cv::getTickCount();
372392
frameInfo.m_dt = t2 - t1;
373393

0 commit comments

Comments
 (0)