diff --git a/src/common.h b/src/common.h index dec0cb8..3505b05 100644 --- a/src/common.h +++ b/src/common.h @@ -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 diff --git a/src/mo_detect.cpp b/src/mo_detect.cpp index 9b70338..26efcdc 100644 --- a/src/mo_detect.cpp +++ b/src/mo_detect.cpp @@ -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; diff --git a/src/mo_detect.h b/src/mo_detect.h index 459f26c..894573c 100644 --- a/src/mo_detect.h +++ b/src/mo_detect.h @@ -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);