-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
apt update -y
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
chmod +x /usr/bin/magick

View File

@ -19,15 +19,12 @@ Camera::Camera(QObject *parent) : QObject(parent)
shared.camName.clear();
shared.retCode = 0;
shared.maxScore = 0;
shared.pixThresh = 50;
shared.imgThresh = 8000;
shared.imgThresh = 15000;
shared.maxEvents = 100;
shared.maxLogSize = 100000;
shared.skipCmd = false;
shared.postSecs = 60;
shared.evMaxSecs = 10;
shared.frameGap = 10;
shared.webRoot = "/var/www/html";
shared.webBg = "#485564";
shared.webTxt = "#dee5ee";
@ -41,6 +38,12 @@ int Camera::start(const QStringList &args)
if (rdConf(&shared))
{
QDir("live").removeRecursively();
QDir("img").removeRecursively();
QDir().mkdir("live");
QDir().mkdir("events");
QDir().mkdir("logs");
QDir().mkdir("img");
auto thr1 = 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;
loopTimer = 0;
connect(thr, &QThread::started, this, &Loop::init);
connect(this, &Loop::loopSig, this, &Loop::loopSlot);
connect(thr, &QThread::started, this, &Loop::init);
moveToThread(thr);
}
void Loop::init()
{
loopTimer = new QTimer(nullptr);
loopTimer = new QTimer(this);
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)
{
pcTimer = 0;
heartBeat = 3;
pcTimer = 0;
heartBeat = 3;
delayCycles = 4; // this will be used to delay the
// actual start of DetectLoop by
// 12secs.
}
void DetectLoop::init()
{
pcTimer = new QTimer(nullptr);
pcTimer = new QTimer(this);
mod = false;
connect(pcTimer, &QTimer::timeout, this, &DetectLoop::pcBreak);
@ -424,43 +429,55 @@ void DetectLoop::pcBreak()
bool DetectLoop::exec()
{
auto curDT = QDateTime::currentDateTime();
auto images = backwardFacingFiles("img", ".bmp", curDT, 10);
if (images.size() < 3)
if (delayCycles > 0)
{
detLog("wrn: didn't pick up enough image files from the image stream. number of files: " + QString::number(images.size()), shared);
delayCycles -= 1;
}
else
{
QProcess extComp;
QStringList args;
auto curDT = QDateTime::currentDateTime();
auto images = backwardFacingFiles("img", ".bmp", curDT, 10);
args << "compare";
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)
if (images.size() < 3)
{
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;
event.imgPath = images[2];
args << "compare";
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;
QTimer *loopTimer;
bool interruptible;
int heartBeat;
protected slots:
virtual void init();
signals:
void loopSig();
private slots:
void loopSlot();
@ -124,6 +119,7 @@ class DetectLoop : public Loop
private:
QTimer *pcTimer;
int delayCycles;
bool mod;
void resetTimers();

View File

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

View File

@ -28,7 +28,7 @@
using namespace std;
#define APP_VER "3.0.t6"
#define APP_VER "3.0.t7"
#define APP_NAME "Motion Watch"
#define APP_BIN "mow"
#define REC_LOG_NAME "rec_log_lines.html"
@ -36,7 +36,7 @@ using namespace std;
#define UPK_LOG_NAME "upk_log_lines.html"
#define DATETIME_FMT "yyyyMMddhhmmss"
#define STRFTIME_FMT "%Y%m%d%H%M%S"
#define MAX_IMAGES 40
#define MAX_IMAGES 1000
struct evt_t
{
@ -47,7 +47,6 @@ struct evt_t
struct shared_t
{
QList<evt_t> recList;
evt_t curEvent;
QString conf;
QString recLog;
QString detLog;
@ -61,19 +60,12 @@ struct shared_t
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;
};
QString getParam(const QString &key, const QStringList &args);