contour can belong to up to 5 layers

This commit is contained in:
Askill 2020-10-20 22:25:23 +02:00
parent 079aaf4338
commit dd8debc9b7
4 changed files with 13 additions and 9 deletions

View File

@ -14,7 +14,8 @@ class Config:
"ttolerance": 60, "ttolerance": 60,
"videoBufferLength": 1000, "videoBufferLength": 1000,
"noiseThreashold": 0.05, "noiseThreashold": 0.05,
"noiseSensitivity": 3/4 "noiseSensitivity": 3/4,
"LayersPerContour": 5
} }
def __init__(self): def __init__(self):

View File

@ -101,22 +101,25 @@ class LayerFactory:
bounds = data[1] bounds = data[1]
(x,y,w,h) = bounds (x,y,w,h) = bounds
tol = self.tolerance tol = self.tolerance
foundLayer = False foundLayer = 0
for i in set(range(0, len(self.layers))).difference(set(self.oldLayerIDs)):
for i in range(0, len(self.layers)):
if i in self.oldLayerIDs:
continue
if frameNumber - self.layers[i].lastFrame > self.ttolerance: if frameNumber - self.layers[i].lastFrame > self.ttolerance:
self.oldLayerIDs.append(i) self.oldLayerIDs.append(i)
continue continue
for bounds in self.layers[i].bounds[-1]: for bounds in self.layers[i].bounds[-1]:
if bounds is None: if bounds is None or foundLayer >= self.config["LayersPerContour"]:
break break
(x2,y2,w2,h2) = bounds (x2,y2,w2,h2) = bounds
if self.contoursOverlay((x-tol,y+h+tol), (x+w+tol,y-tol), (x2,y2+h2), (x2+w2,y2)): if self.contoursOverlay((x-tol,y+h+tol), (x+w+tol,y-tol), (x2,y2+h2), (x2+w2,y2)):
self.layers[i].add(frameNumber, (x,y,w,h)) self.layers[i].add(frameNumber, (x,y,w,h))
foundLayer = True foundLayer += 1
break #break
if not foundLayer: if foundLayer == 0:
self.layers.append(Layer(frameNumber, (x,y,w,h), self.config)) self.layers.append(Layer(frameNumber, (x,y,w,h), self.config))
def contoursOverlay(self, l1, r1, l2, r2): def contoursOverlay(self, l1, r1, l2, r2):

View File

@ -16,7 +16,7 @@ def demo():
config = Config() config = Config()
config["inputPath"] = os.path.join(os.path.dirname(__file__), "generate test footage/out.mp4") config["inputPath"] = os.path.join(os.path.dirname(__file__), "generate test footage/3.mp4")
#config["importPath"] = os.path.join(os.path.dirname(__file__), "output/short.txt") #config["importPath"] = os.path.join(os.path.dirname(__file__), "output/short.txt")
config["outputPath"] = os.path.join(os.path.dirname(__file__), "output/short.mp4") config["outputPath"] = os.path.join(os.path.dirname(__file__), "output/short.mp4")
@ -31,7 +31,7 @@ def demo():
layerFactory = LayerFactory(config) layerFactory = LayerFactory(config)
layers = layerFactory.extractLayers(contours) layers = layerFactory.extractLayers(contours)
layerFactory.fillLayers() #layerFactory.fillLayers()
else: else:
layers = Importer(config).importRawData() layers = Importer(config).importRawData()

Binary file not shown.