Added better support for mjpeg.

When an http:// or https:// URL is provided, assume MJPEG and pass the correct values into OpenCV
Added a VideoBuffer class that pulls the latest images in a background thread.
This commit is contained in:
Matt Hill
2014-05-18 16:35:38 -05:00
parent 0751720d95
commit 5333b8628c
4 changed files with 264 additions and 1 deletions

View File

@@ -22,6 +22,7 @@
#include <iostream>
#include <iterator>
#include <algorithm>
#include <signal.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
@@ -29,6 +30,7 @@
#include "tclap/CmdLine.h"
#include "support/filesystem.h"
#include "support/timing.h"
#include "videobuffer.h"
#include "alpr.h"
const std::string MAIN_WINDOW_NAME = "ALPR main window";
@@ -38,9 +40,14 @@ const std::string LAST_VIDEO_STILL_LOCATION = "/tmp/laststill.jpg";
/** Function Headers */
bool detectandshow(Alpr* alpr, cv::Mat frame, std::string region, bool writeJson);
void sighandler(int sig);
bool measureProcessingTime = false;
// This boolean is set to false when the user hits terminates (e.g., CTRL+C )
// so we can end infinite loops for things like video processing.
bool program_active = true;
int main( int argc, const char** argv )
{
std::string filename;
@@ -100,6 +107,18 @@ int main( int argc, const char** argv )
return 1;
}
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = sighandler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGHUP, &sigIntHandler, NULL);
sigaction(SIGINT, &sigIntHandler, NULL);
sigaction(SIGQUIT, &sigIntHandler, NULL);
sigaction(SIGKILL, &sigIntHandler, NULL);
sigaction(SIGTERM, &sigIntHandler, NULL);
//sigaction(SIGABRT, &sigIntHandler, NULL);
cv::Mat frame;
@@ -152,6 +171,32 @@ int main( int argc, const char** argv )
framenum++;
}
}
else if (startsWith(filename, "http://") || startsWith(filename, "https://"))
{
int framenum = 0;
VideoBuffer videoBuffer;
videoBuffer.connect(filename, 5);
cv::Mat latestFrame;
while (program_active)
{
int response = videoBuffer.getLatestFrame(&latestFrame);
if (response != -1)
{
detectandshow( &alpr, latestFrame, "", outputJson);
}
cv::waitKey(10);
}
videoBuffer.disconnect();
std::cout << "Video processing ended" << std::endl;
}
else if (hasEnding(filename, ".avi") || hasEnding(filename, ".mp4") || hasEnding(filename, ".webm") || hasEnding(filename, ".flv"))
{
if (fileExists(filename.c_str()))
@@ -227,6 +272,14 @@ int main( int argc, const char** argv )
return 0;
}
void sighandler(int sig)
{
program_active = false;
//std::cout << "Sig handler caught " << sig << std::endl;
}
bool detectandshow( Alpr* alpr, cv::Mat frame, std::string region, bool writeJson)
{
std::vector<uchar> buffer;