v1.4.t10
optical flow calculations use up a lot of processing power even at the block level so I decided to take it back out. once again, no objection detection is going to be used and will fall back to pixel diffs only. also modified pixel diffs to decrement pixel diffs of no diff is detected, going test how this works out.
This commit is contained in:
parent
17c136b6bc
commit
9ecace7e4b
|
@ -13,24 +13,17 @@
|
|||
#include "mo_detect.h"
|
||||
|
||||
bool pixDiff(const uchar &pixA, const uchar &pixB, shared_t *share)
|
||||
{
|
||||
if (pixA > pixB) return true;
|
||||
if (pixB > pixA) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void secDiff(const Mat &imgA, const Mat &imgB, int id, int rows, int cols, int rowOffs, int colOffs, vector<sec_t> *results, mutex *secMutex, shared_t *share)
|
||||
{
|
||||
auto diff = 0;
|
||||
|
||||
if (pixA > pixB) diff = pixA - pixB;
|
||||
if (pixB > pixA) diff = pixB - pixA;
|
||||
|
||||
if (diff < share->colorThresh)
|
||||
{
|
||||
diff = 0;
|
||||
}
|
||||
|
||||
return diff != 0;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
for (auto y = rowOffs; y < (rowOffs + rows); y++)
|
||||
{
|
||||
for (auto x = colOffs; x < (colOffs + cols); x++)
|
||||
|
@ -38,20 +31,21 @@ void secDiff(const Mat &imgA, const Mat &imgB, int rows, int cols, int rowOffs,
|
|||
auto pixA = imgA.at<uchar>(Point(x, y));
|
||||
auto pixB = imgB.at<uchar>(Point(x, y));
|
||||
|
||||
if (pixDiff(pixA, pixB, share))
|
||||
{
|
||||
pnts += 1;
|
||||
}
|
||||
if (pixDiff(pixA, pixB, share)) diff += 1;
|
||||
else diff -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (diff < 0) diff = 0;
|
||||
|
||||
struct sec_t res;
|
||||
|
||||
res.x = colOffs;
|
||||
res.y = rowOffs;
|
||||
res.xSize = cols;
|
||||
res.ySize = rows;
|
||||
res.pixDiff = pnts;
|
||||
res.pixDiff = diff;
|
||||
res.id = id;
|
||||
|
||||
lock_guard<mutex> guard(*secMutex);
|
||||
|
||||
|
@ -64,12 +58,14 @@ bool imgDiff(const Mat &prev, const Mat &next, shared_t *share)
|
|||
vector<sec_t> results;
|
||||
mutex secMutex;
|
||||
|
||||
auto id = 0;
|
||||
|
||||
for (auto x = 0; x < prev.cols; x += share->blockX)
|
||||
{
|
||||
// spawn all of the block motion detection threads.
|
||||
for (auto y = 0; y < prev.rows; y += share->blockY)
|
||||
for (auto y = 0; y < prev.rows; y += share->blockY, id += 1)
|
||||
{
|
||||
threads.push_back(thread(secDiff, prev, next, share->blockY, share->blockX, y, x, &results, &secMutex, share));
|
||||
threads.push_back(thread(secDiff, prev, next, id, share->blockY, share->blockX, y, x, &results, &secMutex, share));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,12 +85,9 @@ bool imgDiff(const Mat &prev, const Mat &next, shared_t *share)
|
|||
auto x = results[i].x;
|
||||
auto y = results[i].y;
|
||||
auto diff = results[i].pixDiff;
|
||||
auto id = results[i].id;
|
||||
|
||||
share->stat += string("block_thread:")
|
||||
+ " x=" + to_string(x)
|
||||
+ " y=" + to_string(y)
|
||||
+ " pixdiff=" + to_string(diff)
|
||||
+ "\n";
|
||||
share->stat += string("block_thread:") + " id=" + to_string(id) + " diff=" + to_string(diff) + "\n";
|
||||
|
||||
if ((results[i].pixDiff >= share->blockThresh) && (results[i].pixDiff > maxPixDiff))
|
||||
{
|
||||
|
@ -103,19 +96,7 @@ bool imgDiff(const Mat &prev, const Mat &next, shared_t *share)
|
|||
}
|
||||
}
|
||||
|
||||
if (maxPixDiff >= share->blockThresh)
|
||||
{
|
||||
// run optical flow calcuations on the block with the highest
|
||||
// pixDiff.
|
||||
auto res = results[blockPick];
|
||||
auto block = Rect(res.x, res.y, res.xSize, res.ySize);
|
||||
|
||||
return objectFlowInImage(prev, next, block, share);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return maxPixDiff >= share->blockThresh;
|
||||
}
|
||||
|
||||
bool moDetect(const string &buffFile, shared_t *share)
|
||||
|
@ -129,8 +110,6 @@ bool moDetect(const string &buffFile, shared_t *share)
|
|||
Mat prev;
|
||||
Mat next;
|
||||
|
||||
share->stat += "motion_detection-- clip_file - " + buffFile + "\n";
|
||||
|
||||
while (capPair(prev, next, capture, share))
|
||||
{
|
||||
if (imgDiff(toGray(prev), toGray(next), share))
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
// GNU General Public License for more details.
|
||||
|
||||
#include "common.h"
|
||||
#include "obj_detect.h"
|
||||
|
||||
struct sec_t
|
||||
{
|
||||
int id;
|
||||
int x;
|
||||
int y;
|
||||
int xSize;
|
||||
|
@ -25,7 +25,7 @@ struct sec_t
|
|||
int pixDiff;
|
||||
};
|
||||
|
||||
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);
|
||||
void secDiff(const Mat &imgA, const Mat &imgB, int id, int rows, int cols, int rowOffs, int colOffs, vector<sec_t> *results, mutex *secMutex, shared_t *share);
|
||||
bool pixDiff(const uchar &pixA, const uchar &pixB, shared_t *share);
|
||||
bool imgDiff(const Mat &prev, const Mat &next, shared_t *share);
|
||||
bool moDetect(const string &buffFile, shared_t *share);
|
||||
|
|
Loading…
Reference in New Issue
Block a user