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

Connected the Python parts that retrieve the generated .csv and trim the video...

Connected the Python parts that retrieve the generated .csv and trim the video based on the timestamps. Haven't been able to test, but it should work as a complete MVP. Have yet to add the optional success rate calculation functionality if there is a ground truth to compare to.
parent 09886881
Branches
No related tags found
No related merge requests found
......@@ -13,8 +13,8 @@
using namespace std;
using namespace cv;
ofstream createCSV(string filename)
void writeCSV(string line, ofstream csv)
ofstream createCSV(string filename);
void writeCSV(string line, ofstream csv);
// 2^-11
double percentChangeThreshold = 0.00048828125;
......@@ -48,7 +48,6 @@ int main(int argc, char** argv) {
}
filesystem::path videoPath(argv[1]);
filesystem::path csvExtention(".csv");
if(videoPath.extension() != ".mp4") {
cerr << "Failed to read input; make sure it is a valid .mp4 video file." << endl;
cerr << "Current input: " << argv[1];
......@@ -56,7 +55,8 @@ int main(int argc, char** argv) {
}
// Currently using Myggbukta-[2021-05-21_10-47-06]-716 as test.mp4.
ofstream csv = createCSV(videoPath.replace_extension(csvExtention);
filesystem::path csvPath(videoPath.string());
ofstream csv = createCSV(csvPath.replace_extension(".csv").string());
VideoCapture decoder(videoPath.string());
auto start = chrono::steady_clock::now();
......@@ -145,9 +145,7 @@ int main(int argc, char** argv) {
runEnd_s = runStart_s + timePerSimFrame_s*runCounter;
i += runCounter;
if (runCounter>0) {
int startMin = floor(runStart_s/60);
int endMin = floor(runEnd_s/60);
csv << startMin << ":" << floor(runStart_s-(startMin*60)) << "," << endMin << ":" << floor(runEnd_s-(endMin*60)) << endl;
csv << runStart_s << "," << runEnd_s << ",";
}
}
......@@ -155,7 +153,7 @@ int main(int argc, char** argv) {
auto elapsed = chrono::duration_cast<chrono::seconds>(end - start).count();
int minutes = floor(elapsed/60);
int seconds = floor(elapsed-(minutes*60));
csv << "Elapsed(mm:ss)=" << minutes << ":" << seconds << endl;
cout << "Elapsed(mm:ss)=" << minutes << ":" << seconds << endl;
return 0;
}
......
......@@ -30,12 +30,4 @@ def calculateSuccess(observedIntervalsList, trueIntervalsList):
while len(indices) < len(trueIntervalsList):
indices.append(0)
print(indices)
def main():
test = ((101, 167), (480, 520), (700, 710))
real = ((70, 180), (300,400), (500, 510), (705, 720))
calculateSuccess(test, real)
if __name__ == "__main__":
main()
print(sum(indices)/len(indices))
\ No newline at end of file
import subprocess as sp
import threading
import os
import ctypes, sys
import sys
import ctypes
import VideoTrimmer
import Jaccard
def is_admin():
try:
......@@ -12,12 +13,27 @@ def is_admin():
def main(inputVideo):
if is_admin():
curDir = os.getcwd()
print(curDir)
# Relative path to input folder from the current working directory (often the root of the repo).
repoRootToBinary = "build\\Release"
pathToBinary = os.path.join(curDir, repoRootToBinary)
print("Working on file %s" % inputVideo)
print("halo")
os.chdir(pathToBinary)
os.system("opencvtest.exe {input}".format(input=inputVideo))
# Creates input/output folders for videofiles.
if "output" not in os.listdir():
os.mkdir("output")
if "input" not in os.listdir():
os.mkdir("input")
# Log instead of print
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)))
prefix, ext = os.path.splitext(inputVideo)
print("\nVideo processed and outputted to {csv}.".format(csv=prefix+".csv"))
print("Starting trimming now...")
VideoTrimmer.readForCSV(pathToBinary)
main("test.mp4")
\ No newline at end of file
......@@ -41,23 +41,28 @@ def trim(inputVideo, csvTimestamps):
ffmpeg
.concat(*trims)
.filter('setpts', expr='PTS-STARTPTS')
.output("trimmed/%s" % inputVideo)
.output("output/%s" % inputVideo)
.run(quiet=False)
)
def readForCSV():
# Changes working directory to the specified path. CHANGE DURING STANDALONE BUILD.
os.chdir("gitlab repo/nina-thesis")
if "trimmed" not in os.listdir():
os.mkdir("trimmed")
def readForCSV(inputVideoName):
if inputVideoName in os.listdir():
# Checks if there is a .csv in the directory. If there is, tries to trim according to timestamps.
# Expects even-sized appropriately timed timestamps in seconds of the input video.
# Example: {5, 33, 106, 180} -> Two intervals of length 28 and 74 seconds respectively.
fileFound = False
for file in os.listdir():
if file.endswith(".csv"):
fileFound = True
with open(file) as csvFile:
reader = csv.reader(csvFile, delimiter=",")
for row in reader:
logging.getLogger().info("Trimming file %s" % row[0])
trim(row[0], row[1:])
# Reads first row only.
trim(inputVideoName, reader.next())
break
if not fileFound:
# Log instead of print.
print("Input video file found, but no .csv file generated or found.")
else:
# Log instead of print.
print("Input video file not found.")
\ No newline at end of file
File added
File added
testingDetection.mp4, 101, 167, 480, 520, 700, 710
\ 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