25#include <opencv2/opencv.hpp>
29 static std::string dir;
37 if (
o[
"History dir"] != std::string(
""))
38 dir =
o[
"History dir"];
42 dir = l[
"History dir"];
52 if (dir.back() !=
'/')
76 if (!
stat(dir.c_str(), &
sb))
93 cv::VideoCapture*
cap =
new cv::VideoCapture();
100 std::this_thread::sleep_for(std::chrono::milliseconds(20));
115 for (
unsigned i=0 ;
i<
flist.size() ;
i++) {
116 std::string filename =
flist[
i];
118 sscanf(filename.c_str(),
"%2d%2d%2d_%2d%2d%2d", &
ti.tm_year, &
ti.tm_mon,
119 &
ti.tm_mday, &
ti.tm_hour, &
ti.tm_min, &
ti.tm_sec);
125 if (
age >=
o[
"Storage hours"]) {
126 std::string
pathname = (path+
"/"+filename);
141 if (
ss_time() >=
o[
"Last fetch"] +
o[
"Period"]) {
143 std::string
url =
o[
"URL"];
146 if (
url.compare(0,7,
"rtsp://") == 0) {
149 if (!
cap->isOpened() ) {
151 if (!
cap->open(
url.c_str())) {
152 std::cout <<
"Unable to open video capture\n";
154 std::string error =
"Cannot connect to camera \"" +
name +
"\" at " +
url +
", please check camera power and URL";
157 cm_msg(
MERROR,
"image_history_rtsp",
"More than 10 failed connections, I will stop reporting this error");
166 std::string error =
"Cannot connect to camera \"" +
name +
"\". mlogger not build with rtsp support (OpenCV)";
171 std::string
dotname = filename;
183 std::setfill(
'0') << std::setw(2) <<
ltm.tm_year - 100 <<
184 std::setfill(
'0') << std::setw(2) <<
ltm.tm_mon + 1 <<
185 std::setfill(
'0') << std::setw(2) <<
ltm.tm_mday <<
187 std::setfill(
'0') << std::setw(2) <<
ltm.tm_hour <<
188 std::setfill(
'0') << std::setw(2) <<
ltm.tm_min <<
189 std::setfill(
'0') << std::setw(2) <<
ltm.tm_sec;
190 filename +=
"/" + s.str();
193 if (
o[
"Extension"] == std::string(
"")) {
194 filename +=
url.substr(
url.find_last_of(
'.'));
197 filename +=
o[
"Extension"];
204 bool OK =
cap->grab();
206 std::string error =
"Cannot grab from camera \"" +
name +
"\" at " +
url +
", please check camera power and URL";
207 cm_msg(
MERROR,
"log_image_history",
"%s", error.c_str());
210 cap =
new cv::VideoCapture();
216 std::string error =
"Recieved empty frame from camera \"" +
name;
217 cm_msg(
MERROR,
"log_image_history",
"%s", error.c_str());
220 cap =
new cv::VideoCapture();
224 cv::imwrite(filename, frame);
239 error =
"Cannot connect to camera \"" +
name +
"\" at " +
url +
", please check camera power and URL";
241 error =
"Error fetching image from camera \"" +
name +
"\", curl status " + std::to_string(
status);
246 error =
"Error fetching image from camera \"" +
name +
"\", http error status " +
249 if (!error.empty()) {
250 if (
ss_time() >
o[
"Last error"] +
o[
"Error interval (s)"]) {
251 cm_msg(
MERROR,
"log_image_history",
"%s", error.c_str());
293 {
"Name",
"Demo Camera"},
295 {
"URL",
"https://localhost:8000/image.jpg"},
296 {
"Extension",
".jpg"},
299 {
"Storage hours", 0},
300 {
"Error interval (s)", 60},
306 std::string
name =
ic.get_odb().get_name();
307 if (
name !=
"Demo" ||
c[
"Enabled"] ==
true)
345 std::setfill(
'0') << std::setw(2) <<
ltm.tm_year - 100 <<
346 std::setfill(
'0') << std::setw(2) <<
ltm.tm_mon + 1 <<
347 std::setfill(
'0') << std::setw(2) <<
ltm.tm_mday <<
357 mask =
"??????_??????.*";
360 std::setfill(
'0') << std::setw(2) <<
ltStart.tm_year - 100 <<
361 std::setfill(
'0') << std::setw(2) <<
ltStart.tm_mon + 1 <<
362 std::setfill(
'0') << std::setw(2) <<
ltStart.tm_mday <<
364 std::setfill(
'0') << std::setw(2) <<
ltStart.tm_hour <<
365 std::setfill(
'0') << std::setw(2) <<
ltStart.tm_min <<
366 std::setfill(
'0') << std::setw(2) <<
ltStart.tm_sec;
369 std::setfill(
'0') << std::setw(2) <<
ltStop.tm_year - 100 <<
370 std::setfill(
'0') << std::setw(2) <<
ltStop.tm_mon + 1 <<
371 std::setfill(
'0') << std::setw(2) <<
ltStop.tm_mday <<
373 std::setfill(
'0') << std::setw(2) <<
ltStop.tm_hour <<
374 std::setfill(
'0') << std::setw(2) <<
ltStop.tm_min <<
375 std::setfill(
'0') << std::setw(2) <<
ltStop.tm_sec;
377 for (
int i=0 ;
i<13 ;
i++) {
392 std::sort(
vfn.begin(),
vfn.end());
398 for (
unsigned i=0 ;
i<
vfn.size() ;
i++) {
401 &
ti.tm_mday, &
ti.tm_hour, &
ti.tm_min, &
ti.tm_sec);
static bool exists(const std::string &name)
static int create(const char *name, int type=TID_KEY)
bool is_subkey(std::string str)
void connect(const std::string &path, const std::string &name, bool write_defaults, bool delete_keys_not_in_defaults=false)
std::string cm_get_path()
time_t ss_mktime(struct tm *tms)
INT ss_file_find(const char *path, const char *pattern, char **plist)
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
std::string history_dir()
void stop_image_history()
int hs_image_retrieve(std::string image_name, time_t start_time, time_t stop_time, std::vector< time_t > &vtime, std::vector< std::string > &vfilename)
int get_number_image_history_threads()
void start_image_history()
volatile int stop_all_threads
static std::string join(const char *sep, const std::vector< std::string > &v)
std::vector< std::string > STRING_LIST
static std::string remove(const std::string s, char c)
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)