diff --git a/.gitignore b/.gitignore index eea7b5d..5c18a8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ generate test footage/images/ + +generate test footage/3.MP4 diff --git a/ContourExctractor.py b/ContourExctractor.py index 2299598..03ea153 100644 --- a/ContourExctractor.py +++ b/ContourExctractor.py @@ -15,9 +15,9 @@ class ContourExtractor: #X = {frame_number: [(contour, (x,y,w,h)), ...], } extractedContours = dict() - min_area = 200 - max_area = 30000 - threashold = 35 + min_area = 100 + max_area = 50000 + threashold = 12 xDim = 0 yDim = 0 @@ -50,6 +50,7 @@ class ContourExtractor: break frame = imutils.resize(frame, width=500) + frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray = cv2.GaussianBlur(gray, (5, 5), 0) diff --git a/Exporter.py b/Exporter.py index 4936acd..683c1e5 100644 --- a/Exporter.py +++ b/Exporter.py @@ -38,3 +38,32 @@ class Exporter: writer.close() #cv2.destroyAllWindows() + + def exportOverlayed(self, layers, outputPath): + fps = self.fps + writer = imageio.get_writer(outputPath, fps=fps) + + maxLength = self.getMaxLengthOfLayers(layers) + + for i in range(maxLength): + frame1 = np.zeros(shape=[1080, 1920, 3], dtype=np.uint8) + frame1 = imutils.resize(frame1, width=512) + + for layer in layers: + data = layer.data + if len(layer.data) > i: + frame = layer.data[i] + (x, y, w, h) = frame[1] + frame = frame[0] + + frame1[y:y+h, x:x+w] = frame + writer.append_data(np.array(frame1)) + writer.close() + + def getMaxLengthOfLayers(self, layers): + maxLength = 0 + for layer in layers: + if layer.getLength() > maxLength: + maxLength = layer.getLength() + return maxLength + diff --git a/Layer.py b/Layer.py index bdd809f..81be920 100644 --- a/Layer.py +++ b/Layer.py @@ -3,16 +3,23 @@ class Layer: startFrame = None lastFrame = None + length = None def __init__(self, startFrame, data): self.startFrame = startFrame self.lastFrame = startFrame + self.data = [] self.data.append(data) - print("Layer constructed") + #print("Layer constructed") def add(self, frameNumber, data): if not (self.startFrame + len(self.data) - frameNumber < 0): self.lastFrame = frameNumber self.data.append(data) + + def getLength(self): + self.length = len(self.data) + return self.length + diff --git a/LayerFactory.py b/LayerFactory.py index 4369d27..7b0e808 100644 --- a/LayerFactory.py +++ b/LayerFactory.py @@ -3,7 +3,7 @@ from Layer import Layer class LayerFactory: data = {} layers = [] - tolerance = -10 + tolerance = 5 def __init__(self, data=None): print("LayerFactory constructed") self.data = data diff --git a/__pycache__/ContourExctractor.cpython-37.pyc b/__pycache__/ContourExctractor.cpython-37.pyc index 496f1a7..91f68bb 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 bcdfd5e..3505af8 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 index 62c7a0f..2f83e59 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 87c4d50..8ba4258 100644 Binary files a/__pycache__/LayerFactory.cpython-37.pyc and b/__pycache__/LayerFactory.cpython-37.pyc differ diff --git a/main.py b/main.py index 6ca0693..49f460c 100644 --- a/main.py +++ b/main.py @@ -24,7 +24,7 @@ def demo(): contours = contourExtractor.getextractedContours() layerFactory = LayerFactory(contours) - Exporter().exportLayers(layerFactory.layers, os.path.join(os.path.dirname(__file__), "./short.mp4")) + Exporter().exportOverlayed(layerFactory.layers, os.path.join(os.path.dirname(__file__), "./short.mp4")) def init(): print("not needed yet") diff --git a/short.mp4 b/short.mp4 index 2141bf3..30dfecb 100644 Binary files a/short.mp4 and b/short.mp4 differ