diff --git a/Config.py b/Config.py index 620af3d..2f7d858 100644 --- a/Config.py +++ b/Config.py @@ -19,6 +19,8 @@ class Config: print("Current Config:", self.c) def __getitem__(self, key): + if key not in self.c: + return None return self.c[key] def __setitem__(self, key, value): diff --git a/Exporter.py b/Exporter.py index 41150f0..18751bc 100644 --- a/Exporter.py +++ b/Exporter.py @@ -4,7 +4,7 @@ import numpy as np from Layer import Layer import cv2 from VideoReader import VideoReader - +import pickle class Exporter: fps = 30 @@ -105,6 +105,11 @@ class Exporter: writer.close() + def exportRawData(self, layers): + with open(self.outputPath.split(".")[-2] + ".txt", "wb+") as file: + pickle.dump(layers, file) + + def getMaxLengthOfLayers(self, layers): maxLength = 0 for layer in layers: diff --git a/Importer.py b/Importer.py new file mode 100644 index 0000000..332df6a --- /dev/null +++ b/Importer.py @@ -0,0 +1,10 @@ +import pickle + +class Importer: + def __init__(self, config): + self.path = config["importPath"] + + def importRawData(self): + with open(self.path, "rb") as file: + layers = pickle.load(file) + return layers \ No newline at end of file diff --git a/Layer.py b/Layer.py index 901a725..8c5aaa0 100644 --- a/Layer.py +++ b/Layer.py @@ -47,6 +47,7 @@ class Layer: self.data[i] = frame[y:y+h, x:x+w] i+=1 cap.release() + diff --git a/main.py b/main.py index 4163eee..ac4e1d6 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ from LayerFactory import LayerFactory from Analyzer import Analyzer from VideoReader import VideoReader from Config import Config +from Importer import Importer import cv2 #TODO # finden von relevanten Stellen anhand von zu findenen metriken für vergleichsbilder @@ -15,15 +16,22 @@ def demo(): start = time.time() config = Config() - config["inputPath"] = os.path.join(os.path.dirname(__file__), "./generate test footage/out.mp4") - config["outputPath"] = os.path.join(os.path.dirname(__file__), "./output/short.mp4") + config["inputPath"] = os.path.join(os.path.dirname(__file__), "generate test footage/3.mp4") + #config["importPath"] = os.path.join(os.path.dirname(__file__), "output/short.txt") + config["outputPath"] = os.path.join(os.path.dirname(__file__), "output/short.mp4") - contours = ContourExtractor(config).extractContours() - print("Time consumed extracting: ", time.time() - start) - layerFactory = LayerFactory(config) - layers = layerFactory.extractLayers(contours) + if config["importPath"] is None: + contours = ContourExtractor(config).extractContours() + print("Time consumed extracting: ", time.time() - start) + layerFactory = LayerFactory(config) + layers = layerFactory.extractLayers(contours) + else: + layers = Importer(config).importRawData() - Exporter(config).exportOverlayed(layers) + exporter = Exporter(config) + exporter.exportRawData(layers) + exporter.exportOverlayed(layers) + print("Total time: ", time.time() - start) def init(): diff --git a/output/short.txt b/output/short.txt new file mode 100644 index 0000000..a552346 Binary files /dev/null and b/output/short.txt differ