-added a dely to DetectLoop after a positive motion detection to
 prevent motion event overlap.

-moved the 2 image diff pair compair to proper "end of array" in
 DetectLoop.

-increased the size of the image stream so queded up events will
 be able generate thumbnails properly.

-cleaned off a bunch of unused parameters in the code.

-adjusted the default motion sensitivity after real world
 testing.

-added libfuse-dev to setup.sh since imagemagic needs that to
 operate.
This commit is contained in:
Maurice ONeal 2023-05-27 09:33:14 -04:00
parent 4134d4befb
commit b445906403
5 changed files with 59 additions and 56 deletions

View File

@ -2,6 +2,6 @@
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
apt update -y apt update -y
apt install -y pkg-config cmake make g++ apt install -y pkg-config cmake make g++
apt install -y ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev x264 libx264-dev libilmbase-dev qt6-base-dev qtchooser qmake6 qt6-base-dev-tools libxkbcommon-dev apt install -y ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev x264 libx264-dev libilmbase-dev qt6-base-dev qtchooser qmake6 qt6-base-dev-tools libxkbcommon-dev libfuse-dev
cp ./bin/magick /usr/bin/magick cp ./bin/magick /usr/bin/magick
chmod +x /usr/bin/magick chmod +x /usr/bin/magick

View File

@ -19,15 +19,12 @@ Camera::Camera(QObject *parent) : QObject(parent)
shared.camName.clear(); shared.camName.clear();
shared.retCode = 0; shared.retCode = 0;
shared.maxScore = 0; shared.imgThresh = 15000;
shared.pixThresh = 50;
shared.imgThresh = 8000;
shared.maxEvents = 100; shared.maxEvents = 100;
shared.maxLogSize = 100000; shared.maxLogSize = 100000;
shared.skipCmd = false; shared.skipCmd = false;
shared.postSecs = 60; shared.postSecs = 60;
shared.evMaxSecs = 10; shared.evMaxSecs = 10;
shared.frameGap = 10;
shared.webRoot = "/var/www/html"; shared.webRoot = "/var/www/html";
shared.webBg = "#485564"; shared.webBg = "#485564";
shared.webTxt = "#dee5ee"; shared.webTxt = "#dee5ee";
@ -41,6 +38,12 @@ int Camera::start(const QStringList &args)
if (rdConf(&shared)) if (rdConf(&shared))
{ {
QDir("live").removeRecursively(); QDir("live").removeRecursively();
QDir("img").removeRecursively();
QDir().mkdir("live");
QDir().mkdir("events");
QDir().mkdir("logs");
QDir().mkdir("img");
auto thr1 = new QThread(nullptr); auto thr1 = new QThread(nullptr);
auto thr2 = new QThread(nullptr); auto thr2 = new QThread(nullptr);
@ -67,15 +70,14 @@ Loop::Loop(shared_t *sharedRes, QThread *thr, QObject *parent) : QObject(parent)
heartBeat = 10; heartBeat = 10;
loopTimer = 0; loopTimer = 0;
connect(thr, &QThread::started, this, &Loop::init); connect(thr, &QThread::started, this, &Loop::init);
connect(this, &Loop::loopSig, this, &Loop::loopSlot);
moveToThread(thr); moveToThread(thr);
} }
void Loop::init() void Loop::init()
{ {
loopTimer = new QTimer(nullptr); loopTimer = new QTimer(this);
connect(loopTimer, &QTimer::timeout, this, &Loop::loopSlot); connect(loopTimer, &QTimer::timeout, this, &Loop::loopSlot);
@ -381,13 +383,16 @@ bool EventLoop::wrOutVod(const QString &name, const QStringList &vids)
DetectLoop::DetectLoop(shared_t *sharedRes, QThread *thr, QObject *parent) : Loop(sharedRes, thr, parent) DetectLoop::DetectLoop(shared_t *sharedRes, QThread *thr, QObject *parent) : Loop(sharedRes, thr, parent)
{ {
pcTimer = 0; pcTimer = 0;
heartBeat = 3; heartBeat = 3;
delayCycles = 4; // this will be used to delay the
// actual start of DetectLoop by
// 12secs.
} }
void DetectLoop::init() void DetectLoop::init()
{ {
pcTimer = new QTimer(nullptr); pcTimer = new QTimer(this);
mod = false; mod = false;
connect(pcTimer, &QTimer::timeout, this, &DetectLoop::pcBreak); connect(pcTimer, &QTimer::timeout, this, &DetectLoop::pcBreak);
@ -424,43 +429,55 @@ void DetectLoop::pcBreak()
bool DetectLoop::exec() bool DetectLoop::exec()
{ {
auto curDT = QDateTime::currentDateTime(); if (delayCycles > 0)
auto images = backwardFacingFiles("img", ".bmp", curDT, 10);
if (images.size() < 3)
{ {
detLog("wrn: didn't pick up enough image files from the image stream. number of files: " + QString::number(images.size()), shared); delayCycles -= 1;
} }
else else
{ {
QProcess extComp; auto curDT = QDateTime::currentDateTime();
QStringList args; auto images = backwardFacingFiles("img", ".bmp", curDT, 10);
args << "compare"; if (images.size() < 3)
args << "-metric" << "FUZZ";
args << images[0];
args << images[1];
args << "/dev/null";
extComp.start("magick", args);
extComp.waitForFinished();
QString output = extComp.readAllStandardError();
output = output.left(output.indexOf(' '));
detLog(extComp.program() + " " + args.join(" ") + " --result: " + output, shared);
if (output.toFloat() >= shared->imgThresh)
{ {
detLog("--threshold_breached: " + QString::number(shared->imgThresh), shared); detLog("wrn: didn't pick up enough image files from the image stream. number of files: " + QString::number(images.size()), shared);
detLog(" will try again on the next loop.", shared);
}
else
{
QProcess extComp;
QStringList args;
evt_t event; auto pos = images.size() - 1;
event.timeStamp = curDT; args << "compare";
event.imgPath = images[2]; args << "-metric" << "FUZZ";
args << images[pos - 2];
args << images[pos - 1];
args << "/dev/null";
shared->recList.append(event); mod = true; extComp.start("magick", args);
extComp.waitForFinished();
QString output = extComp.readAllStandardError();
output = output.left(output.indexOf(' '));
detLog(extComp.program() + " " + args.join(" ") + " --result: " + output, shared);
if (output.toFloat() >= shared->imgThresh)
{
detLog("--threshold_breached: " + QString::number(shared->imgThresh), shared);
evt_t event;
event.timeStamp = curDT;
event.imgPath = images[pos];
delayCycles = shared->evMaxSecs / heartBeat;
shared->recList.append(event); mod = true;
}
} }
} }

View File

@ -40,17 +40,12 @@ protected:
shared_t *shared; shared_t *shared;
QTimer *loopTimer; QTimer *loopTimer;
bool interruptible;
int heartBeat; int heartBeat;
protected slots: protected slots:
virtual void init(); virtual void init();
signals:
void loopSig();
private slots: private slots:
void loopSlot(); void loopSlot();
@ -124,6 +119,7 @@ class DetectLoop : public Loop
private: private:
QTimer *pcTimer; QTimer *pcTimer;
int delayCycles;
bool mod; bool mod;
void resetTimers(); void resetTimers();

View File

@ -184,9 +184,7 @@ bool rdConf(const QString &filePath, shared_t *share)
rdLine("max_event_secs = ", line, &share->evMaxSecs); rdLine("max_event_secs = ", line, &share->evMaxSecs);
rdLine("post_secs = ", line, &share->postSecs); rdLine("post_secs = ", line, &share->postSecs);
rdLine("post_cmd = ", line, &share->postCmd); rdLine("post_cmd = ", line, &share->postCmd);
rdLine("pix_thresh = ", line, &share->pixThresh);
rdLine("img_thresh = ", line, &share->imgThresh); rdLine("img_thresh = ", line, &share->imgThresh);
rdLine("frame_gap = ", line, &share->frameGap);
rdLine("max_events = ", line, &share->maxEvents); rdLine("max_events = ", line, &share->maxEvents);
rdLine("max_log_size = ", line, &share->maxLogSize); rdLine("max_log_size = ", line, &share->maxLogSize);
} }

View File

@ -28,7 +28,7 @@
using namespace std; using namespace std;
#define APP_VER "3.0.t6" #define APP_VER "3.0.t7"
#define APP_NAME "Motion Watch" #define APP_NAME "Motion Watch"
#define APP_BIN "mow" #define APP_BIN "mow"
#define REC_LOG_NAME "rec_log_lines.html" #define REC_LOG_NAME "rec_log_lines.html"
@ -36,7 +36,7 @@ using namespace std;
#define UPK_LOG_NAME "upk_log_lines.html" #define UPK_LOG_NAME "upk_log_lines.html"
#define DATETIME_FMT "yyyyMMddhhmmss" #define DATETIME_FMT "yyyyMMddhhmmss"
#define STRFTIME_FMT "%Y%m%d%H%M%S" #define STRFTIME_FMT "%Y%m%d%H%M%S"
#define MAX_IMAGES 40 #define MAX_IMAGES 1000
struct evt_t struct evt_t
{ {
@ -47,7 +47,6 @@ struct evt_t
struct shared_t struct shared_t
{ {
QList<evt_t> recList; QList<evt_t> recList;
evt_t curEvent;
QString conf; QString conf;
QString recLog; QString recLog;
QString detLog; QString detLog;
@ -61,19 +60,12 @@ struct shared_t
QString webFont; QString webFont;
QString webRoot; QString webRoot;
bool skipCmd; bool skipCmd;
int frameGap;
int evMaxSecs; int evMaxSecs;
int postSecs; int postSecs;
int maxScore;
int procCnt;
int hlsCnt;
int pixThresh;
int imgThresh; int imgThresh;
int maxEvents; int maxEvents;
int maxLogSize; int maxLogSize;
int retCode; int retCode;
int postInd;
int evInd;
}; };
QString getParam(const QString &key, const QStringList &args); QString getParam(const QString &key, const QStringList &args);