mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 23:32:54 +08:00
Merge branch 'Kees-V-master'
This commit is contained in:
@@ -46,7 +46,7 @@ VideoDispatcher* VideoBuffer::createDispatcher(std::string mjpeg_url, int fps)
|
||||
void VideoBuffer::connect(std::string mjpeg_url, int fps)
|
||||
{
|
||||
|
||||
if (hasEnding(mjpeg_url, ".mjpg") == false)
|
||||
if (startsWith(mjpeg_url, "http") && hasEnding(mjpeg_url, ".mjpg") == false)
|
||||
{
|
||||
// The filename doesn't end with ".mjpg" so the downstream processing may not treat it as such
|
||||
// OpenCV doesn't have a way to force the rendering, other than via URL path. So, let's add it to the URL
|
||||
@@ -105,11 +105,13 @@ void imageCollectionThread(void* arg)
|
||||
try
|
||||
{
|
||||
cv::VideoCapture cap=cv::VideoCapture();
|
||||
dispatcher->log_info("Video stream connecting...");
|
||||
cap.open(dispatcher->mjpeg_url);
|
||||
|
||||
if (cap.isOpened())
|
||||
{
|
||||
getALPRImages(cap, dispatcher);
|
||||
dispatcher->log_info("Video stream connected");
|
||||
getALPRImages(cap, dispatcher);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -147,29 +149,29 @@ void imageCollectionThread(void* arg)
|
||||
// it returns so that the video capture can be recreated.
|
||||
void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher)
|
||||
{
|
||||
cv::Mat frame;
|
||||
|
||||
|
||||
while (dispatcher->active)
|
||||
{
|
||||
while (dispatcher->active)
|
||||
{
|
||||
|
||||
dispatcher->mMutex.lock();
|
||||
bool hasImage = false;
|
||||
try
|
||||
{
|
||||
cv::Mat frame;
|
||||
hasImage = cap.read(frame);
|
||||
// Double check the image to make sure it's valid.
|
||||
// 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->setLatestFrame(&frame);
|
||||
dispatcher->mMutex.lock();
|
||||
dispatcher->setLatestFrame(frame);
|
||||
dispatcher->mMutex.unlock();
|
||||
}
|
||||
catch (const std::runtime_error& error)
|
||||
{
|
||||
|
@@ -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