\brief VideoExample::AsyncProcess
| 247 | /// \brief VideoExample::AsyncProcess |
| 248 | /// |
| 249 | void VideoExample::AsyncProcess() |
| 250 | { |
| 251 | std::atomic<bool> stopCapture(false); |
| 252 | |
| 253 | std::thread thCapDet(CaptureAndDetect, this, std::ref(stopCapture)); |
| 254 | |
| 255 | cv::VideoWriter writer; |
| 256 | |
| 257 | #ifndef SILENT_WORK |
| 258 | cv::namedWindow("Video", cv::WINDOW_NORMAL | cv::WINDOW_KEEPRATIO); |
| 259 | bool manualMode = false; |
| 260 | #endif |
| 261 | |
| 262 | double freq = cv::getTickFrequency(); |
| 263 | |
| 264 | int64 allTime = 0; |
| 265 | int64 startLoopTime = cv::getTickCount(); |
| 266 | size_t processCounter = 0; |
| 267 | for (; !stopCapture.load(); ) |
| 268 | { |
| 269 | FrameInfo& frameInfo = m_frameInfo[processCounter % 2]; |
| 270 | m_logger->debug("--- waiting tracking from {0} ind = {1}", processCounter % 2, processCounter); |
| 271 | { |
| 272 | std::unique_lock<std::mutex> lock(frameInfo.m_mutex); |
| 273 | if (!frameInfo.m_cond.wait_for(lock, std::chrono::milliseconds(m_captureTimeOut), [&frameInfo] { return frameInfo.m_captured.load(); })) |
| 274 | { |
| 275 | m_logger->info("--- Wait frame timeout!"); |
| 276 | break; |
| 277 | } |
| 278 | } |
| 279 | m_logger->debug("--- tracking from {} in progress...", processCounter % 2); |
| 280 | if (!m_isTrackerInitialized) |
| 281 | { |
| 282 | m_isTrackerInitialized = InitTracker(frameInfo.m_frames[0].GetUMatBGR()); |
| 283 | if (!m_isTrackerInitialized) |
| 284 | { |
| 285 | m_logger->critical("--- AsyncProcess: Tracker initialize error!!!"); |
| 286 | frameInfo.m_cond.notify_one(); |
| 287 | break; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | int64 t1 = cv::getTickCount(); |
| 292 | |
| 293 | Tracking(frameInfo); |
| 294 | |
| 295 | int64 t2 = cv::getTickCount(); |
| 296 | |
| 297 | allTime += t2 - t1 + frameInfo.m_dt; |
| 298 | int currTime = cvRound(1000 * (t2 - t1 + frameInfo.m_dt) / freq); |
| 299 | |
| 300 | m_logger->debug("--- Frame {0}: td = {1}, tt = {2}", frameInfo.m_frameInds[0], 1000 * frameInfo.m_dt / freq, 1000 * (t2 - t1) / freq); |
| 301 | |
| 302 | int key = 0; |
| 303 | for (size_t i = 0; i < m_batchSize; ++i) |
| 304 | { |
| 305 | DrawData(frameInfo.m_frames[i].GetMatBGR(), frameInfo.m_tracks[i], frameInfo.m_frameInds[i], currTime); |
| 306 |