From 686743484cd903b60e4f508577704b0200ad28b3 Mon Sep 17 00:00:00 2001 From: Kees-V Date: Sat, 25 Oct 2014 14:22:50 +0200 Subject: [PATCH 1/4] Revert "Only lock when needed." This reverts commit 1c20855f29274068d9d0570b2df776ac423445ea. --- src/video/videobuffer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/video/videobuffer.cpp b/src/video/videobuffer.cpp index cdaec56..9994874 100644 --- a/src/video/videobuffer.cpp +++ b/src/video/videobuffer.cpp @@ -156,6 +156,7 @@ void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher) while (dispatcher->active) { + dispatcher->mMutex.lock(); bool hasImage = false; try { @@ -163,16 +164,15 @@ void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher) // Double check the image to make sure it's valid. if (!frame.data || frame.empty()) { + dispatcher->mMutex.unlock(); std::stringstream ss; ss << "Stream " << dispatcher->mjpeg_url << " received invalid frame"; dispatcher->log_error(ss.str()); return; } - dispatcher->mMutex.lock(); dispatcher->setLatestFrame(&frame); - dispatcher->mMutex.unlock(); - } + } catch (const std::runtime_error& error) { // Error occured while trying to gather image. Retry, don't exit. From 528b548b11a8467068c214e4dff32a2bdbb1023d Mon Sep 17 00:00:00 2001 From: Kees-V Date: Sun, 26 Oct 2014 10:56:09 +0100 Subject: [PATCH 2/4] Enhancement to video stream input thread --- src/video/videobuffer.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/video/videobuffer.cpp b/src/video/videobuffer.cpp index 9994874..aeff204 100644 --- a/src/video/videobuffer.cpp +++ b/src/video/videobuffer.cpp @@ -149,30 +149,36 @@ void imageCollectionThread(void* arg) // it returns so that the video capture can be recreated. void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher) { - cv::Mat frame; - + cv::Mat frame1; + cv::Mat frame2; + cv::Mat* receiveframe; + BOOLEAN receiveframeisframe1 = TRUE; + while (dispatcher->active) { while (dispatcher->active) { - dispatcher->mMutex.lock(); bool hasImage = false; try { - hasImage = cap.read(frame); - // Double check the image to make sure it's valid. - if (!frame.data || frame.empty()) + if (receiveframeisframe1) receiveframe = &frame1; + else receiveframe = &frame2; + hasImage = cap.read(*receiveframe); + // Double check the image to make sure it's valid. + if (!(*receiveframe).data || (*receiveframe).empty()) { - dispatcher->mMutex.unlock(); std::stringstream ss; ss << "Stream " << dispatcher->mjpeg_url << " received invalid frame"; dispatcher->log_error(ss.str()); return; } - dispatcher->setLatestFrame(&frame); - } + dispatcher->mMutex.lock(); + dispatcher->setLatestFrame(receiveframe); + dispatcher->mMutex.unlock(); + receiveframeisframe1 = !receiveframeisframe1; + } catch (const std::runtime_error& error) { // Error occured while trying to gather image. Retry, don't exit. From f1e5e7932ccbe3f962ee02714368f8a8d06f4361 Mon Sep 17 00:00:00 2001 From: Kees-V Date: Sun, 26 Oct 2014 11:13:14 +0100 Subject: [PATCH 3/4] Changed BOOLEAN to bool --- src/video/videobuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/videobuffer.cpp b/src/video/videobuffer.cpp index aeff204..831a85c 100644 --- a/src/video/videobuffer.cpp +++ b/src/video/videobuffer.cpp @@ -152,7 +152,7 @@ void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher) cv::Mat frame1; cv::Mat frame2; cv::Mat* receiveframe; - BOOLEAN receiveframeisframe1 = TRUE; + bool receiveframeisframe1 = TRUE; while (dispatcher->active) { From 77e308904cf075eb6ad9b963ed6263fe689c3095 Mon Sep 17 00:00:00 2001 From: Kees-V Date: Sun, 26 Oct 2014 11:22:29 +0100 Subject: [PATCH 4/4] Travis Cl build: changed TRUE to true --- src/video/videobuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video/videobuffer.cpp b/src/video/videobuffer.cpp index 831a85c..2b256ee 100644 --- a/src/video/videobuffer.cpp +++ b/src/video/videobuffer.cpp @@ -152,7 +152,7 @@ void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher) cv::Mat frame1; cv::Mat frame2; cv::Mat* receiveframe; - bool receiveframeisframe1 = TRUE; + bool receiveframeisframe1 = true; while (dispatcher->active) {