merging layers
This commit is contained in:
parent
50dc1ef560
commit
d0ec1f4612
|
|
@ -11,3 +11,5 @@ __pycache__/
|
||||||
|
|
||||||
*.weights
|
*.weights
|
||||||
*.m4v
|
*.m4v
|
||||||
|
|
||||||
|
*.txt
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class Config:
|
||||||
"videoBufferLength": 500,
|
"videoBufferLength": 500,
|
||||||
"noiseThreashold": 0.25,
|
"noiseThreashold": 0.25,
|
||||||
"noiseSensitivity": 3/4,
|
"noiseSensitivity": 3/4,
|
||||||
"LayersPerContour": 2,
|
"LayersPerContour": 20,
|
||||||
"avgNum":10
|
"avgNum":10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class Layer:
|
||||||
avgx += float(middles[i][0]-middles[i-1][0])/len(middles)
|
avgx += float(middles[i][0]-middles[i-1][0])/len(middles)
|
||||||
avgy += float(middles[i][1]-middles[i-1][1])/len(middles)
|
avgy += float(middles[i][1]-middles[i-1][1])/len(middles)
|
||||||
self.stats = dict()
|
self.stats = dict()
|
||||||
self.stats["avg"] = [round(avgx,2), round(avgy, 2)]
|
self.stats["avg"] = round((avgx**2 + avgy**2)**(1/2),2)
|
||||||
|
|
||||||
x=0
|
x=0
|
||||||
y=0
|
y=0
|
||||||
|
|
@ -73,8 +73,8 @@ class Layer:
|
||||||
x /= (len(middles)-1)
|
x /= (len(middles)-1)
|
||||||
y /= (len(middles)-1)
|
y /= (len(middles)-1)
|
||||||
|
|
||||||
self.stats["var"] = [round(x,2),round(y, 2)]
|
self.stats["var"] = round((x**2 + y**2)**(1/2),2)
|
||||||
self.stats["dev"] = [round(x**(1/2), 2), round(y**(1/2),2)]
|
self.stats["dev"] = round((x + y)**(1/2), 2)
|
||||||
|
|
||||||
|
|
||||||
def getLength(self):
|
def getLength(self):
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ from Application.Exporter import Exporter
|
||||||
from multiprocessing.pool import ThreadPool
|
from multiprocessing.pool import ThreadPool
|
||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import copy
|
||||||
|
|
||||||
class LayerFactory:
|
class LayerFactory:
|
||||||
def __init__(self, config, data=None):
|
def __init__(self, config, data=None):
|
||||||
|
|
@ -57,6 +58,8 @@ class LayerFactory:
|
||||||
(x,y,w,h) = bounds
|
(x,y,w,h) = bounds
|
||||||
tol = self.tolerance
|
tol = self.tolerance
|
||||||
foundLayer = 0
|
foundLayer = 0
|
||||||
|
#to merge layers
|
||||||
|
foundLayerIDs = []
|
||||||
|
|
||||||
for i in range(0, len(self.layers)):
|
for i in range(0, len(self.layers)):
|
||||||
if foundLayer >= self.config["LayersPerContour"]:
|
if foundLayer >= self.config["LayersPerContour"]:
|
||||||
|
|
@ -80,11 +83,50 @@ class LayerFactory:
|
||||||
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 += 1
|
foundLayer += 1
|
||||||
|
foundLayerIDs.append(i)
|
||||||
break
|
break
|
||||||
|
|
||||||
if foundLayer == 0:
|
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))
|
||||||
|
|
||||||
|
if len(foundLayerIDs) > 1:
|
||||||
|
self.mergeLayers(foundLayerIDs)
|
||||||
|
|
||||||
|
def mergeLayers(self, foundLayerIDs):
|
||||||
|
|
||||||
|
layers = self.sortLayers(foundLayerIDs)
|
||||||
|
layer1 = layers[0]
|
||||||
|
for layerID in range(1, len(layers)):
|
||||||
|
layer2 = layers[layerID]
|
||||||
|
layer1 = self.merge2Layers(layer1, layer2)
|
||||||
|
|
||||||
|
self.layers[foundLayerIDs[0]] = layer1
|
||||||
|
|
||||||
|
layers = []
|
||||||
|
for i, layer in enumerate(self.layers):
|
||||||
|
if i not in foundLayerIDs[1:]:
|
||||||
|
layers.append(layer)
|
||||||
|
self.layers = layers
|
||||||
|
|
||||||
|
|
||||||
|
def merge2Layers(self, layer1, layer2):
|
||||||
|
"""Merges 2 Layers, Layer1 must start before Layer2"""
|
||||||
|
|
||||||
|
dSF = layer2.startFrame - layer1.startFrame
|
||||||
|
l1bounds = copy.deepcopy(layer1.bounds)
|
||||||
|
|
||||||
|
for i in range(len(layer2.bounds)):
|
||||||
|
bounds = layer2.bounds[i]
|
||||||
|
while dSF + i >= len(l1bounds):
|
||||||
|
l1bounds.append([])
|
||||||
|
for bound in bounds:
|
||||||
|
if bound not in l1bounds[dSF + i]:
|
||||||
|
l1bounds[dSF + i].append(bound)
|
||||||
|
|
||||||
|
layer1.bounds = l1bounds
|
||||||
|
return layer1
|
||||||
|
|
||||||
|
|
||||||
def contoursOverlay(self, l1, r1, l2, r2):
|
def contoursOverlay(self, l1, r1, l2, r2):
|
||||||
# If one rectangle is on left side of other
|
# If one rectangle is on left side of other
|
||||||
if(l1[0] >= r2[0] or l2[0] >= r1[0]):
|
if(l1[0] >= r2[0] or l2[0] >= r1[0]):
|
||||||
|
|
@ -93,3 +135,11 @@ class LayerFactory:
|
||||||
if(l1[1] <= r2[1] or l2[1] <= r1[1]):
|
if(l1[1] <= r2[1] or l2[1] <= r1[1]):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def sortLayers(self, foundLayerIDs):
|
||||||
|
layers = []
|
||||||
|
for layerID in foundLayerIDs:
|
||||||
|
layers.append(self.layers[layerID])
|
||||||
|
|
||||||
|
layers.sort(key = lambda c:c.startFrame)
|
||||||
|
return layers
|
||||||
4
main.py
4
main.py
|
|
@ -32,8 +32,8 @@ def main():
|
||||||
layers = layerFactory.extractLayers(contours)
|
layers = layerFactory.extractLayers(contours)
|
||||||
else:
|
else:
|
||||||
layers, contours = Importer(config).importRawData()
|
layers, contours = Importer(config).importRawData()
|
||||||
#layerFactory = LayerFactory(config)
|
layerFactory = LayerFactory(config)
|
||||||
#layers = layerFactory.extractLayers(contours)
|
layers = layerFactory.extractLayers(contours)
|
||||||
|
|
||||||
layerManager = LayerManager(config, layers)
|
layerManager = LayerManager(config, layers)
|
||||||
layerManager.transformLayers()
|
layerManager.transformLayers()
|
||||||
|
|
|
||||||
BIN
output/3.txt
BIN
output/3.txt
Binary file not shown.
BIN
output/out.txt
BIN
output/out.txt
Binary file not shown.
BIN
output/x23.txt
BIN
output/x23.txt
Binary file not shown.
Loading…
Reference in New Issue