Improved robustness of videobuffer

This commit is contained in:
Matt Hill
2014-07-03 15:34:12 -04:00
parent 8af784840e
commit cf7addab56

View File

@@ -21,6 +21,7 @@
void imageCollectionThread(void* arg); void imageCollectionThread(void* arg);
void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher);
VideoBuffer::VideoBuffer() VideoBuffer::VideoBuffer()
@@ -102,6 +103,27 @@ void imageCollectionThread(void* arg)
cv::VideoCapture cap=cv::VideoCapture(); cv::VideoCapture cap=cv::VideoCapture();
cap.open(dispatcher->mjpeg_url); cap.open(dispatcher->mjpeg_url);
getALPRImages(cap, dispatcher);
}
catch (const std::runtime_error& error)
{
// Error occured while trying to gather image. Retry, don't exit.
std::cerr << "VideoBuffer exception: " << error.what() << std::endl;
}
// Delay 1 second
usleep(1000000);
}
}
// Continuously grabs images from the video capture. If there is an error,
// it returns so that the video capture can be recreated.
void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher)
{
cv::Mat frame; cv::Mat frame;
while (dispatcher->active) while (dispatcher->active)
@@ -114,16 +136,23 @@ void imageCollectionThread(void* arg)
try try
{ {
hasImage = cap.read(frame); hasImage = cap.read(frame);
dispatcher->setLatestFrame(&frame);
}
catch (int e)
{
// Error occured while trying to gather image. Retry, don't exit.
std::cerr << "Exception happened " << e << std::endl;
}
// Double check the image to make sure it's valid. // Double check the image to make sure it's valid.
if (frame.cols == 0 || frame.rows == 0) if (frame.cols == 0 || frame.rows == 0)
hasImage = false; {
dispatcher->mMutex.unlock();
return;
}
dispatcher->setLatestFrame(&frame);
}
catch (const std::runtime_error& error)
{
// Error occured while trying to gather image. Retry, don't exit.
std::cerr << "Exception happened " << error.what() << std::endl;
dispatcher->mMutex.unlock();
return;
}
dispatcher->mMutex.unlock(); dispatcher->mMutex.unlock();
@@ -139,15 +168,3 @@ void imageCollectionThread(void* arg)
usleep(100000); usleep(100000);
} }
} }
catch (const std::runtime_error& error)
{
// Error occured while trying to gather image. Retry, don't exit.
std::cerr << "VideoBuffer exception: " << error.what() << std::endl;
}
// Delay 1 second
usleep(1000000);
}
}