switched over the stat text from a regular file to a fifo file.
This commit is contained in:
Maurice ONeal 2022-10-02 09:01:38 -04:00
parent c7a1dd3c84
commit 1e72107ff0
5 changed files with 39 additions and 20 deletions

View File

@ -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);
}
}

View File

@ -19,13 +19,15 @@
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
#include <vector>
#include <thread>
#include <dirent.h>
#include <filesystem>
#include <mutex>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <opencv4/opencv2/opencv.hpp>
#include <opencv4/opencv2/videoio.hpp>
@ -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 &param, const string &line, string *value);
void rdLine(const string &param, 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);

View File

@ -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());

View File

@ -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)
{

View File

@ -26,7 +26,7 @@ struct sec_t
void secDiff(const Mat &imgA, const Mat &imgB, int rows, int cols, int rowOffs, int colOffs, vector<sec_t> *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