Video-Summary/main.py

70 lines
2.3 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-09-20 20:01:54 +00:00
2020-12-05 19:57:24 +00:00
2020-10-31 19:36:43 +00:00
def main():
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-18 20:27:19 +00:00
fileName = "3.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-05 19:57:24 +00:00
stats = dict()
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()
2020-12-05 19:57:24 +00:00
stats["Contour Extractor"] = time.time() - start
start = time.time()
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)
2020-12-05 19:57:24 +00:00
stats["Layer Factory"] = time.time() - start
start = time.time()
2020-10-16 08:36:52 +00:00
else:
2020-11-27 00:06:25 +00:00
layers, contours, masks = Importer(config).importRawData()
2020-12-13 20:36:04 +00:00
layerFactory = LayerFactory(config)
layers = layerFactory.extractLayers(contours, masks)
2020-10-16 08:36:52 +00:00
2020-10-31 19:36:43 +00:00
layerManager = LayerManager(config, layers)
layerManager.transformLayers()
2020-12-05 19:57:24 +00:00
stats["Layer Manager"] = time.time() - start
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
2020-12-18 20:27:19 +00:00
print([len(l) for l in sorted(layers, key = lambda c:len(c), reverse=True)[:20]])
if len(layers) == 0:
exit(1)
2020-10-16 08:36:52 +00:00
exporter = Exporter(config)
2020-11-08 15:28:47 +00:00
print(f"Exporting {len(contours)} Contours and {len(layers)} Layers")
2020-12-18 20:27:19 +00:00
exporter.export(layers, contours, masks, raw=True, overlayed=False)
2020-12-05 19:57:24 +00:00
stats["Exporter"] = time.time() - start
print("Total time: ", time.time() - startTotal)
print(stats)
exit(0)
2020-10-05 20:24:38 +00:00
2020-09-20 20:01:54 +00:00
if __name__ == "__main__":
2020-10-31 19:36:43 +00:00
main()
2020-09-22 18:25:06 +00:00