This commit is contained in:
Askill 2020-09-25 19:52:41 +02:00
parent 2d00ffcd1a
commit 2ae7520d2a
9 changed files with 33 additions and 4 deletions

View File

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

View File

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

View File

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

Binary file not shown.

View File

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

BIN
out.mp4 Normal file

Binary file not shown.

BIN
short.mp4

Binary file not shown.