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

Fixed writing to csv; issue was caused by out of bounds array in dilation logic.

parent f1eb7f58
No related branches found
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:\\opencv++" )
set(OpenCV_DIR "C:\\CPP Libs\\oomga\\build" )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
......
......@@ -59,7 +59,6 @@ int main(int argc, char** argv) {
double simFPS = decoder.get(CAP_PROP_FPS) / detectionsPerSec;
int simFrameTime = decoder.get(CAP_PROP_FRAME_COUNT) / simFPS;
motionVec.reserve(simFrameTime);
motionVec.push_back(0);
Mat frame;
Mat nextFrame;
......@@ -72,8 +71,8 @@ int main(int argc, char** argv) {
int32_t height = decoder.get(CAP_PROP_FRAME_HEIGHT);
int32_t width = decoder.get(CAP_PROP_FRAME_WIDTH);
bool isFirstFrame = true;
bool keyPressed = false;
cout << motionVec.size() << endl;
bool gotFrame, gotNextFrame;
while (gotFrame = decoder.read(frame)) {
// Skips some amount of "real" frames to reach desired "simulated fps".
......@@ -84,7 +83,7 @@ int main(int argc, char** argv) {
// Applies bg segmentation, median filter to reduce noise, and pushes the change detection result to output vector.
// The frame count might be inaccurate at the moment, such that real frame 24 at time 1s, might be declared as being at time 0.9s. Needs testing.
if (gotFrame && gotNextFrame && !keyPressed) {
if (gotFrame && gotNextFrame) {
p_bgSub->apply(frame, binaryFrame, -1);
p_bgSub->apply(nextFrame, binaryNextFrame, -1);
......@@ -93,25 +92,27 @@ int main(int argc, char** argv) {
medianBlur(binaryNextFrame, medianBlurNextFrame, blurRadius);
motionVec.push_back(detectChange(medianBlurFrame, medianBlurNextFrame));
} else { break; }
}
cout << motionVec.size() << endl;
destroyAllWindows();
decoder.release();
// Detection interval padding logic; essentially applies 1D dilation (morphological operation).
int framesPaddedEachSide = ceil((paddingTime_s/2)*detectionsPerSec + 0.5);
vector<bool> dilated = motionVec;
cout << dilated.size() << endl;
for(int i=0; i<motionVec.size(); i++) {
if (motionVec[i] == 1) {
if (motionVec.at(i) == 1) {
for(int k = -framesPaddedEachSide; k <= framesPaddedEachSide; k++) {
dilated[i+k] = 1;
int index = i+k;
if (index < 0 || index >= motionVec.size()) { continue; }
dilated.at(index) = 1;
}
}
}
// Timestamp generator logic; converts frame index to real time in input file. As mentioned above, the math might be inaccurate.
// Timestamp generator logic; converts simulated frame index to real time in input file. As mentioned above, the math might be inaccurate.
double timePerSimFrame_s = 1/(double)detectionsPerSec;
double runStart_s, runEnd_s;
for(int i=0; i<dilated.size(); i++) {
......@@ -129,7 +130,6 @@ int main(int argc, char** argv) {
csv << floor(runStart_s) << "," << ceil(runEnd_s) << "\n";
}
}
csv.close();
auto end = chrono::steady_clock::now();
auto elapsed = chrono::duration_cast<chrono::seconds>(end - start).count();
......
......@@ -27,11 +27,11 @@ def main(inputVideo):
print("No input folder found. Creating it now. Place input video files in that folder.")
return
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)
print("\nVideo processed and outputted to {csv}.".format(csv=prefix+".csv"))
print("Starting trimming now...")
VideoTrimmer.readForCSV(inputVideo)
main("Myggbukta-[2021-07-09_13-48-44]-105.mp4")
\ No newline at end of file
main("test.mp4")
\ No newline at end of file
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