MCPcopy Create free account
hub / github.com/Smorodov/Multitarget-tracker / CaptureAndDetect

Method CaptureAndDetect

example/VideoExample.cpp:360–451  ·  view source on GitHub ↗

\brief VideoExample::CaptureAndDetect \param thisPtr \param stopCapture

Source from the content-addressed store, hash-verified

358/// \param stopCapture
359///
360void VideoExample::CaptureAndDetect(VideoExample* thisPtr, std::atomic<bool>& stopCapture)
361{
362 cv::VideoCapture capture;
363 if (!thisPtr->OpenCapture(capture))
364 {
365 thisPtr->m_logger->critical("+++ Can't open {}", thisPtr->m_inFile);
366 stopCapture = true;
367 return;
368 }
369
370 int framesCounter = 0;
371
372 const auto localEndFrame = thisPtr->m_endFrame;
373 auto localIsDetectorInitialized = thisPtr->m_isDetectorInitialized;
374 auto localTrackingTimeOut = thisPtr->m_trackingTimeOut;
375 size_t processCounter = 0;
376 for (; !stopCapture.load();)
377 {
378 FrameInfo& frameInfo = thisPtr->m_frameInfo[processCounter % 2];
379 thisPtr->m_logger->debug("+++ waiting capture to {0}, ind = {1}", processCounter % 2, processCounter);
380 {
381 std::unique_lock<std::mutex> lock(frameInfo.m_mutex);
382 if (!frameInfo.m_cond.wait_for(lock, std::chrono::milliseconds(localTrackingTimeOut), [&frameInfo] { return !frameInfo.m_captured.load(); }))
383 {
384 thisPtr->m_logger->info("+++ Wait tracking timeout!");
385 frameInfo.m_cond.notify_one();
386 break;
387 }
388 }
389 thisPtr->m_logger->debug("+++ capture to {0} in progress...", processCounter % 2);
390 if (frameInfo.m_frames.size() < frameInfo.m_batchSize)
391 {
392 frameInfo.m_frames.resize(frameInfo.m_batchSize);
393 frameInfo.m_frameInds.resize(frameInfo.m_batchSize);
394 frameInfo.m_frameTimeStamps.resize(frameInfo.m_batchSize);
395 }
396
397 cv::Mat frame;
398 size_t i = 0;
399 for (; i < frameInfo.m_batchSize; ++i)
400 {
401 capture >> frame;
402 if (frame.empty())
403 {
404 thisPtr->m_logger->error("+++ CaptureAndDetect: frame is empty!");
405 frameInfo.m_cond.notify_one();
406 break;
407 }
408 frameInfo.m_frames[i].GetMatBGRWrite() = frame;
409 frameInfo.m_frames[i].AdjustMatBGR();
410 frameInfo.m_frameInds[i] = framesCounter;
411 frameInfo.m_frameTimeStamps[i] = thisPtr->GetNextTimeStamp(framesCounter);
412 ++framesCounter;
413
414 if (localEndFrame && framesCounter > localEndFrame)
415 {
416 thisPtr->m_logger->info("+++ Process: riched last {} frame", localEndFrame);
417 break;

Callers

nothing calls this directly

Calls 9

OpenCaptureMethod · 0.80
resizeMethod · 0.80
AdjustMatBGRMethod · 0.80
GetNextTimeStampMethod · 0.80
loadMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
InitDetectorMethod · 0.45
DetectionMethod · 0.45

Tested by

no test coverage detected