diff --git a/src/common.cpp b/src/common.cpp index 818d775..ede1a72 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -224,7 +224,6 @@ bool rdConf(shared_t *share) share->vidExt = "mp4"; share->recLoopWait = false; share->skipCmd = false; - share->stat = string(); share->network = dnn::readNet("/etc/mow/yolov5s.onnx"); share->classNames = loadClassList(); @@ -263,6 +262,8 @@ bool rdConf(shared_t *share) remove_all(share->buffDir.c_str()); share->init = false; + + new thread(statFifo, share); } new thread(enforceMaxDays, share); @@ -334,3 +335,25 @@ string parseForParam(const string &arg, int argc, char** argv, bool argOnly) return string(); } + +void statFifo(shared_t *share) +{ + createDirTree(cleanDir(share->buffDir)); + + auto path = string(cleanDir(share->buffDir) + "/stat"); + auto newLine = string("\n"); + + if (!fileExists(path)) + { + mkfifo(path.c_str(), 0666); + } + + while (true) + { + auto fd = open(path.c_str(), O_WRONLY); + + write(fd, newLine.c_str(), newLine.size() + 1); + write(fd, share->stat.c_str(), share->stat.size() + 1); + close(fd); + } +} diff --git a/src/common.h b/src/common.h index a960dcd..af983e5 100644 --- a/src/common.h +++ b/src/common.h @@ -19,13 +19,15 @@ #include #include #include -#include #include #include #include #include #include #include +#include +#include +#include #include #include @@ -35,7 +37,7 @@ using namespace std; using namespace std::filesystem; #define BUF_SZ 10 -#define APP_VER "1.4.t5" +#define APP_VER "1.4.t6" struct shared_t { @@ -77,6 +79,7 @@ void replaceAll(string &str, const string &from, const string &to); void enforceMaxDays(shared_t *share); void rdLine(const string ¶m, const string &line, string *value); void rdLine(const string ¶m, const string &line, int *value); +void statFifo(shared_t *share); bool rdConf(shared_t *share); bool capPair(Mat &prev, Mat &next, VideoCapture &capture, shared_t *share); Mat toGray(const Mat &src); diff --git a/src/main.cpp b/src/main.cpp index d787802..98b8f5f 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,6 +28,8 @@ void detectLoop(shared_t *share) auto fullPath = cleanDir(share->buffDir) + "/" + bufFiles[0]; + share->stat.clear(); + if (moDetect(fullPath, &blockArea, &blockImg, share)) { if (objectInImage(blockImg, blockArea, share)) @@ -72,12 +74,6 @@ void recLoop(shared_t *share) th2.join(); - ofstream file(string(cleanDir(share->buffDir) + "/stat").c_str()); - - file << share->stat; - - file.close(); - if (!share->skipCmd) { system(share->postCmd.c_str()); diff --git a/src/mo_detect.cpp b/src/mo_detect.cpp index 950182c..c8c7f1a 100644 --- a/src/mo_detect.cpp +++ b/src/mo_detect.cpp @@ -58,7 +58,7 @@ void secDiff(const Mat &imgA, const Mat &imgB, int rows, int cols, int rowOffs, results->push_back(res); } -bool imgDiff(Mat prev, Mat next, Rect *block, shared_t *share) +bool imgDiff(const Mat &prev, const Mat &next, Rect *block, shared_t *share) { auto moInBlock = false; @@ -90,16 +90,13 @@ bool imgDiff(Mat prev, Mat next, Rect *block, shared_t *share) // the block with the highest amount of pixDiff. auto x = results[i].x; auto y = results[i].y; - auto xSz = results[i].xSize; - auto ySz = results[i].ySize; auto diff = results[i].pixDiff; - share->stat += "block_thread:" - + string(" x=") + to_string(x) - + " y=" + to_string(y) - + " x_len=" + to_string(xSz) - + " y_len=" + to_string(ySz) - + " pixdiff=" + to_string(diff) + "\n"; + share->stat += string("block_thread:") + + " x=" + to_string(x) + + " y=" + to_string(y) + + " pixdiff=" + to_string(diff) + + "\n"; if ((results[i].pixDiff >= share->blockThresh) && (results[i].pixDiff > maxPixDiff)) { @@ -137,7 +134,7 @@ bool moDetect(const string &buffFile, Rect *block, Mat *img, shared_t *share) Mat prev; Mat next; - share->stat += "motion_detection -- clip_file - " + buffFile + "\n"; + share->stat += "motion_detection-- clip_file - " + buffFile + "\n"; for (auto i = 0; capPair(prev, next, capture, share); ++i) { diff --git a/src/mo_detect.h b/src/mo_detect.h index 8a92550..aa8a979 100644 --- a/src/mo_detect.h +++ b/src/mo_detect.h @@ -26,7 +26,7 @@ struct sec_t void secDiff(const Mat &imgA, const Mat &imgB, int rows, int cols, int rowOffs, int colOffs, vector *results, mutex *secMutex, shared_t *share); bool pixDiff(const uchar &pixA, const uchar &pixB, shared_t *share); -bool imgDiff(Mat prev, Mat next, Rect *block, shared_t *share); +bool imgDiff(const Mat &prev, const Mat &next, Rect *block, shared_t *share); bool moDetect(const string &buffFile, Rect *block, Mat *img, shared_t *share); #endif // MO_DETECT_H