contour can belong to up to 5 layers
This commit is contained in:
parent
079aaf4338
commit
dd8debc9b7
|
|
@ -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):
|
||||||
|
|
|
||||||
|
|
@ -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):
|
||||||
|
|
|
||||||
4
main.py
4
main.py
|
|
@ -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()
|
||||||
|
|
||||||
|
|
|
||||||
BIN
output/short.txt
BIN
output/short.txt
Binary file not shown.
Loading…
Reference in New Issue