v1.5.t11
Found the infinite loop issue in moDetect(), turns out the frame parameters at some point were never returning empty, hence moDetect() would continue into perpetuity. Changed the loop structure to use a fixed frame count instead of relying on frameFF() to return empty on EOF.
This commit is contained in:
parent
c153fdcd21
commit
523ff57215
|
@ -35,7 +35,7 @@ using namespace cv;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::filesystem;
|
using namespace std::filesystem;
|
||||||
|
|
||||||
#define APP_VER "1.5.t10"
|
#define APP_VER "1.5.t11"
|
||||||
#define APP_NAME "Motion Watch"
|
#define APP_NAME "Motion Watch"
|
||||||
|
|
||||||
struct shared_t
|
struct shared_t
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#include "mo_detect.h"
|
#include "mo_detect.h"
|
||||||
|
|
||||||
bool imgDiff(const Mat &prev, const Mat &next, int &diffScore, shared_t *share)
|
bool imgDiff(const Mat &prev, const Mat &next, shared_t *share)
|
||||||
{
|
{
|
||||||
auto ret = false;
|
auto ret = false;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ bool imgDiff(const Mat &prev, const Mat &next, int &diffScore, shared_t *share)
|
||||||
absdiff(prev, next, diff);
|
absdiff(prev, next, diff);
|
||||||
threshold(diff, diff, share->pixThresh, 255, THRESH_BINARY);
|
threshold(diff, diff, share->pixThresh, 255, THRESH_BINARY);
|
||||||
|
|
||||||
diffScore = countNonZero(diff);
|
auto diffScore = countNonZero(diff);
|
||||||
|
|
||||||
detLog("diff_score: " + to_string(diffScore), share);
|
detLog("diff_score: " + to_string(diffScore), share);
|
||||||
|
|
||||||
|
@ -108,35 +108,34 @@ bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share)
|
||||||
{
|
{
|
||||||
Mat prev;
|
Mat prev;
|
||||||
Mat next;
|
Mat next;
|
||||||
int diff = 0;
|
auto frameCount = capture.get(CAP_PROP_FRAME_COUNT);
|
||||||
int maxDiff = 0;
|
auto frameGaps = frameCount / share->frameGap;
|
||||||
int frameGaps = 0;
|
|
||||||
|
|
||||||
do
|
detLog("frame_count: " + to_string(frameCount), share);
|
||||||
|
detLog("frame_gaps: " + to_string(frameGaps), share);
|
||||||
|
|
||||||
|
for (auto i = 0; i < frameGaps; i++)
|
||||||
{
|
{
|
||||||
if (prev.empty()) prev = frameFF(&capture, 1);
|
if (prev.empty()) prev = frameFF(&capture, 1);
|
||||||
else prev = next.clone();
|
else prev = next.clone();
|
||||||
|
|
||||||
next = frameFF(&capture, share->frameGap);
|
next = frameFF(&capture, share->frameGap);
|
||||||
|
|
||||||
if (imgDiff(prev, next, diff, share))
|
if (imgDiff(prev, next, share))
|
||||||
{
|
{
|
||||||
resize(next, vidThumb, Size(1280, 720), INTER_LINEAR);
|
resize(next, vidThumb, Size(1280, 720), INTER_LINEAR);
|
||||||
|
|
||||||
mod = true;
|
mod = true; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
frameGaps += share->frameGap;
|
|
||||||
|
|
||||||
detLog("frame_gap: " + to_string(frameGaps), share);
|
|
||||||
}
|
}
|
||||||
while (!prev.empty() && !next.empty() && !mod);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
detLog("failed to open the buff file for reading. check permissions and/or opencv's video-io support (gstreamer/ffmpeg).", share);
|
detLog("failed to open the buff file for reading. check permissions and/or opencv's video-io support (gstreamer/ffmpeg).", share);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
capture.release();
|
||||||
|
|
||||||
detLog("mo_detect() -- finished()", share);
|
detLog("mo_detect() -- finished()", share);
|
||||||
|
|
||||||
return mod;
|
return mod;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "web.h"
|
#include "web.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
bool imgDiff(const Mat &prev, const Mat &next, int &diffScore, shared_t *share);
|
bool imgDiff(const Mat &prev, const Mat &next, shared_t *share);
|
||||||
bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share);
|
bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share);
|
||||||
void wrOut(const string &buffFile, const Mat &vidThumb, shared_t *share);
|
void wrOut(const string &buffFile, const Mat &vidThumb, shared_t *share);
|
||||||
Mat frameFF(VideoCapture *cap, int gap);
|
Mat frameFF(VideoCapture *cap, int gap);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user