Video-Summary/main.py

94 lines
3.1 KiB
Python
Raw Normal View History

2020-09-22 18:25:06 +00:00
import os
import time
2020-10-18 15:36:34 +00:00
from Application.ContourExctractor import ContourExtractor
from Application.Exporter import Exporter
from Application.LayerFactory import LayerFactory
from Application.Analyzer import Analyzer
from Application.Config import Config
from Application.Importer import Importer
from Application.VideoReader import VideoReader
2020-10-23 22:14:43 +00:00
from Application.LayerManager import LayerManager
from Application.Classifiers import *
2020-12-20 18:46:11 +00:00
from itertools import product
import csv
def main(v1, v2, v3, v4):
2020-12-05 19:57:24 +00:00
startTotal = time.time()
start = startTotal
2020-10-11 15:09:49 +00:00
config = Config()
2020-09-24 13:47:49 +00:00
2020-12-20 18:46:11 +00:00
config["ce_average_threads"] = v1
config["ce_comp_threads"] = v2
config["lf_threads"] = v3
config["videoBufferLength"] = v4
fileName = "X23-1.mp4"
2020-11-08 15:28:47 +00:00
outputPath = os.path.join(os.path.dirname(__file__), "output")
dirName = os.path.join(os.path.dirname(__file__), "generate test footage")
2020-10-16 08:36:52 +00:00
2020-11-08 15:28:47 +00:00
config["inputPath"] = os.path.join(dirName, fileName)
config["outputPath"] = os.path.join(outputPath, fileName)
2020-10-18 15:36:34 +00:00
2020-11-08 15:28:47 +00:00
config["importPath"] = os.path.join(outputPath, fileName.split(".")[0] + ".txt")
config["w"], config["h"] = VideoReader(config).getWH()
2020-12-20 18:46:11 +00:00
stats = [config["ce_average_threads"], config["ce_comp_threads"], config["lf_threads"], config["videoBufferLength"]]
2020-11-08 15:28:47 +00:00
if not os.path.exists(config["importPath"]):
2020-11-27 00:06:25 +00:00
contours, masks = ContourExtractor(config).extractContours()
stats.append(time.time() - start)
2020-12-05 19:57:24 +00:00
start = time.time()
2020-12-20 18:46:11 +00:00
#print("Time consumed extracting contours: ", stats["Contour Extractor"])
2020-10-16 08:36:52 +00:00
layerFactory = LayerFactory(config)
2020-11-27 00:06:25 +00:00
layers = layerFactory.extractLayers(contours, masks)
stats.append(time.time() - start)
2020-12-05 19:57:24 +00:00
start = time.time()
2020-10-16 08:36:52 +00:00
else:
2020-12-20 18:46:11 +00:00
stats.append(0)
2020-11-27 00:06:25 +00:00
layers, contours, masks = Importer(config).importRawData()
2020-12-20 18:46:11 +00:00
layerFactory = LayerFactory(config)
layers = layerFactory.extractLayers(contours, masks)
stats.append(time.time() - start)
2020-10-16 08:36:52 +00:00
2020-10-31 19:36:43 +00:00
layerManager = LayerManager(config, layers)
layerManager.transformLayers()
stats.append(time.time() - start)
2020-12-05 19:57:24 +00:00
start = time.time()
2020-10-31 19:36:43 +00:00
2020-11-05 22:17:05 +00:00
#layerManager.tagLayers()
2020-10-31 19:36:43 +00:00
layers = layerManager.layers
#print([len(l) for l in sorted(layers, key = lambda c:len(c), reverse=True)[:20]])
2020-12-18 20:27:19 +00:00
if len(layers) == 0:
exit(1)
2020-10-16 08:36:52 +00:00
exporter = Exporter(config)
2020-12-20 18:46:11 +00:00
#print(f"Exporting {len(contours)} Contours and {len(layers)} Layers")
#exporter.export(layers, contours, masks, raw=False, overlayed=True)
stats.append(time.time() - start)
2020-12-05 19:57:24 +00:00
print("Total time: ", time.time() - startTotal)
stats.append(time.time() - startTotal)
2020-12-20 18:46:11 +00:00
with open("bm.csv", "a") as myfile:
writer = csv.writer(myfile)
writer.writerow(stats)
#print(stats)
exit(0)
2020-10-05 20:24:38 +00:00
2020-09-20 20:01:54 +00:00
if __name__ == "__main__":
2020-12-20 19:58:56 +00:00
ass = list(range(4, 18, 4))
bss = list(range(4, 18, 4))
2020-12-20 18:46:11 +00:00
css = list(range(1, 16, 8))
2020-12-20 19:58:56 +00:00
dss = list(range(100, 500, 200))
2020-12-20 18:46:11 +00:00
params = [ass, bss, css, dss]
params = list(product(*params))
counter = 0
for a,b,c,d in params:
print(f"{counter}/{len(params)} - {counter/len(params)} {a, b, c, d}")
counter += 1
main(a, b, c, d)
2020-09-22 18:25:06 +00:00