2022-09-22 20:57:46 -04:00
|
|
|
#ifndef COMMON_H
|
|
|
|
#define COMMON_H
|
|
|
|
|
|
|
|
// This file is part of Motion Watch.
|
|
|
|
|
|
|
|
// Motion Watch is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Motion Watch is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <vector>
|
2023-02-18 21:20:24 -05:00
|
|
|
#include <thread>
|
2022-09-22 20:57:46 -04:00
|
|
|
#include <filesystem>
|
2022-09-29 11:37:10 -04:00
|
|
|
#include <mutex>
|
2022-10-02 09:01:38 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2022-09-22 20:57:46 -04:00
|
|
|
|
|
|
|
#include <opencv4/opencv2/opencv.hpp>
|
|
|
|
#include <opencv4/opencv2/videoio.hpp>
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
|
|
|
using namespace std::filesystem;
|
|
|
|
|
2023-02-18 21:20:24 -05:00
|
|
|
#define APP_VER "1.6.t9"
|
|
|
|
#define APP_NAME "Motion Watch"
|
2022-09-22 20:57:46 -04:00
|
|
|
|
|
|
|
struct shared_t
|
|
|
|
{
|
2023-02-18 21:20:24 -05:00
|
|
|
vector<thread> detThreads;
|
|
|
|
vector<string> conf;
|
|
|
|
ofstream recLogFile;
|
|
|
|
ofstream detLogFile;
|
|
|
|
string recLogPath;
|
|
|
|
string detLogPath;
|
|
|
|
string recordUrl;
|
|
|
|
string outDir;
|
|
|
|
string postCmd;
|
|
|
|
string buffDir;
|
|
|
|
string vidExt;
|
|
|
|
string vidCodec;
|
|
|
|
string camName;
|
|
|
|
string webBg;
|
|
|
|
string webTxt;
|
|
|
|
string webFont;
|
|
|
|
string webRoot;
|
|
|
|
bool init;
|
|
|
|
bool skipCmd;
|
|
|
|
int clipLen;
|
|
|
|
int frameGap;
|
|
|
|
int pixThresh;
|
|
|
|
int imgThresh;
|
|
|
|
int numOfClips;
|
|
|
|
int maxDays;
|
|
|
|
int maxClips;
|
|
|
|
int maxLogSize;
|
|
|
|
int retCode;
|
2023-02-07 23:19:41 -05:00
|
|
|
};
|
|
|
|
|
2022-09-22 20:57:46 -04:00
|
|
|
string genDstFile(const string &dirOut, const char *fmt, const string &ext);
|
|
|
|
string genTimeStr(const char *fmt);
|
|
|
|
string cleanDir(const string &path);
|
2023-02-12 15:04:32 -05:00
|
|
|
string parseForParam(const string &arg, int argc, char** argv, bool argOnly, int &offs);
|
2022-09-22 20:57:46 -04:00
|
|
|
string parseForParam(const string &arg, int argc, char** argv, bool argOnly);
|
|
|
|
bool createDir(const string &dir);
|
|
|
|
bool createDirTree(const string &full_path);
|
2022-12-04 15:13:39 -05:00
|
|
|
void enforceMaxDays(const string &dirPath, shared_t *share);
|
|
|
|
void enforceMaxClips(const string &dirPath, shared_t *share);
|
2022-09-22 20:57:46 -04:00
|
|
|
void rdLine(const string ¶m, const string &line, string *value);
|
|
|
|
void rdLine(const string ¶m, const string &line, int *value);
|
2023-02-18 21:20:24 -05:00
|
|
|
void statOut(shared_t *share);
|
|
|
|
void waitForDetThreads(shared_t *share);
|
2022-09-22 20:57:46 -04:00
|
|
|
bool rdConf(shared_t *share);
|
2023-02-18 21:20:24 -05:00
|
|
|
vector<string> parseForList(const string &arg, int argc, char** argv);
|
2022-12-04 15:13:39 -05:00
|
|
|
vector<string> lsFilesInDir(const string &path, const string &ext = string());
|
|
|
|
vector<string> lsDirsInDir(const string &path);
|
2022-09-22 20:57:46 -04:00
|
|
|
|
|
|
|
#endif // COMMON_H
|