diff --git a/Layer.py b/Layer.py index 75b0f62..20eaffc 100644 --- a/Layer.py +++ b/Layer.py @@ -1,8 +1,8 @@ class Layer: #data = [(contour, (x,y,w,h)),] data = [] - startFrame = 0 - lastFrame = 0 + startFrame = None + lastFrame = None backgroundImage = [] def __init__(self, startFrame, data): @@ -10,7 +10,7 @@ class Layer: self.lastFrame = startFrame self.data.append(data) - #print("Layer constructed") + print("Layer constructed") def add(self, frameNumber, data): self.lastFrame = frameNumber diff --git a/LayerFactory.py b/LayerFactory.py index 7c2c4ab..2df91c1 100644 --- a/LayerFactory.py +++ b/LayerFactory.py @@ -3,6 +3,7 @@ from Layer import Layer class LayerFactory: data = {} layers = [] + tolerance = 10 def __init__(self, data=None): print("LayerFactory constructed") self.data = data @@ -10,6 +11,8 @@ class LayerFactory: self.extractLayers(data) def extractLayers(self, data = None): + tol = self.tolerance + if self.data is None: if data is None: print("LayerFactory data was none") @@ -27,18 +30,24 @@ class LayerFactory: # inserts all the fucking contours as layers? for frameNumber, contours in data.items(): for contour, (x,y,w,h) in contours: - for layer in layers: + foundLayer = False + i = 0 + for i in range(0, len(layers)): + layer = layers[i] + + if len(layer.data[-1][1]) != 4: + # should never be called, hints at problem in ContourExtractor + print("LayerFactory: Layer knew no bounds") + continue + if frameNumber - layer.lastFrame <= 5: - if len(layer.data[-1][1]) != 4: - print("LayerFactory: Layer knew no bounds") - continue - (x2,y2,w2,h2) = layer.data[-1][1] - tol = 10 if self.contoursOverlay((x-tol,y+h+tol), (x+w+tol,y-tol), (x2,y2+h2), (x2+w2,y2)): + foundLayer = True layer.add(frameNumber, (contour, (x,y,w,h))) - break - + + layers[i] = layer + if not foundLayer: layers.append(Layer(frameNumber, (contour, (x,y,w,h)))) self.layers = layers diff --git a/__pycache__/Layer.cpython-37.pyc b/__pycache__/Layer.cpython-37.pyc index acbf747..ca0d5e4 100644 Binary files a/__pycache__/Layer.cpython-37.pyc and b/__pycache__/Layer.cpython-37.pyc differ diff --git a/__pycache__/LayerFactory.cpython-37.pyc b/__pycache__/LayerFactory.cpython-37.pyc index 35bf1b1..80ca3a9 100644 Binary files a/__pycache__/LayerFactory.cpython-37.pyc and b/__pycache__/LayerFactory.cpython-37.pyc differ diff --git a/short.mp4 b/short.mp4 index 17e5e5f..33764e0 100644 Binary files a/short.mp4 and b/short.mp4 differ