@@ -181,7 +181,7 @@ void VideoExample::SyncProcess()
181181
182182 for (size_t i = 0 ; i < m_batchSize; ++i)
183183 {
184- DrawData (frameInfo.m_frames [i], frameInfo.m_frameInds [i], currTime);
184+ DrawData (frameInfo.m_frames [i]. GetMatBGR () , frameInfo.m_frameInds [i], currTime);
185185
186186#ifndef SILENT_WORK
187187 cv::imshow (" Video" , frame);
@@ -196,7 +196,7 @@ void VideoExample::SyncProcess()
196196 std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
197197#endif
198198
199- WriteFrame (writer, frameInfo.m_frames [i]);
199+ WriteFrame (writer, frameInfo.m_frames [i]. GetMatBGR () );
200200 }
201201 }
202202
@@ -245,8 +245,7 @@ void VideoExample::AsyncProcess()
245245
246246 if (!m_isTrackerInitialized)
247247 {
248- cv::UMat ufirst = frameInfo.m_frames [0 ].getUMat (cv::ACCESS_READ);
249- m_isTrackerInitialized = InitTracker (ufirst);
248+ m_isTrackerInitialized = InitTracker (frameInfo.m_frames [0 ].GetUMatBGR ());
250249 if (!m_isTrackerInitialized)
251250 {
252251 std::cerr << " CaptureAndDetect: Tracker initialize error!!!" << std::endl;
@@ -269,14 +268,14 @@ void VideoExample::AsyncProcess()
269268 int key = 0 ;
270269 for (size_t i = 0 ; i < m_batchSize; ++i)
271270 {
272- DrawData (frameInfo.m_frames [i], framesCounter, currTime);
271+ DrawData (frameInfo.m_frames [i]. GetMatBGR () , framesCounter, currTime);
273272
274- WriteFrame (writer, frameInfo.m_frames [i]);
273+ WriteFrame (writer, frameInfo.m_frames [i]. GetMatBGR () );
275274
276275 ++framesCounter;
277276
278277#ifndef SILENT_WORK
279- cv::imshow (" Video" , frameInfo.m_frames [0 ]);
278+ cv::imshow (" Video" , frameInfo.m_frames [0 ]. GetMatBGR () );
280279
281280 int waitTime = manualMode ? 0 : 1 ;// std::max<int>(1, cvRound(1000 / m_fps - currTime));
282281 key = cv::waitKey (waitTime);
@@ -360,7 +359,7 @@ void VideoExample::CaptureAndDetect(VideoExample* thisPtr, std::atomic<bool>& st
360359
361360 for (size_t i = 1 ; i < frameInfo.m_batchSize ; ++i)
362361 {
363- capture >> frameInfo.m_frames [i];
362+ capture >> frameInfo.m_frames [i]. GetMatBGRWrite () ;
364363 if (frameInfo.m_frames [i].empty ())
365364 {
366365 std::cerr << " CaptureAndDetect: frame is empty!" << std::endl;
@@ -376,8 +375,7 @@ void VideoExample::CaptureAndDetect(VideoExample* thisPtr, std::atomic<bool>& st
376375
377376 if (!thisPtr->m_isDetectorInitialized )
378377 {
379- cv::UMat ufirst = frameInfo.m_frames [0 ].getUMat (cv::ACCESS_READ);
380- thisPtr->m_isDetectorInitialized = thisPtr->InitDetector (ufirst);
378+ thisPtr->m_isDetectorInitialized = thisPtr->InitDetector (frameInfo.m_frames [0 ].GetUMatBGR ());
381379 if (!thisPtr->m_isDetectorInitialized )
382380 {
383381 std::cerr << " CaptureAndDetect: Detector initialize error!!!" << std::endl;
@@ -409,30 +407,21 @@ void VideoExample::CaptureAndDetect(VideoExample* thisPtr, std::atomic<bool>& st
409407// /
410408void VideoExample::Detection (FrameInfo& frame)
411409{
412- cv::UMat uframe;
410+ for (const auto & track : m_tracks)
411+ {
412+ if (track.m_isStatic )
413+ m_detector->ResetModel (frame.m_frames [0 ].GetUMatBGR (), track.m_rrect .boundingRect ());
414+ }
413415
416+ std::vector<cv::UMat> frames;
414417 for (size_t i = 0 ; i < frame.m_frames .size (); ++i)
415418 {
416- if (!m_detector->CanGrayProcessing ())
417- uframe = frame.m_frames [i].getUMat (cv::ACCESS_READ);
418- else
419- cv::cvtColor (frame.m_frames [i], uframe, cv::COLOR_BGR2GRAY);
420-
421- if (i == 0 )
422- {
423- for (const auto & track : m_tracks)
424- {
425- if (track.m_isStatic )
426- m_detector->ResetModel (uframe, track.m_rrect .boundingRect ());
427- }
428- }
429-
430- m_detector->Detect (uframe);
431-
432- const regions_t & regs = m_detector->GetDetects ();
433-
434- frame.m_regions [i].assign (std::begin (regs), std::end (regs));
419+ if (m_detector->CanGrayProcessing ())
420+ frames.emplace_back (frame.m_frames [i].GetUMatGray ());
421+ else
422+ frames.emplace_back (frame.m_frames [i].GetUMatBGR ());
435423 }
424+ m_detector->Detect (frames, frame.m_regions );
436425}
437426
438427// /
@@ -442,16 +431,12 @@ void VideoExample::Detection(FrameInfo& frame)
442431// /
443432void VideoExample::Tracking (FrameInfo& frame)
444433{
445- cv::UMat uframe;
446-
447434 for (size_t i = 0 ; i < frame.m_frames .size (); ++i)
448435 {
449436 if (m_tracker->CanColorFrameToTrack ())
450- uframe = frame.m_frames [i].getUMat (cv::ACCESS_READ );
437+ m_tracker-> Update (frame. m_regions [i], frame.m_frames [i].GetUMatBGR (), m_fps );
451438 else
452- cv::cvtColor (frame.m_frames [i], uframe, cv::COLOR_BGR2GRAY);
453-
454- m_tracker->Update (frame.m_regions [i], uframe, m_fps);
439+ m_tracker->Update (frame.m_regions [i], frame.m_frames [i].GetUMatGray (), m_fps);
455440 }
456441}
457442
0 commit comments