diff --git a/ContourExctractor.py b/ContourExctractor.py index 9e708de..8e16bc1 100644 --- a/ContourExctractor.py +++ b/ContourExctractor.py @@ -15,7 +15,7 @@ class ContourExtractor: #X = {frame_number: [(contour, (x,y,w,h)), ...], } extractedContours = dict() - min_area = 990 + min_area = 0 max_area = 30000 threashold = 25 xDim = 0 diff --git a/Exporter.py b/Exporter.py index e4969a5..82e54d9 100644 --- a/Exporter.py +++ b/Exporter.py @@ -1,5 +1,8 @@ import imageio +import imutils import numpy as np +from Layer import Layer +import cv2 class Exporter: fps = 30 @@ -12,3 +15,23 @@ class Exporter: for frame in frames: writer.append_data(np.array(frame)) writer.close() + + def exportLayers(self, layers, outputPath): + for layer in layers: + data = layer.data + fps = self.fps + writer = imageio.get_writer(outputPath, fps=fps) + for frame in data: + + + (x, y, w, h) = frame[1] + frame = frame[0] + frame1 = np.zeros(shape=[1080, 1920, 3], dtype=np.uint8) + frame1 = imutils.resize(frame1, width=512) + frame1[y:y+frame.shape[0], x:x+frame.shape[1]] = frame + writer.append_data(np.array(frame1)) + cv2.imshow("changes overlayed", frame) + cv2.waitKey(10) & 0XFF + + writer.close() + cv2.destroyAllWindows() diff --git a/LayerFactory.py b/LayerFactory.py index 912ce37..e5cdba8 100644 --- a/LayerFactory.py +++ b/LayerFactory.py @@ -25,7 +25,10 @@ class LayerFactory: layers.append(Layer(frameNumber, contour, None)) for frameNumber, contours in data.items(): - for layer in layers: + layerNum = len(layers) + i = 0 + while i < layerNum: + layer = layers[i] if frameNumber - layer.lastFrame < 5: for contour, (x,y,w,h) in contours: if len(layer.data[-1][1]) != 4: @@ -37,6 +40,8 @@ class LayerFactory: layer.add(frameNumber, (contour, (x,y,w,h))) else: layers.append(Layer(frameNumber, contour, None)) + layerNum = len(layers) + i+=1 self.layers = layers diff --git a/__pycache__/ContourExctractor.cpython-37.pyc b/__pycache__/ContourExctractor.cpython-37.pyc index 428ed16..a7f602b 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 d5459e6..b8adc05 100644 Binary files a/__pycache__/Exporter.cpython-37.pyc and b/__pycache__/Exporter.cpython-37.pyc differ diff --git a/__pycache__/LayerFactory.cpython-37.pyc b/__pycache__/LayerFactory.cpython-37.pyc index b57e6ab..c21679b 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 60d3881..f0bdff3 100644 --- a/main.py +++ b/main.py @@ -11,7 +11,7 @@ from LayerFactory import LayerFactory def demo(): print("startup") - footagePath = os.path.join(os.path.dirname(__file__), "./generate test footage/out.mp4") + footagePath = os.path.join(os.path.dirname(__file__), "./generate test footage/2.mp4") start = time.time() contourExtractor = ContourExtractor(footagePath) @@ -20,8 +20,9 @@ def demo(): frames = contourExtractor.exportContours() #Exporter().export(frames,os.path.join(os.path.dirname(__file__), "./short.mp4")) contours = contourExtractor.getextractedContours() - layerFactory = LayerFactory(contourExtractor.extractedContours) + layerFactory = LayerFactory(contourExtractor.extractedContours) + Exporter().exportLayers(layerFactory.layers, os.path.join(os.path.dirname(__file__), "./short.mp4")) def init(): print("not needed yet") diff --git a/out.mp4 b/out.mp4 new file mode 100644 index 0000000..992380d Binary files /dev/null and b/out.mp4 differ diff --git a/short.mp4 b/short.mp4 index 57dcc26..17e5e5f 100644 Binary files a/short.mp4 and b/short.mp4 differ