overlay works

This commit is contained in:
Askill 2020-09-30 19:22:10 +02:00
parent 0ce61c655a
commit 5837e6330e
11 changed files with 45 additions and 6 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
generate test footage/images/
generate test footage/3.MP4

View File

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

View File

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

View File

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

View File

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

Binary file not shown.

Binary file not shown.

View File

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

BIN
short.mp4

Binary file not shown.