Skip to content
Snippets Groups Projects
Commit 9ce90b05 authored by Erlend Sørhus's avatar Erlend Sørhus
Browse files

Cleaned up main a little.

parent e1cd854b
Branches
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
include(CTest)
enable_testing()
set(OpenCV_DIR "C:\\CPP Libs\\oomga\\build" )
set(OpenCV_DIR "C:\\opencv++" )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
......
......@@ -13,32 +13,17 @@
using namespace std;
using namespace cv;
ofstream createCSV(string filename);
void writeCSV(string line, ofstream csv);
// 2^-11
double percentChangeThreshold = 0.00048828125;
// Creates a new csv file based on a filepath with name videofilename.csv
ofstream createCSV(filesystem::path videoFilePath);
// Defines change between frames as XOR bitwise operation between pixel pairs mapped to same position,
// and returns true for when the ratio of the sum of those changes is sufficiently large.
bool detectChange(Mat firstFrame, Mat secFrame) {
Mat xorMapMat = Mat::zeros(firstFrame.rows, firstFrame.cols, CV_8U);
bool detectChange(Mat firstFrame, Mat secFrame);
double percentChangeThreshold = 0.00048828125; // 2^-11
uint8_t* xorMapArr = (uint8_t*)xorMapMat.data;
uint8_t* firstFrameArr = (uint8_t*)firstFrame.data;
uint8_t* secFrameArr = (uint8_t*)secFrame.data;
long sum = 0;
for(int i = 0; i < firstFrame.rows; i++)
{
for(int j = 0; j < firstFrame.cols; j++)
{
int pos = i*j + j;
sum += firstFrameArr[pos] ^ secFrameArr[pos];
}
}
return sum/(firstFrame.rows*firstFrame.cols) > percentChangeThreshold;
}
int main(int argc, char** argv) {
if (argc != 2) {
......@@ -55,8 +40,7 @@ int main(int argc, char** argv) {
}
// Currently using Myggbukta-[2021-05-21_10-47-06]-716 as test.mp4.
filesystem::path csvPath(videoPath.string());
ofstream csv = createCSV(csvPath.replace_extension(".csv").string());
ofstream csv = createCSV(videoPath);
VideoCapture decoder(videoPath.string());
auto start = chrono::steady_clock::now();
......@@ -145,7 +129,7 @@ int main(int argc, char** argv) {
runEnd_s = runStart_s + timePerSimFrame_s*runCounter;
i += runCounter;
if (runCounter>0) {
csv << runStart_s << "," << runEnd_s << ",";
csv << runStart_s << "," << runEnd_s << endl;
}
}
......@@ -157,11 +141,27 @@ int main(int argc, char** argv) {
return 0;
}
ofstream createCSV(string filename) {
// Check for issues here
ofstream csv(filename);
ofstream createCSV(filesystem::path videoFilePath) {
filesystem::path csvPath(videoFilePath.string());
ofstream csv(csvPath.replace_extension(".csv").string());
return csv;
}
void writeCSV(string line, ofstream csv){
csv << line;
bool detectChange(Mat firstFrame, Mat secFrame) {
Mat xorMapMat = Mat::zeros(firstFrame.rows, firstFrame.cols, CV_8U);
uint8_t* xorMapArr = (uint8_t*)xorMapMat.data;
uint8_t* firstFrameArr = (uint8_t*)firstFrame.data;
uint8_t* secFrameArr = (uint8_t*)secFrame.data;
long sum = 0;
for(int i = 0; i < firstFrame.rows; i++)
{
for(int j = 0; j < firstFrame.cols; j++)
{
int pos = i*j + j;
sum += firstFrameArr[pos] ^ secFrameArr[pos];
}
}
return sum/(firstFrame.rows*firstFrame.cols) > percentChangeThreshold;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment