Video-Summary/main.py

56 lines
1.9 KiB
Python
Raw Normal View History

2020-09-22 18:25:06 +00:00
import os
import time
2021-02-04 22:14:07 +00:00
from Application.Config import Config
2020-10-18 15:36:34 +00:00
from Application.ContourExctractor import ContourExtractor
from Application.Exporter import Exporter
2022-01-09 11:25:22 +00:00
from Application.HeatMap import HeatMap
2020-10-18 15:36:34 +00:00
from Application.Importer import Importer
2021-02-04 22:14:07 +00:00
from Application.LayerFactory import LayerFactory
2020-10-23 22:14:43 +00:00
from Application.LayerManager import LayerManager
2021-02-04 22:14:07 +00:00
from Application.VideoReader import VideoReader
2020-09-20 20:01:54 +00:00
2022-08-15 10:20:28 +00:00
def main(config):
2020-12-05 19:57:24 +00:00
startTotal = time.time()
2020-12-22 12:58:47 +00:00
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-10-16 08:36:52 +00:00
layerFactory = LayerFactory(config)
2020-11-27 00:06:25 +00:00
layers = layerFactory.extractLayers(contours, masks)
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-22 12:58:47 +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)
2022-05-03 08:57:19 +00:00
layerManager.cleanLayers()
2020-12-22 12:58:47 +00:00
2022-01-09 19:25:44 +00:00
# layerManager.tagLayers()
2022-08-15 10:20:28 +00:00
if len(layerManager.layers) == 0:
2020-12-18 20:27:19 +00:00
exit(1)
2020-12-26 13:58:58 +00:00
2022-08-15 10:21:20 +00:00
heatmap = HeatMap(
config["w"], config["h"], [contour for layer in layerManager.layers for contour in layer.bounds], 1920 / config["resizeWidth"]
)
2022-01-09 11:25:22 +00:00
heatmap.showImage()
2022-08-15 10:20:28 +00:00
print(f"Exporting {len(contours)} Contours and {len(layerManager.layers)} Layers")
Exporter(config).export(layerManager.layers, contours, masks, raw=True, overlayed=True)
2020-12-05 19:57:24 +00:00
print("Total time: ", time.time() - startTotal)
2020-10-05 20:24:38 +00:00
2021-02-04 22:14:07 +00:00
2020-09-20 20:01:54 +00:00
if __name__ == "__main__":
2022-08-15 10:20:28 +00:00
config = Config()
fileName = "x23-1.mp4"
outputPath = os.path.join(os.path.dirname(__file__), "output")
inputDirPath = os.path.join(os.path.dirname(__file__), "generate test footage")
config["inputPath"] = os.path.join(inputDirPath, fileName)
config["outputPath"] = os.path.join(outputPath, fileName)
config["importPath"] = os.path.join(outputPath, fileName.split(".")[0] + ".txt")
config["w"], config["h"] = VideoReader(config).getWH()
main(config)