Video-Summary/main.py

67 lines
2.5 KiB
Python
Raw Permalink Normal View History

2020-09-22 18:25:06 +00:00
import os
import time
2022-09-11 09:25:36 +00:00
import argparse
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):
2022-09-11 09:25:36 +00:00
start_total = time.time()
2020-12-22 12:58:47 +00:00
2022-10-07 21:10:26 +00:00
if os.path.exists(config["cachePath"] + "_layers.txt"):
layers, contours, masks = Importer(config).import_raw_data()
2022-09-11 09:25:36 +00:00
layers = LayerFactory(config).extract_layers(contours, masks)
2020-10-16 08:36:52 +00:00
else:
2022-10-07 21:10:26 +00:00
contours, masks = ContourExtractor(config).extract_contours()
2022-09-11 09:25:36 +00:00
layers = LayerFactory(config).extract_layers(contours, masks)
2020-10-16 08:36:52 +00:00
2022-09-11 09:25:36 +00:00
layer_manager = LayerManager(config, layers)
layer_manager.clean_layers()
2020-12-22 12:58:47 +00:00
2022-01-09 19:25:44 +00:00
# layerManager.tagLayers()
2022-09-11 09:25:36 +00:00
if len(layer_manager.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(
2022-09-11 09:25:36 +00:00
config["w"], config["h"], [contour for layer in layer_manager.layers for contour in layer.bounds], 1920 / config["resizeWidth"]
2022-08-15 10:21:20 +00:00
)
2022-10-07 21:10:26 +00:00
heatmap.show_image()
#heatmap.save_image(config["outputPath"].split(".")[0] + "_heatmap.png") # not working yet
2022-01-09 11:25:22 +00:00
2022-09-11 09:25:36 +00:00
print(f"Exporting {len(contours)} Contours and {len(layer_manager.layers)} Layers")
Exporter(config).export(layer_manager.layers, contours, masks, raw=True, overlayed=True)
print("Total time: ", time.time() - start_total)
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-09-11 09:25:36 +00:00
parser = argparse.ArgumentParser(description='Extract movement from static camera recording')
parser.add_argument('input', metavar='input_file', type=str,
help='input video to extract movement from')
parser.add_argument('output', metavar='output_dir', type=str, nargs="?", default="output",
help='output directory to save results and cached files into')
2022-10-11 19:35:37 +00:00
parser.add_argument('config', metavar='config', type=str, nargs="?", default=None,
help='relative path to config.json')
2022-09-11 09:25:36 +00:00
args = parser.parse_args()
2022-10-11 19:35:37 +00:00
config = Config(args.config)
2022-08-15 10:20:28 +00:00
2022-09-11 09:25:36 +00:00
input_path = os.path.join(os.path.dirname(__file__), args.input)
output_path = os.path.join(os.path.dirname(__file__), args.output)
file_name = input_path.split("/")[-1]
2022-08-15 10:20:28 +00:00
2022-09-11 09:25:36 +00:00
config["inputPath"] = input_path
config["outputPath"] = os.path.join(output_path, file_name)
2022-10-07 21:10:26 +00:00
config["cachePath"] = os.path.join(output_path, file_name.split(".")[0])
2022-09-11 09:25:36 +00:00
config["w"], config["h"] = VideoReader(config).get_wh()
2022-08-15 10:20:28 +00:00
main(config)