layer factory fills layers
This commit is contained in:
parent
947b56b7e2
commit
079aaf4338
|
|
@ -13,7 +13,7 @@ class Config:
|
||||||
"maxLength": None,
|
"maxLength": None,
|
||||||
"ttolerance": 60,
|
"ttolerance": 60,
|
||||||
"videoBufferLength": 1000,
|
"videoBufferLength": 1000,
|
||||||
"noiseThreashold": 0.2,
|
"noiseThreashold": 0.05,
|
||||||
"noiseSensitivity": 3/4
|
"noiseSensitivity": 3/4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,4 +132,4 @@ class Exporter:
|
||||||
frameNumbers.update(
|
frameNumbers.update(
|
||||||
list(range(layer.startFrame, layer.startFrame + len(layer.bounds))))
|
list(range(layer.startFrame, layer.startFrame + len(layer.bounds))))
|
||||||
|
|
||||||
return list(frameNumbers)
|
return sorted(list(frameNumbers))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
from Application.Layer import Layer
|
from Application.Layer import Layer
|
||||||
from Application.Config import Config
|
from Application.Config import Config
|
||||||
|
from Application.VideoReader import VideoReader
|
||||||
|
from Application.Exporter import Exporter
|
||||||
from multiprocessing.pool import ThreadPool
|
from multiprocessing.pool import ThreadPool
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
class LayerFactory:
|
class LayerFactory:
|
||||||
def __init__(self, config, data=None):
|
def __init__(self, config, data=None):
|
||||||
|
|
@ -18,8 +22,6 @@ class LayerFactory:
|
||||||
if data is not None:
|
if data is not None:
|
||||||
self.extractLayers(data)
|
self.extractLayers(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def removeStaticLayers(self):
|
def removeStaticLayers(self):
|
||||||
'''Removes Layers with little to no movement'''
|
'''Removes Layers with little to no movement'''
|
||||||
layers = []
|
layers = []
|
||||||
|
|
@ -127,10 +129,32 @@ class LayerFactory:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def fillLayers(self):
|
def fillLayers(self):
|
||||||
for i in range(len(self.layers)):
|
|
||||||
|
listOfFrames = Exporter(self.config).makeListOfFrames(self.layers)
|
||||||
|
videoReader = VideoReader(self.config, listOfFrames)
|
||||||
|
videoReader.fillBuffer()
|
||||||
|
|
||||||
|
while not videoReader.videoEnded():
|
||||||
|
frameCount, frame = videoReader.pop()
|
||||||
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||||
|
for i, layer in enumerate(self.layers):
|
||||||
if i % 20 == 0:
|
if i % 20 == 0:
|
||||||
print(f"filled {int(round(i/len(self.layers),2)*100)}% of all Layers")
|
print(f"filled {int(round(i/len(self.layers),2)*100)}% of all Layers")
|
||||||
self.layers[i].fill(self.footagePath, self.resizeWidth)
|
|
||||||
|
if layer.startFrame <= frameCount and layer.startFrame + len(layer.bounds) > frameCount:
|
||||||
|
data = []
|
||||||
|
for (x, y, w, h) in layer.bounds[frameCount - layer.startFrame]:
|
||||||
|
if x is None:
|
||||||
|
break
|
||||||
|
factor = videoReader.w / self.resizeWidth
|
||||||
|
x = int(x * factor)
|
||||||
|
y = int(y * factor)
|
||||||
|
w = int(w * factor)
|
||||||
|
h = int(h * factor)
|
||||||
|
data.append(np.copy(frame[y:y+h, x:x+w]))
|
||||||
|
layer.data.append(data)
|
||||||
|
|
||||||
|
videoReader.thread.join()
|
||||||
|
|
||||||
def sortLayers(self):
|
def sortLayers(self):
|
||||||
self.layers.sort(key = lambda c:c.startFrame)
|
self.layers.sort(key = lambda c:c.startFrame)
|
||||||
|
|
|
||||||
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/3.mp4")
|
config["inputPath"] = os.path.join(os.path.dirname(__file__), "generate test footage/out.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")
|
||||||
|
|
||||||
|
|
@ -29,7 +29,9 @@ def demo():
|
||||||
contours = ContourExtractor(config).extractContours()
|
contours = ContourExtractor(config).extractContours()
|
||||||
print("Time consumed extracting: ", time.time() - start)
|
print("Time consumed extracting: ", time.time() - start)
|
||||||
layerFactory = LayerFactory(config)
|
layerFactory = LayerFactory(config)
|
||||||
|
|
||||||
layers = layerFactory.extractLayers(contours)
|
layers = layerFactory.extractLayers(contours)
|
||||||
|
layerFactory.fillLayers()
|
||||||
else:
|
else:
|
||||||
layers = Importer(config).importRawData()
|
layers = Importer(config).importRawData()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue