mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 11:56:52 +08:00
Improved daemon error logging
This commit is contained in:
@@ -5,13 +5,13 @@
|
|||||||
|
|
||||||
#include "daemon/beanstalk.hpp"
|
#include "daemon/beanstalk.hpp"
|
||||||
#include "daemon/uuid.h"
|
#include "daemon/uuid.h"
|
||||||
|
#include "daemon/logging_videobuffer.h"
|
||||||
|
|
||||||
#include "tclap/CmdLine.h"
|
#include "tclap/CmdLine.h"
|
||||||
#include "alpr.h"
|
#include "alpr.h"
|
||||||
#include "openalpr/simpleini/simpleini.h"
|
#include "openalpr/simpleini/simpleini.h"
|
||||||
#include "openalpr/cjson.h"
|
#include "openalpr/cjson.h"
|
||||||
#include "support/tinythread.h"
|
#include "support/tinythread.h"
|
||||||
#include "videobuffer.h"
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include "support/timing.h"
|
#include "support/timing.h"
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ void streamRecognitionThread(void* arg)
|
|||||||
|
|
||||||
int framenum = 0;
|
int framenum = 0;
|
||||||
|
|
||||||
VideoBuffer videoBuffer;
|
LoggingVideoBuffer videoBuffer(logger);
|
||||||
|
|
||||||
videoBuffer.connect(tdata->stream_url, 5);
|
videoBuffer.connect(tdata->stream_url, 5);
|
||||||
|
|
||||||
|
50
src/daemon/logging_videobuffer.h
Normal file
50
src/daemon/logging_videobuffer.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#ifndef OPENALPR_LOGGING_VIDEOBUFFER_H
|
||||||
|
#define OPENALPR_LOGGING_VIDEOBUFFER_H
|
||||||
|
#include "../videobuffer.h"
|
||||||
|
|
||||||
|
#include <log4cplus/logger.h>
|
||||||
|
|
||||||
|
|
||||||
|
class LoggingVideoDispatcher : public VideoDispatcher
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LoggingVideoDispatcher(std::string mjpeg_url, int fps, log4cplus::Logger logger) :
|
||||||
|
VideoDispatcher(mjpeg_url, fps)
|
||||||
|
{
|
||||||
|
this->logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void log_info(std::string message)
|
||||||
|
{
|
||||||
|
LOG4CPLUS_INFO(logger, message);
|
||||||
|
}
|
||||||
|
virtual void log_error(std::string error)
|
||||||
|
{
|
||||||
|
LOG4CPLUS_WARN(logger, error );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
log4cplus::Logger logger;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class LoggingVideoBuffer : public VideoBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LoggingVideoBuffer(log4cplus::Logger logger) : VideoBuffer()
|
||||||
|
{
|
||||||
|
this->logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual VideoDispatcher* createDispatcher(std::string mjpeg_url, int fps)
|
||||||
|
{
|
||||||
|
return new LoggingVideoDispatcher(mjpeg_url, fps, logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
log4cplus::Logger logger;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // OPENALPR_LOGGING_VIDEOBUFFER_H
|
@@ -38,6 +38,10 @@ VideoBuffer::~VideoBuffer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VideoDispatcher* VideoBuffer::createDispatcher(std::string mjpeg_url, int fps)
|
||||||
|
{
|
||||||
|
return new VideoDispatcher(mjpeg_url, fps);
|
||||||
|
}
|
||||||
|
|
||||||
void VideoBuffer::connect(std::string mjpeg_url, int fps)
|
void VideoBuffer::connect(std::string mjpeg_url, int fps)
|
||||||
{
|
{
|
||||||
@@ -62,7 +66,7 @@ void VideoBuffer::connect(std::string mjpeg_url, int fps)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatcher = new VideoDispatcher(mjpeg_url, fps);
|
dispatcher = createDispatcher(mjpeg_url, fps);
|
||||||
|
|
||||||
tthread::thread* t = new tthread::thread(imageCollectionThread, (void*) dispatcher);
|
tthread::thread* t = new tthread::thread(imageCollectionThread, (void*) dispatcher);
|
||||||
|
|
||||||
@@ -103,14 +107,33 @@ void imageCollectionThread(void* arg)
|
|||||||
cv::VideoCapture cap=cv::VideoCapture();
|
cv::VideoCapture cap=cv::VideoCapture();
|
||||||
cap.open(dispatcher->mjpeg_url);
|
cap.open(dispatcher->mjpeg_url);
|
||||||
|
|
||||||
getALPRImages(cap, dispatcher);
|
if (cap.isOpened())
|
||||||
|
{
|
||||||
|
getALPRImages(cap, dispatcher);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Stream " << dispatcher->mjpeg_url << " failed to open.";
|
||||||
|
dispatcher->log_error(ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
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.
|
||||||
std::cerr << "VideoBuffer exception: " << error.what() << std::endl;
|
std::stringstream ss;
|
||||||
|
ss << "VideoBuffer exception: " << error.what();
|
||||||
|
dispatcher->log_error( ss.str() );
|
||||||
}
|
}
|
||||||
|
catch (cv::Exception e)
|
||||||
|
{
|
||||||
|
// OpenCV Exception occured while trying to gather image. Retry, don't exit.
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "VideoBuffer OpenCV exception: " << e.what();
|
||||||
|
dispatcher->log_error( ss.str() );
|
||||||
|
}
|
||||||
|
|
||||||
// Delay 1 second
|
// Delay 1 second
|
||||||
usleep(1000000);
|
usleep(1000000);
|
||||||
|
|
||||||
@@ -137,9 +160,12 @@ void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher)
|
|||||||
{
|
{
|
||||||
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.cols == 0 || frame.rows == 0)
|
if (!frame.data || frame.empty())
|
||||||
{
|
{
|
||||||
dispatcher->mMutex.unlock();
|
dispatcher->mMutex.unlock();
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Stream " << dispatcher->mjpeg_url << " received invalid frame";
|
||||||
|
dispatcher->log_error(ss.str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +174,9 @@ void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher)
|
|||||||
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.
|
||||||
std::cerr << "Exception happened " << error.what() << std::endl;
|
std::stringstream ss;
|
||||||
|
ss << "Exception happened " << error.what();
|
||||||
|
dispatcher->log_error(ss.str());
|
||||||
dispatcher->mMutex.unlock();
|
dispatcher->mMutex.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "opencv2/highgui/highgui.hpp"
|
#include "opencv2/highgui/highgui.hpp"
|
||||||
|
|
||||||
@@ -47,6 +48,15 @@ class VideoDispatcher
|
|||||||
this->latestFrameNumber++;
|
this->latestFrameNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void log_info(std::string message)
|
||||||
|
{
|
||||||
|
std::cout << message << std::endl;
|
||||||
|
}
|
||||||
|
virtual void log_error(std::string error)
|
||||||
|
{
|
||||||
|
std::cerr << error << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
bool active;
|
bool active;
|
||||||
|
|
||||||
int latestFrameNumber;
|
int latestFrameNumber;
|
||||||
@@ -70,12 +80,17 @@ class VideoBuffer
|
|||||||
|
|
||||||
void connect(std::string mjpeg_url, int fps);
|
void connect(std::string mjpeg_url, int fps);
|
||||||
|
|
||||||
|
|
||||||
// If a new frame is available, the function sets "frame" to it and returns the frame number
|
// If a new frame is available, the function sets "frame" to it and returns the frame number
|
||||||
// If no frames are available, or the latest has already been grabbed, returns -1.
|
// If no frames are available, or the latest has already been grabbed, returns -1.
|
||||||
int getLatestFrame(cv::Mat* frame);
|
int getLatestFrame(cv::Mat* frame);
|
||||||
|
|
||||||
void disconnect();
|
void disconnect();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual VideoDispatcher* createDispatcher(std::string mjpeg_url, int fps);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user