mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 19:32:45 +08:00
Simplified videobuffer usage by copying all the buffer data -- reduces chances of memory issues across threads.
This commit is contained in:
@@ -149,10 +149,6 @@ void imageCollectionThread(void* arg)
|
||||
// it returns so that the video capture can be recreated.
|
||||
void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher)
|
||||
{
|
||||
cv::Mat frame1;
|
||||
cv::Mat frame2;
|
||||
cv::Mat* receiveframe;
|
||||
bool receiveframeisframe1 = true;
|
||||
|
||||
while (dispatcher->active)
|
||||
{
|
||||
@@ -162,11 +158,10 @@ void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher)
|
||||
bool hasImage = false;
|
||||
try
|
||||
{
|
||||
if (receiveframeisframe1) receiveframe = &frame1;
|
||||
else receiveframe = &frame2;
|
||||
hasImage = cap.read(*receiveframe);
|
||||
cv::Mat frame;
|
||||
hasImage = cap.read(frame);
|
||||
// Double check the image to make sure it's valid.
|
||||
if (!(*receiveframe).data || (*receiveframe).empty())
|
||||
if (!frame.data || frame.empty())
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Stream " << dispatcher->mjpeg_url << " received invalid frame";
|
||||
@@ -175,10 +170,9 @@ void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher)
|
||||
}
|
||||
|
||||
dispatcher->mMutex.lock();
|
||||
dispatcher->setLatestFrame(receiveframe);
|
||||
dispatcher->setLatestFrame(frame);
|
||||
dispatcher->mMutex.unlock();
|
||||
receiveframeisframe1 = !receiveframeisframe1;
|
||||
}
|
||||
}
|
||||
catch (const std::runtime_error& error)
|
||||
{
|
||||
// Error occured while trying to gather image. Retry, don't exit.
|
||||
|
@@ -31,10 +31,10 @@ class VideoDispatcher
|
||||
tthread::lock_guard<tthread::mutex> guard(mMutex);
|
||||
|
||||
if (latestFrameNumber == lastFrameRead)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
frame->create(latestFrame->size(), latestFrame->type());
|
||||
latestFrame->copyTo(*frame);
|
||||
frame->create(latestFrame.size(), latestFrame.type());
|
||||
latestFrame.copyTo(*frame);
|
||||
|
||||
this->lastFrameRead = this->latestFrameNumber;
|
||||
|
||||
@@ -45,11 +45,10 @@ class VideoDispatcher
|
||||
return this->lastFrameRead;
|
||||
}
|
||||
|
||||
void setLatestFrame(cv::Mat* frame)
|
||||
void setLatestFrame(cv::Mat frame)
|
||||
{
|
||||
//tthread::lock_guard<tthread::mutex> guard(mMutex);
|
||||
this->latestFrame = frame;
|
||||
this->latestRegionsOfInterest = calculateRegionsOfInterest(frame);
|
||||
frame.copyTo(this->latestFrame);
|
||||
this->latestRegionsOfInterest = calculateRegionsOfInterest(&this->latestFrame);
|
||||
|
||||
this->latestFrameNumber++;
|
||||
}
|
||||
@@ -83,7 +82,7 @@ class VideoDispatcher
|
||||
tthread::mutex mMutex;
|
||||
|
||||
private:
|
||||
cv::Mat* latestFrame;
|
||||
cv::Mat latestFrame;
|
||||
std::vector<cv::Rect> latestRegionsOfInterest;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user