better exporter for single layers

This commit is contained in:
Askill 2020-11-11 18:37:25 +01:00
parent acaf2dbfdc
commit 0df1bc2119
1 changed files with 35 additions and 24 deletions

View File

@ -5,6 +5,7 @@ from Application.Layer import Layer
import cv2 import cv2
from Application.VideoReader import VideoReader from Application.VideoReader import VideoReader
import pickle import pickle
import time
class Exporter: class Exporter:
fps = 30 fps = 30
@ -37,18 +38,28 @@ class Exporter:
self.fps = videoReader.getFPS() self.fps = videoReader.getFPS()
writer = imageio.get_writer(self.outputPath, fps=self.fps) writer = imageio.get_writer(self.outputPath, fps=self.fps)
start = time.time()
for i, layer in enumerate(layers):
print(f"{round(i/len(layers)*100,2)} {round((time.time() - start), 2)}")
start = time.time()
if len(layer.bounds[0]) == 0:
continue
listOfFrames = self.makeListOfFrames([layer])
videoReader = VideoReader(self.config, listOfFrames)
videoReader.fillBuffer()
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))
if frame is None:
print("ContourExtractor: frame was None")
continue
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame2 = np.copy(underlay) frame2 = np.copy(underlay)
for xi, layer in enumerate(layers):
if layer.startFrame <= frameCount and layer.startFrame + len(layer.bounds) > frameCount:
for (x, y, w, h) in layer.bounds[frameCount - layer.startFrame]: for (x, y, w, h) in layer.bounds[frameCount - layer.startFrame]:
if x is None: if x is None:
continue continue
@ -59,7 +70,7 @@ class Exporter:
h = int(h * factor) h = int(h * factor)
frame2[y:y+h, x:x+w] = np.copy(frame[y:y+h, x:x+w]) frame2[y:y+h, x:x+w] = np.copy(frame[y:y+h, x:x+w])
cv2.putText(frame2, str(xi) + " " + str(int(frameCount/self.fps)), (int(x+w/2), int(y+h/2)), cv2.FONT_HERSHEY_SIMPLEX, 1,(255,255,255), 2) cv2.putText(frame2, str(i) + " " + str(int(frameCount/self.fps)), (int(x+w/2), int(y+h/2)), cv2.FONT_HERSHEY_SIMPLEX, 1,(255,255,255), 2)
writer.append_data(frame2) writer.append_data(frame2)