contour export and import

This commit is contained in:
Askill 2020-10-16 10:36:52 +02:00
parent 73d1ddc74b
commit f907094d1a
6 changed files with 34 additions and 8 deletions

View File

@ -19,6 +19,8 @@ class Config:
print("Current Config:", self.c) print("Current Config:", self.c)
def __getitem__(self, key): def __getitem__(self, key):
if key not in self.c:
return None
return self.c[key] return self.c[key]
def __setitem__(self, key, value): def __setitem__(self, key, value):

View File

@ -4,7 +4,7 @@ import numpy as np
from Layer import Layer from Layer import Layer
import cv2 import cv2
from VideoReader import VideoReader from VideoReader import VideoReader
import pickle
class Exporter: class Exporter:
fps = 30 fps = 30
@ -105,6 +105,11 @@ class Exporter:
writer.close() writer.close()
def exportRawData(self, layers):
with open(self.outputPath.split(".")[-2] + ".txt", "wb+") as file:
pickle.dump(layers, file)
def getMaxLengthOfLayers(self, layers): def getMaxLengthOfLayers(self, layers):
maxLength = 0 maxLength = 0
for layer in layers: for layer in layers:

10
Importer.py Normal file
View File

@ -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

View File

@ -50,3 +50,4 @@ class Layer:

22
main.py
View File

@ -6,6 +6,7 @@ from LayerFactory import LayerFactory
from Analyzer import Analyzer from Analyzer import Analyzer
from VideoReader import VideoReader from VideoReader import VideoReader
from Config import Config from Config import Config
from Importer import Importer
import cv2 import cv2
#TODO #TODO
# finden von relevanten Stellen anhand von zu findenen metriken für vergleichsbilder # finden von relevanten Stellen anhand von zu findenen metriken für vergleichsbilder
@ -15,15 +16,22 @@ def demo():
start = time.time() start = time.time()
config = Config() config = Config()
config["inputPath"] = os.path.join(os.path.dirname(__file__), "./generate test footage/out.mp4") config["inputPath"] = os.path.join(os.path.dirname(__file__), "generate test footage/3.mp4")
config["outputPath"] = os.path.join(os.path.dirname(__file__), "./output/short.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() if config["importPath"] is None:
print("Time consumed extracting: ", time.time() - start) contours = ContourExtractor(config).extractContours()
layerFactory = LayerFactory(config) print("Time consumed extracting: ", time.time() - start)
layers = layerFactory.extractLayers(contours) layerFactory = LayerFactory(config)
layers = layerFactory.extractLayers(contours)
else:
layers = Importer(config).importRawData()
exporter = Exporter(config)
exporter.exportRawData(layers)
exporter.exportOverlayed(layers)
Exporter(config).exportOverlayed(layers)
print("Total time: ", time.time() - start) print("Total time: ", time.time() - start)
def init(): def init():

BIN
output/short.txt Normal file

Binary file not shown.