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::filesystem;
|
||||
|
||||
#define APP_VER "1.5.t10"
|
||||
#define APP_VER "1.5.t11"
|
||||
#define APP_NAME "Motion Watch"
|
||||
|
||||
struct shared_t
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#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;
|
||||
|
||||
|
@ -28,7 +28,7 @@ bool imgDiff(const Mat &prev, const Mat &next, int &diffScore, shared_t *share)
|
|||
absdiff(prev, next, diff);
|
||||
threshold(diff, diff, share->pixThresh, 255, THRESH_BINARY);
|
||||
|
||||
diffScore = countNonZero(diff);
|
||||
auto diffScore = countNonZero(diff);
|
||||
|
||||
detLog("diff_score: " + to_string(diffScore), share);
|
||||
|
||||
|
@ -106,37 +106,36 @@ bool moDetect(const string &buffFile, Mat &vidThumb, shared_t *share)
|
|||
|
||||
if (capture.isOpened())
|
||||
{
|
||||
Mat prev;
|
||||
Mat next;
|
||||
int diff = 0;
|
||||
int maxDiff = 0;
|
||||
int frameGaps = 0;
|
||||
Mat prev;
|
||||
Mat next;
|
||||
auto frameCount = capture.get(CAP_PROP_FRAME_COUNT);
|
||||
auto frameGaps = frameCount / share->frameGap;
|
||||
|
||||
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);
|
||||
else prev = next.clone();
|
||||
|
||||
next = frameFF(&capture, share->frameGap);
|
||||
|
||||
if (imgDiff(prev, next, diff, share))
|
||||
if (imgDiff(prev, next, share))
|
||||
{
|
||||
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
|
||||
{
|
||||
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);
|
||||
|
||||
return mod;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "web.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);
|
||||
void wrOut(const string &buffFile, const Mat &vidThumb, shared_t *share);
|
||||
Mat frameFF(VideoCapture *cap, int gap);
|
||||
|
|
Loading…
Reference in New Issue
Block a user