potentially fixed what was apparently a long standing bug that caused
motion detection to look at just the first block. this bug was found
thanks to the stats output.
This commit is contained in:
Maurice ONeal 2022-09-30 16:18:39 -04:00
parent 4f33c280ce
commit cd4a2d0f98
3 changed files with 24 additions and 9 deletions

View File

@ -252,6 +252,12 @@ bool rdConf(shared_t *share)
} while(!line.empty()); } while(!line.empty());
// it's imperative that blockX/Y are not zero or it will cause
// an infinte loop. if bad data is read from the conf, default
// values will be used.
if (share->blockX == 0) share->blockX = 32;
if (share->blockY == 0) share->blockY = 32;
if (share->init) if (share->init)
{ {
remove_all(share->buffDir.c_str()); remove_all(share->buffDir.c_str());

View File

@ -35,7 +35,7 @@ using namespace std;
using namespace std::filesystem; using namespace std::filesystem;
#define BUF_SZ 10 #define BUF_SZ 10
#define APP_VER "1.4.t3" #define APP_VER "1.4.t4"
struct shared_t struct shared_t
{ {

View File

@ -27,7 +27,7 @@ bool pixDiff(const uchar &pixA, const uchar &pixB, shared_t *share)
return diff != 0; return diff != 0;
} }
void secDiff(Mat imgA, Mat imgB, int rows, int cols, int rowOffs, int colOffs, vector<sec_t> *results, mutex *secMutex, shared_t *share) void secDiff(const Mat &imgA, const Mat &imgB, int rows, int cols, int rowOffs, int colOffs, vector<sec_t> *results, mutex *secMutex, shared_t *share)
{ {
auto pnts = 0; auto pnts = 0;
@ -60,18 +60,16 @@ void secDiff(Mat imgA, Mat imgB, int rows, int cols, int rowOffs, int colOffs, v
bool imgDiff(Mat prev, Mat next, Rect *block, shared_t *share) bool imgDiff(Mat prev, Mat next, Rect *block, shared_t *share)
{ {
auto numOfXBlocks = prev.cols / share->blockX;
auto numOfYBlocks = prev.rows / share->blockY;
auto moInBlock = false; auto moInBlock = false;
vector<thread> threads; vector<thread> threads;
vector<sec_t> results; vector<sec_t> results;
mutex secMutex; mutex secMutex;
for (auto x = 0; x < numOfXBlocks; x += share->blockX) for (auto x = 0; x < prev.cols; x += share->blockX)
{ {
// spawn all of the block motion detection threads. // spawn all of the block motion detection threads.
for (auto y = 0; y < numOfYBlocks; y += share->blockY) for (auto y = 0; y < prev.rows; y += share->blockY)
{ {
threads.push_back(thread(secDiff, prev, next, share->blockY, share->blockX, y, x, &results, &secMutex, share)); threads.push_back(thread(secDiff, prev, next, share->blockY, share->blockX, y, x, &results, &secMutex, share));
} }
@ -92,9 +90,16 @@ bool imgDiff(Mat prev, Mat next, Rect *block, shared_t *share)
// the block with the highest amount of pixDiff. // the block with the highest amount of pixDiff.
auto x = results[i].x; auto x = results[i].x;
auto y = results[i].y; auto y = results[i].y;
auto xSz = results[i].xSize;
auto ySz = results[i].ySize;
auto diff = results[i].pixDiff; auto diff = results[i].pixDiff;
share->stat += "block_thread:" + string(" x=") + to_string(x) + " y=" + to_string(y) + " pixdiff=" + to_string(diff) + "\n"; share->stat += "block_thread:"
+ string(" x=") + to_string(x)
+ " y=" + to_string(y)
+ " x_len=" + to_string(xSz)
+ " y_len=" + to_string(ySz)
+ " pixdiff=" + to_string(diff) + "\n";
if ((results[i].pixDiff >= share->blockThresh) && (results[i].pixDiff > maxPixDiff)) if ((results[i].pixDiff >= share->blockThresh) && (results[i].pixDiff > maxPixDiff))
{ {
@ -132,8 +137,12 @@ bool moDetect(const string &buffFile, Rect *block, Mat *img, shared_t *share)
Mat prev; Mat prev;
Mat next; Mat next;
while (capPair(prev, next, capture, share)) share->stat += "motion_detection -- clip_file - " + buffFile + "\n";
for (auto i = 0; capPair(prev, next, capture, share); ++i)
{ {
share->stat += "frame_pair-- " + to_string(i) + "\n";
if (imgDiff(toGray(prev), toGray(next), block, share)) if (imgDiff(toGray(prev), toGray(next), block, share))
{ {
*img = next; *img = next;