Skip to content
Snippets Groups Projects
Commit f1eb7f58 authored by Leonardo de Lima Gaspar's avatar Leonardo de Lima Gaspar
Browse files

Testing OR instead of XOR for change detection.

parent 351cbafa
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ ofstream createCSV(filesystem::path videoFilePath); ...@@ -20,7 +20,7 @@ ofstream createCSV(filesystem::path videoFilePath);
// and returns true for when the ratio of the sum of those changes is sufficiently large. // and returns true for when the ratio of the sum of those changes is sufficiently large.
bool detectChange(Mat firstFrame, Mat secFrame); bool detectChange(Mat firstFrame, Mat secFrame);
double percentChangeThreshold = 0.00048828125; // 2^-11 double percentChangeThreshold = 0.001;
int main(int argc, char** argv) { int main(int argc, char** argv) {
if (argc != 2) { if (argc != 2) {
...@@ -37,6 +37,7 @@ int main(int argc, char** argv) { ...@@ -37,6 +37,7 @@ int main(int argc, char** argv) {
} }
ofstream csv = createCSV(videoPath); ofstream csv = createCSV(videoPath);
VideoCapture decoder(videoPath.string()); VideoCapture decoder(videoPath.string());
auto start = chrono::steady_clock::now(); auto start = chrono::steady_clock::now();
...@@ -100,7 +101,7 @@ int main(int argc, char** argv) { ...@@ -100,7 +101,7 @@ int main(int argc, char** argv) {
decoder.release(); decoder.release();
// Detection interval padding logic; essentially applies 1D dilation (morphological operation). // Detection interval padding logic; essentially applies 1D dilation (morphological operation).
int framesPaddedEachSide = round((paddingTime_s/2)*detectionsPerSec + 0.5); int framesPaddedEachSide = ceil((paddingTime_s/2)*detectionsPerSec + 0.5);
vector<bool> dilated = motionVec; vector<bool> dilated = motionVec;
for(int i=0; i<motionVec.size(); i++) { for(int i=0; i<motionVec.size(); i++) {
if (motionVec[i] == 1) { if (motionVec[i] == 1) {
...@@ -157,8 +158,8 @@ bool detectChange(Mat firstFrame, Mat secFrame) { ...@@ -157,8 +158,8 @@ bool detectChange(Mat firstFrame, Mat secFrame) {
for(int j = 0; j < firstFrame.cols; j++) for(int j = 0; j < firstFrame.cols; j++)
{ {
int pos = i*j + j; int pos = i*j + j;
sum += firstFrameArr[pos] ^ secFrameArr[pos]; sum += firstFrameArr[pos] | secFrameArr[pos];
} }
} }
return sum/(firstFrame.rows*firstFrame.cols) > percentChangeThreshold; return 4*sum/(firstFrame.rows*firstFrame.cols) > percentChangeThreshold;
} }
\ No newline at end of file
...@@ -27,7 +27,7 @@ def main(inputVideo): ...@@ -27,7 +27,7 @@ def main(inputVideo):
print("No input folder found. Creating it now. Place input video files in that folder.") print("No input folder found. Creating it now. Place input video files in that folder.")
return return
print("Processing file {file}".format(file=inputVideo)) print("Processing file {file}".format(file=inputVideo))
#os.system("opencvtest.exe {input}".format(input="input/{file}".format(file=inputVideo))) os.system("opencvtest.exe {input}".format(input="input/{file}".format(file=inputVideo)))
prefix, ext = os.path.splitext(inputVideo) prefix, ext = os.path.splitext(inputVideo)
print("\nVideo processed and outputted to {csv}.".format(csv=prefix+".csv")) print("\nVideo processed and outputted to {csv}.".format(csv=prefix+".csv"))
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment