JustMotion/src/common.h
2023-05-17 19:40:09 +00:00

112 lines
2.9 KiB
C++

#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 <QCoreApplication>
#include <QProcess>
#include <QTextStream>
#include <QObject>
#include <QRegularExpression>
#include <QDir>
#include <QCryptographicHash>
#include <QFile>
#include <QDateTime>
#include <QThread>
#include <opencv4/opencv2/opencv.hpp>
#include <opencv4/opencv2/videoio.hpp>
using namespace cv;
using namespace std;
#define APP_VER "3.0.t2"
#define APP_NAME "Motion Watch"
#define APP_BIN "mow"
#define REC_LOG_NAME "rec_log_lines.html"
#define DET_LOG_NAME "det_log_lines.html"
#define UPK_LOG_NAME "upk_log_lines.html"
struct evt_t
{
QString evName;
QStringList srcPaths;
Mat thumbnail;
};
struct shared_t
{
QList<evt_t> recList;
evt_t curEvent;
QString conf;
QString recLog;
QString detLog;
QString upkLog;
QString recordUrl;
QString outDir;
QString postCmd;
QString camName;
QString webBg;
QString webTxt;
QString webFont;
QString webRoot;
bool skipCmd;
int frameGap;
int evMaxSecs;
int postSecs;
int maxScore;
int procCnt;
int hlsCnt;
int pixThresh;
int imgThresh;
int maxEvents;
int maxLogSize;
int retCode;
int postInd;
int evInd;
};
QByteArray genMD5(const QString &path);
QByteArray genMD5(const QByteArray &bytes);
QString getParam(const QString &key, const QStringList &args);
QStringList lsFilesInDir(const QString &path, const QString &ext = QString());
QStringList lsDirsInDir(const QString &path);
bool rdConf(const QString &filePath, shared_t *share);
bool rdConf(shared_t *share);
void rdLine(const QString &param, const QString &line, QString *value);
void rdLine(const QString &param, const QString &line, int *value);
void enforceMaxEvents(shared_t *share);
class MultiInstance : public QObject
{
Q_OBJECT
private:
QList<QProcess*> procList;
private slots:
void instStdout();
void instStderr();
void procChanged(QProcess::ProcessState newState);
public:
explicit MultiInstance(QObject *parent = nullptr);
int start(const QStringList &args);
};
#endif // COMMON_H