started Layer extraction
This commit is contained in:
parent
0d928b435c
commit
2d00ffcd1a
|
|
@ -21,10 +21,12 @@ class ContourExtractor:
|
|||
xDim = 0
|
||||
yDim = 0
|
||||
|
||||
def getextractedContours(self):
|
||||
return self.extractedContours
|
||||
|
||||
def __init__(self, videoPath):
|
||||
print("ContourExtractor initiated")
|
||||
|
||||
|
||||
min_area = self.min_area
|
||||
max_area = self.max_area
|
||||
threashold = self.threashold
|
||||
|
|
|
|||
12
Layer.py
12
Layer.py
|
|
@ -2,10 +2,16 @@ class Layer:
|
|||
#data = [(contour, (x,y,w,h)),]
|
||||
data = []
|
||||
startFrame = 0
|
||||
lastFrame = 0
|
||||
backgroundImage = []
|
||||
|
||||
def __init__(self, startFrame, data, backgroundImage):
|
||||
self.startFrame = startFrame
|
||||
self.data = data
|
||||
self.data.append(data)
|
||||
self.backgroundImage = backgroundImage
|
||||
|
||||
print("Layer constructed")
|
||||
|
||||
print("Layer constructed")
|
||||
|
||||
def add(self, frameNumber, data):
|
||||
self.lastFrame = frameNumber
|
||||
self.data.append(data)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,60 @@
|
|||
from Layer import Layer
|
||||
|
||||
class LayerFactory:
|
||||
def __init__(self):
|
||||
print("LayerFactory constructed")
|
||||
data = {}
|
||||
layers = []
|
||||
def __init__(self, data=None):
|
||||
print("LayerFactory constructed")
|
||||
self.data = data
|
||||
if data is not None:
|
||||
self.extractLayers(data)
|
||||
|
||||
def extractLayers(self, data = None):
|
||||
if self.data is None:
|
||||
if data is None:
|
||||
print("LayerFactory data was none")
|
||||
return None
|
||||
else:
|
||||
self.data = data
|
||||
|
||||
layers = []
|
||||
frameNumber = min(data)
|
||||
contours = data[frameNumber]
|
||||
|
||||
for contour in contours:
|
||||
layers.append(Layer(frameNumber, contour, None))
|
||||
|
||||
for frameNumber, contours in data.items():
|
||||
for layer in layers:
|
||||
if frameNumber - layer.lastFrame < 5:
|
||||
for contour, (x,y,w,h) in contours:
|
||||
if len(layer.data[-1][1]) != 4:
|
||||
print("LayerFactory: Layer knew no bounds")
|
||||
continue
|
||||
(x2,y2,w2,h2) = layer.data[-1][1]
|
||||
|
||||
if self.contoursOverlay((x,y+h), (x+w,y), (x2,y2+h2), (x2+w2,y2)):
|
||||
layer.add(frameNumber, (contour, (x,y,w,h)))
|
||||
else:
|
||||
layers.append(Layer(frameNumber, contour, None))
|
||||
|
||||
self.layers = layers
|
||||
|
||||
|
||||
def contoursOverlay(self, l1, r1, l2, r2):
|
||||
|
||||
# If one rectangle is on left side of other
|
||||
if(l1[0] >= r2[0] or l2[0] >= r1[0]):
|
||||
return False
|
||||
|
||||
# If one rectangle is above other
|
||||
if(l1[1] <= r2[1] or l2[1] <= r1[1]):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7
main.py
7
main.py
|
|
@ -2,6 +2,7 @@ import os
|
|||
import time
|
||||
from ContourExctractor import ContourExtractor
|
||||
from Exporter import Exporter
|
||||
from LayerFactory import LayerFactory
|
||||
#TODO
|
||||
# finden von relevanten Stellen anhand von zu findenen metriken für vergleichsbilder
|
||||
# X diff zu den ref bildern aufnehmen
|
||||
|
|
@ -10,14 +11,16 @@ from Exporter import Exporter
|
|||
|
||||
def demo():
|
||||
print("startup")
|
||||
footagePath = os.path.join(os.path.dirname(__file__), "./generate test footage/2.mp4")
|
||||
footagePath = os.path.join(os.path.dirname(__file__), "./generate test footage/out.mp4")
|
||||
|
||||
start = time.time()
|
||||
contourExtractor = ContourExtractor(footagePath)
|
||||
print("Time consumed in working: ",time.time() - start)
|
||||
|
||||
frames = contourExtractor.exportContours()
|
||||
Exporter().export(frames,os.path.join(os.path.dirname(__file__), "./short.mp4"))
|
||||
#Exporter().export(frames,os.path.join(os.path.dirname(__file__), "./short.mp4"))
|
||||
contours = contourExtractor.getextractedContours()
|
||||
layerFactory = LayerFactory(contourExtractor.extractedContours)
|
||||
|
||||
|
||||
def init():
|
||||
|
|
|
|||
Loading…
Reference in New Issue