Skip to content

Commit 7916e1a

Browse files
committed
Correct exit from process in AsyncDetector
1 parent d15eea7 commit 7916e1a

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
build
2-
CMakeLists.txt.user
2+
CMakeLists.txt.user*
33

async_detector/AsyncDetector.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ void AsyncDetector::Process()
5151
bool stopFlag = false;
5252

5353
std::thread thCapture(CaptureThread, m_inFile, m_startFrame, &m_fps, &m_framesQue, &stopFlag);
54-
thCapture.detach();
5554

5655
cv::namedWindow("Video", cv::WINDOW_NORMAL | cv::WINDOW_KEEPRATIO);
5756

@@ -308,9 +307,7 @@ void AsyncDetector::CaptureThread(std::string fileName, int startFrame, float* f
308307
cv::cvtColor(firstFrame, firstGray, cv::COLOR_BGR2GRAY);
309308

310309
std::thread thDetection(DetectThread, detectorConfig, firstGray, framesQue, stopFlag);
311-
thDetection.detach();
312310
std::thread thTracking(TrackingThread, trackerSettings, framesQue, stopFlag);
313-
thTracking.detach();
314311

315312
// Capture frame
316313
for (; !(*stopFlag);)
@@ -322,6 +319,7 @@ void AsyncDetector::CaptureThread(std::string fileName, int startFrame, float* f
322319
{
323320
std::cerr << "Frame is empty!" << std::endl;
324321
*stopFlag = true;
322+
framesQue->SetBreak(true);
325323
break;
326324
}
327325
if (frameInfo->m_clFrame.empty())
@@ -335,14 +333,14 @@ void AsyncDetector::CaptureThread(std::string fileName, int startFrame, float* f
335333
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / cvRound(*fps)));
336334
}
337335

338-
if (thDetection.joinable())
339-
{
340-
thDetection.join();
341-
}
342336
if (thTracking.joinable())
343337
{
344338
thTracking.join();
345339
}
340+
if (thDetection.joinable())
341+
{
342+
thDetection.join();
343+
}
346344
}
347345

348346
///

async_detector/Queue.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,11 @@ class FramesQueue : public SafeQueue<frame_ptr>
262262
//QUE_LOG << "Signal end: " << ts << std::endl;
263263
}
264264

265+
void SetBreak(bool val)
266+
{
267+
m_break = val;
268+
}
269+
265270
private:
271+
bool m_break = false;
266272
};

example/VideoExample.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ void VideoExample::Process()
9090

9191
Gate trackLock;
9292
std::thread thCapDet(CaptureAndDetect, this, &stopCapture, &frameLock, &trackLock);
93-
thCapDet.detach();
9493

9594
{
9695
if (!frameLock.WaitAtGateUntil(m_captureTimeOut))

0 commit comments

Comments
 (0)