mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 01:42:49 +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)
|
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
|
// 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
|
// 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
|
try
|
||||||
{
|
{
|
||||||
cv::VideoCapture cap=cv::VideoCapture();
|
cv::VideoCapture cap=cv::VideoCapture();
|
||||||
|
dispatcher->log_info("Video stream connecting...");
|
||||||
cap.open(dispatcher->mjpeg_url);
|
cap.open(dispatcher->mjpeg_url);
|
||||||
|
|
||||||
if (cap.isOpened())
|
if (cap.isOpened())
|
||||||
{
|
{
|
||||||
getALPRImages(cap, dispatcher);
|
dispatcher->log_info("Video stream connected");
|
||||||
|
getALPRImages(cap, dispatcher);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -147,29 +149,29 @@ 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;
|
|
||||||
|
|
||||||
while (dispatcher->active)
|
while (dispatcher->active)
|
||||||
{
|
{
|
||||||
while (dispatcher->active)
|
while (dispatcher->active)
|
||||||
{
|
{
|
||||||
|
|
||||||
dispatcher->mMutex.lock();
|
|
||||||
bool hasImage = false;
|
bool hasImage = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
cv::Mat frame;
|
||||||
hasImage = cap.read(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())
|
if (!frame.data || frame.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(frame);
|
||||||
|
dispatcher->mMutex.unlock();
|
||||||
}
|
}
|
||||||
catch (const std::runtime_error& error)
|
catch (const std::runtime_error& error)
|
||||||
{
|
{
|
||||||
|
@@ -31,10 +31,10 @@ class VideoDispatcher
|
|||||||
tthread::lock_guard<tthread::mutex> guard(mMutex);
|
tthread::lock_guard<tthread::mutex> guard(mMutex);
|
||||||
|
|
||||||
if (latestFrameNumber == lastFrameRead)
|
if (latestFrameNumber == lastFrameRead)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
frame->create(latestFrame->size(), latestFrame->type());
|
frame->create(latestFrame.size(), latestFrame.type());
|
||||||
latestFrame->copyTo(*frame);
|
latestFrame.copyTo(*frame);
|
||||||
|
|
||||||
this->lastFrameRead = this->latestFrameNumber;
|
this->lastFrameRead = this->latestFrameNumber;
|
||||||
|
|
||||||
@@ -45,11 +45,10 @@ class VideoDispatcher
|
|||||||
return this->lastFrameRead;
|
return this->lastFrameRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLatestFrame(cv::Mat* frame)
|
void setLatestFrame(cv::Mat frame)
|
||||||
{
|
{
|
||||||
//tthread::lock_guard<tthread::mutex> guard(mMutex);
|
frame.copyTo(this->latestFrame);
|
||||||
this->latestFrame = frame;
|
this->latestRegionsOfInterest = calculateRegionsOfInterest(&this->latestFrame);
|
||||||
this->latestRegionsOfInterest = calculateRegionsOfInterest(frame);
|
|
||||||
|
|
||||||
this->latestFrameNumber++;
|
this->latestFrameNumber++;
|
||||||
}
|
}
|
||||||
@@ -83,7 +82,7 @@ class VideoDispatcher
|
|||||||
tthread::mutex mMutex;
|
tthread::mutex mMutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cv::Mat* latestFrame;
|
cv::Mat latestFrame;
|
||||||
std::vector<cv::Rect> latestRegionsOfInterest;
|
std::vector<cv::Rect> latestRegionsOfInterest;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user