diff --git a/ContourExctractor.py b/ContourExctractor.py index e22f638..9e708de 100644 --- a/ContourExctractor.py +++ b/ContourExctractor.py @@ -21,10 +21,12 @@ class ContourExtractor: xDim = 0 yDim = 0 + def getextractedContours(self): + return self.extractedContours + def __init__(self, videoPath): print("ContourExtractor initiated") - min_area = self.min_area max_area = self.max_area threashold = self.threashold diff --git a/Layer.py b/Layer.py index 676cee4..8de2e3a 100644 --- a/Layer.py +++ b/Layer.py @@ -2,10 +2,16 @@ class Layer: #data = [(contour, (x,y,w,h)),] data = [] startFrame = 0 + lastFrame = 0 backgroundImage = [] + def __init__(self, startFrame, data, backgroundImage): self.startFrame = startFrame - self.data = data + self.data.append(data) self.backgroundImage = backgroundImage - - print("Layer constructed") \ No newline at end of file + + print("Layer constructed") + + def add(self, frameNumber, data): + self.lastFrame = frameNumber + self.data.append(data) diff --git a/LayerFactory.py b/LayerFactory.py index 0334b72..912ce37 100644 --- a/LayerFactory.py +++ b/LayerFactory.py @@ -1,3 +1,60 @@ +from Layer import Layer + class LayerFactory: - def __init__(self): - print("LayerFactory constructed") \ No newline at end of file + data = {} + layers = [] + def __init__(self, data=None): + print("LayerFactory constructed") + self.data = data + if data is not None: + self.extractLayers(data) + + def extractLayers(self, data = None): + if self.data is None: + if data is None: + print("LayerFactory data was none") + return None + else: + self.data = data + + layers = [] + frameNumber = min(data) + contours = data[frameNumber] + + for contour in contours: + layers.append(Layer(frameNumber, contour, None)) + + for frameNumber, contours in data.items(): + for layer in layers: + if frameNumber - layer.lastFrame < 5: + for contour, (x,y,w,h) in contours: + if len(layer.data[-1][1]) != 4: + print("LayerFactory: Layer knew no bounds") + continue + (x2,y2,w2,h2) = layer.data[-1][1] + + if self.contoursOverlay((x,y+h), (x+w,y), (x2,y2+h2), (x2+w2,y2)): + layer.add(frameNumber, (contour, (x,y,w,h))) + else: + layers.append(Layer(frameNumber, contour, None)) + + self.layers = layers + + + def contoursOverlay(self, l1, r1, l2, r2): + + # If one rectangle is on left side of other + if(l1[0] >= r2[0] or l2[0] >= r1[0]): + return False + + # If one rectangle is above other + if(l1[1] <= r2[1] or l2[1] <= r1[1]): + return False + + return True + + + + + + diff --git a/__pycache__/ContourExctractor.cpython-37.pyc b/__pycache__/ContourExctractor.cpython-37.pyc index ae032db..428ed16 100644 Binary files a/__pycache__/ContourExctractor.cpython-37.pyc and b/__pycache__/ContourExctractor.cpython-37.pyc differ diff --git a/__pycache__/Exporter.cpython-37.pyc b/__pycache__/Exporter.cpython-37.pyc index 6ff4a19..d5459e6 100644 Binary files a/__pycache__/Exporter.cpython-37.pyc and b/__pycache__/Exporter.cpython-37.pyc differ diff --git a/__pycache__/Layer.cpython-37.pyc b/__pycache__/Layer.cpython-37.pyc new file mode 100644 index 0000000..d147627 Binary files /dev/null and b/__pycache__/Layer.cpython-37.pyc differ diff --git a/__pycache__/LayerFactory.cpython-37.pyc b/__pycache__/LayerFactory.cpython-37.pyc new file mode 100644 index 0000000..b57e6ab Binary files /dev/null and b/__pycache__/LayerFactory.cpython-37.pyc differ diff --git a/main.py b/main.py index 5df723f..60d3881 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import os import time from ContourExctractor import ContourExtractor from Exporter import Exporter +from LayerFactory import LayerFactory #TODO # finden von relevanten Stellen anhand von zu findenen metriken für vergleichsbilder # X diff zu den ref bildern aufnehmen @@ -10,14 +11,16 @@ from Exporter import Exporter def demo(): print("startup") - footagePath = os.path.join(os.path.dirname(__file__), "./generate test footage/2.mp4") + footagePath = os.path.join(os.path.dirname(__file__), "./generate test footage/out.mp4") start = time.time() contourExtractor = ContourExtractor(footagePath) print("Time consumed in working: ",time.time() - start) frames = contourExtractor.exportContours() - Exporter().export(frames,os.path.join(os.path.dirname(__file__), "./short.mp4")) + #Exporter().export(frames,os.path.join(os.path.dirname(__file__), "./short.mp4")) + contours = contourExtractor.getextractedContours() + layerFactory = LayerFactory(contourExtractor.extractedContours) def init():