mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 16:27:07 +08:00
Enhancement to video stream input thread
This commit is contained in:
@@ -149,30 +149,36 @@ void imageCollectionThread(void* arg)
|
|||||||
// it returns so that the video capture can be recreated.
|
// it returns so that the video capture can be recreated.
|
||||||
void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher)
|
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)
|
||||||
{
|
{
|
||||||
while (dispatcher->active)
|
while (dispatcher->active)
|
||||||
{
|
{
|
||||||
|
|
||||||
dispatcher->mMutex.lock();
|
|
||||||
bool hasImage = false;
|
bool hasImage = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hasImage = cap.read(frame);
|
if (receiveframeisframe1) receiveframe = &frame1;
|
||||||
// Double check the image to make sure it's valid.
|
else receiveframe = &frame2;
|
||||||
if (!frame.data || frame.empty())
|
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;
|
std::stringstream ss;
|
||||||
ss << "Stream " << dispatcher->mjpeg_url << " received invalid frame";
|
ss << "Stream " << dispatcher->mjpeg_url << " received invalid frame";
|
||||||
dispatcher->log_error(ss.str());
|
dispatcher->log_error(ss.str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatcher->setLatestFrame(&frame);
|
dispatcher->mMutex.lock();
|
||||||
}
|
dispatcher->setLatestFrame(receiveframe);
|
||||||
|
dispatcher->mMutex.unlock();
|
||||||
|
receiveframeisframe1 = !receiveframeisframe1;
|
||||||
|
}
|
||||||
catch (const std::runtime_error& error)
|
catch (const std::runtime_error& error)
|
||||||
{
|
{
|
||||||
// Error occured while trying to gather image. Retry, don't exit.
|
// Error occured while trying to gather image. Retry, don't exit.
|
||||||
|
Reference in New Issue
Block a user