correct stats
This commit is contained in:
parent
c362de147c
commit
03b18a838e
|
|
@ -13,8 +13,7 @@ class Config:
|
||||||
"maxLength": None,
|
"maxLength": None,
|
||||||
"ttolerance": 60,
|
"ttolerance": 60,
|
||||||
"videoBufferLength": 500,
|
"videoBufferLength": 500,
|
||||||
"noiseThreashold": 0.25,
|
"noiseThreashold": 0.4,
|
||||||
"noiseSensitivity": 3/4,
|
|
||||||
"LayersPerContour": 20,
|
"LayersPerContour": 20,
|
||||||
"avgNum":10
|
"avgNum":10
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ class ContourExtractor:
|
||||||
firstFrame = self.averages.pop(frameCount, None)
|
firstFrame = self.averages.pop(frameCount, None)
|
||||||
|
|
||||||
if frameCount % (60*30) == 0:
|
if frameCount % (60*30) == 0:
|
||||||
print(f"{frameCount/(60*30)} Minutes processed in {round((time.time() - self.start), 2)} each")
|
print(f" \r {frameCount/(60*30)} Minutes processed in {round((time.time() - self.start), 2)} each", end='\r')
|
||||||
self.start = time.time()
|
self.start = time.time()
|
||||||
|
|
||||||
gray = self.prepareFrame(frame)
|
gray = self.prepareFrame(frame)
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,12 @@ class Exporter:
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
for i, layer in enumerate(layers):
|
for i, layer in enumerate(layers):
|
||||||
print(f"\r {i}/{len(layers)} {round(i/len(layers)*100,2)}% {round((time.time() - start)/(i+1), 2)}", end='\r')
|
print(f"\r {i}/{len(layers)} {round(i/len(layers)*100,2)}% {round((time.time() - start), 2)}s", end='\r')
|
||||||
|
|
||||||
if len(layer.bounds[0]) == 0:
|
if len(layer.bounds[0]) == 0:
|
||||||
continue
|
continue
|
||||||
|
if layer.stats["dev"] < 5:
|
||||||
|
continue
|
||||||
|
|
||||||
listOfFrames = self.makeListOfFrames([layer])
|
listOfFrames = self.makeListOfFrames([layer])
|
||||||
|
|
||||||
|
|
@ -75,6 +77,7 @@ class Exporter:
|
||||||
writer.append_data(frame2)
|
writer.append_data(frame2)
|
||||||
|
|
||||||
videoReader.thread.join()
|
videoReader.thread.join()
|
||||||
|
videoReader.vc.release()
|
||||||
writer.close()
|
writer.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -93,7 +96,7 @@ class Exporter:
|
||||||
while not videoReader.videoEnded():
|
while not videoReader.videoEnded():
|
||||||
frameCount, frame = videoReader.pop()
|
frameCount, frame = videoReader.pop()
|
||||||
if frameCount % (60*self.fps) == 0:
|
if frameCount % (60*self.fps) == 0:
|
||||||
print("Minutes processed: ", frameCount/(60*self.fps))
|
print("Minutes processed: ", frameCount/(60*self.fps), end="\r")
|
||||||
if frame is None:
|
if frame is None:
|
||||||
print("ContourExtractor: frame was None")
|
print("ContourExtractor: frame was None")
|
||||||
continue
|
continue
|
||||||
|
|
@ -117,6 +120,7 @@ class Exporter:
|
||||||
cv2.putText(frames[frameCount - layer.startFrame], str(int(frameCount/self.fps)), (int(x+w/2), int(y+h/2)), cv2.FONT_HERSHEY_SIMPLEX, 1,(255,255,255), 2)
|
cv2.putText(frames[frameCount - layer.startFrame], str(int(frameCount/self.fps)), (int(x+w/2), int(y+h/2)), cv2.FONT_HERSHEY_SIMPLEX, 1,(255,255,255), 2)
|
||||||
|
|
||||||
videoReader.thread.join()
|
videoReader.thread.join()
|
||||||
|
videoReader.vc.release()
|
||||||
|
|
||||||
self.fps = videoReader.getFPS()
|
self.fps = videoReader.getFPS()
|
||||||
fps = self.fps
|
fps = self.fps
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ class Layer:
|
||||||
#print("Layer constructed")
|
#print("Layer constructed")
|
||||||
|
|
||||||
def add(self, frameNumber, bound):
|
def add(self, frameNumber, bound):
|
||||||
'''Adds a bound'''
|
'''Adds a bound to the Layer at the layer index which corresponds to the given framenumber'''
|
||||||
if self.startFrame + len(self.bounds) - 1 > frameNumber:
|
if self.startFrame + len(self.bounds) - 1 > frameNumber:
|
||||||
if len(self.bounds[frameNumber - self.startFrame]) >= 1:
|
if len(self.bounds[frameNumber - self.startFrame]) >= 1:
|
||||||
self.bounds[frameNumber - self.startFrame].append(bound)
|
self.bounds[frameNumber - self.startFrame].append(bound)
|
||||||
|
|
@ -56,25 +56,20 @@ class Layer:
|
||||||
y = (bound[1] + bound[3]/2)
|
y = (bound[1] + bound[3]/2)
|
||||||
middles.append([x,y])
|
middles.append([x,y])
|
||||||
|
|
||||||
avgx = 0
|
avg = 0
|
||||||
avgy = 0
|
|
||||||
for i in range(1, len(middles), 2):
|
for i in range(1, len(middles), 2):
|
||||||
avgx += float(middles[i][0]-middles[i-1][0])/len(middles)
|
avg += (((float(middles[i][0]-middles[i-1][0])/len(middles))**2 + float(middles[i][1]-middles[i-1][1])/len(middles))**2)**(1/2)
|
||||||
avgy += float(middles[i][1]-middles[i-1][1])/len(middles)
|
|
||||||
self.stats = dict()
|
self.stats = dict()
|
||||||
self.stats["avg"] = round((avgx**2 + avgy**2)**(1/2),2)
|
self.stats["avg"] = round(avg,2)
|
||||||
|
|
||||||
x=0
|
x=0
|
||||||
y=0
|
for i in range(1, len(middles), 2):
|
||||||
for i in range(0, len(middles)):
|
x += (((((float(middles[i][0]-middles[i-1][0])/len(middles))**2 + float(middles[i][1]-middles[i-1][1])/len(middles))**2)**(1/2)) - avg)**2
|
||||||
x += (float(middles[i][0]) - avgx)**2
|
|
||||||
y += (float(middles[i][1]) - avgy)**2
|
|
||||||
|
|
||||||
x /= (len(middles)-1)
|
x /= (len(middles)-1)
|
||||||
y /= (len(middles)-1)
|
|
||||||
|
|
||||||
self.stats["var"] = round((x**2 + y**2)**(1/2),2)
|
self.stats["var"] = round(x,2)
|
||||||
self.stats["dev"] = round((x + y)**(1/2), 2)
|
self.stats["dev"] = round((x)**(1/2), 2)
|
||||||
|
|
||||||
|
|
||||||
def getLength(self):
|
def getLength(self):
|
||||||
|
|
@ -92,7 +87,6 @@ class Layer:
|
||||||
mapped = []
|
mapped = []
|
||||||
mapping = []
|
mapping = []
|
||||||
clusterCount = 1
|
clusterCount = 1
|
||||||
noiseSensitivity = self.config["noiseSensitivity"]
|
|
||||||
noiseThreashold = self.config["noiseThreashold"]
|
noiseThreashold = self.config["noiseThreashold"]
|
||||||
|
|
||||||
# calculates the middle of each contour in the 2d bounds[] and saves it in 1d list
|
# calculates the middle of each contour in the 2d bounds[] and saves it in 1d list
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class LayerFactory:
|
||||||
for frameNumber in sorted(data.keys()):
|
for frameNumber in sorted(data.keys()):
|
||||||
contours = data[frameNumber]
|
contours = data[frameNumber]
|
||||||
if frameNumber%5000 == 0:
|
if frameNumber%5000 == 0:
|
||||||
print("\r" + f" {int(round(frameNumber/max(data.keys()), 2)*100)}% done with Layer extraction", end='\r')
|
print(f" {int(round(frameNumber/max(data.keys()), 2)*100)}% done with Layer extraction", end='\r')
|
||||||
|
|
||||||
tmp = [[frameNumber, contour] for contour in contours]
|
tmp = [[frameNumber, contour] for contour in contours]
|
||||||
#pool.map(self.getLayers, tmp)
|
#pool.map(self.getLayers, tmp)
|
||||||
|
|
@ -71,12 +71,12 @@ class LayerFactory:
|
||||||
self.oldLayerIDs.append(i)
|
self.oldLayerIDs.append(i)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
lastXframes = 3
|
lastXframes = 5
|
||||||
if len(self.layers[i].bounds) < lastXframes:
|
if len(self.layers[i].bounds) < lastXframes:
|
||||||
lastXframes = len(self.layers[i].bounds)
|
lastXframes = len(self.layers[i].bounds)
|
||||||
lastBounds = [bound for bounds in self.layers[i].bounds[-lastXframes:] for bound in bounds]
|
lastBounds = [bound for bounds in self.layers[i].bounds[-lastXframes:] for bound in bounds]
|
||||||
|
|
||||||
for bounds in lastBounds:
|
for j, bounds in enumerate(lastBounds):
|
||||||
if bounds is None:
|
if bounds is None:
|
||||||
break
|
break
|
||||||
(x2,y2,w2,h2) = bounds
|
(x2,y2,w2,h2) = bounds
|
||||||
|
|
|
||||||
4
main.py
4
main.py
|
|
@ -14,7 +14,7 @@ def main():
|
||||||
start = time.time()
|
start = time.time()
|
||||||
config = Config()
|
config = Config()
|
||||||
|
|
||||||
fileName = "3.mp4"
|
fileName = "x23.mp4"
|
||||||
outputPath = os.path.join(os.path.dirname(__file__), "output")
|
outputPath = os.path.join(os.path.dirname(__file__), "output")
|
||||||
dirName = os.path.join(os.path.dirname(__file__), "generate test footage")
|
dirName = os.path.join(os.path.dirname(__file__), "generate test footage")
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ def main():
|
||||||
layers = layerManager.layers
|
layers = layerManager.layers
|
||||||
exporter = Exporter(config)
|
exporter = Exporter(config)
|
||||||
print(f"Exporting {len(contours)} Contours and {len(layers)} Layers")
|
print(f"Exporting {len(contours)} Contours and {len(layers)} Layers")
|
||||||
exporter.export(layers, contours, raw=True, overlayed=False)
|
exporter.export(layers, contours, raw=True, overlayed=True)
|
||||||
|
|
||||||
print("Total time: ", time.time() - start)
|
print("Total time: ", time.time() - start)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 313 KiB After Width: | Height: | Size: 314 KiB |
Loading…
Reference in New Issue