multiple contours
This commit is contained in:
parent
04187cf9ac
commit
ec4812bee1
|
|
@ -45,16 +45,16 @@ class Exporter:
|
|||
continue
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
|
||||
|
||||
frame2 = underlay
|
||||
for layer in layers:
|
||||
if layer.startFrame <= frameCount and layer.startFrame + len(layer.bounds) > frameCount:
|
||||
(x, y, w, h) = layer.bounds[frameCount - layer.startFrame]
|
||||
for (x, y, w, h) in layer.bounds[frameCount - layer.startFrame]:
|
||||
factor = videoReader.w / self.resizeWidth
|
||||
x = int(x * factor)
|
||||
y = int(y * factor)
|
||||
w = int(w * factor)
|
||||
h = int(h * factor)
|
||||
frame2 = underlay
|
||||
|
||||
frame2[y:y+h, x:x+w] = frame[y:y+h, x:x+w]
|
||||
writer.append_data(frame2)
|
||||
|
||||
|
|
@ -84,6 +84,7 @@ class Exporter:
|
|||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
for layer in layers:
|
||||
if layer.startFrame <= frameCount and layer.startFrame + len(layer.bounds) > frameCount:
|
||||
for (x, y, w, h) in layer.bounds[frameCount - layer.startFrame]:
|
||||
(x, y, w, h) = layer.bounds[frameCount - layer.startFrame]
|
||||
factor = videoReader.w / self.resizeWidth
|
||||
x = int(x * factor)
|
||||
|
|
|
|||
11
Layer.py
11
Layer.py
|
|
@ -2,7 +2,7 @@ import numpy as np
|
|||
import cv2
|
||||
import imutils
|
||||
class Layer:
|
||||
#data = [(contour, (x,y,w,h)),]
|
||||
#bounds = [(contour, (x,y,w,h)),]
|
||||
|
||||
startFrame = None
|
||||
lastFrame = None
|
||||
|
|
@ -14,14 +14,17 @@ class Layer:
|
|||
|
||||
self.data = []
|
||||
self.bounds = []
|
||||
self.bounds.append(data)
|
||||
self.bounds.append([data])
|
||||
#print("Layer constructed")
|
||||
|
||||
def add(self, frameNumber, data):
|
||||
if not (self.startFrame + len(self.bounds) - frameNumber < 0):
|
||||
if not self.startFrame + len(self.bounds) < frameNumber:
|
||||
if len(self.bounds[self.startFrame - frameNumber]) >= 1:
|
||||
self.bounds[self.startFrame - frameNumber].append(data)
|
||||
else:
|
||||
self.lastFrame = frameNumber
|
||||
self.bounds.append([data])
|
||||
|
||||
self.bounds.append(data)
|
||||
self.getLength()
|
||||
|
||||
def getLength(self):
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ class LayerFactory:
|
|||
layers = []
|
||||
for i, layer in enumerate(self.layers):
|
||||
checks = 0
|
||||
if abs(self.layers[i].bounds[0][0] - self.layers[i].bounds[-1][0]) < 5:
|
||||
if abs(self.layers[i].bounds[0][0][0] - self.layers[i].bounds[-1][0][0]) < 5:
|
||||
checks += 1
|
||||
if abs(self.layers[i].bounds[0][1] - self.layers[i].bounds[-1][1]) < 5:
|
||||
if abs(self.layers[i].bounds[0][0][1] - self.layers[i].bounds[-1][0][1]) < 5:
|
||||
checks += 1
|
||||
if checks <= 2:
|
||||
layers.append(layer)
|
||||
|
|
@ -71,11 +71,15 @@ class LayerFactory:
|
|||
oldLayerIDs.append(i)
|
||||
continue
|
||||
|
||||
(x2,y2,w2,h2) = self.layers[i].bounds[-1]
|
||||
for bounds in self.layers[i].bounds[-1]:
|
||||
if bounds is None:
|
||||
break
|
||||
(x2,y2,w2,h2) = bounds
|
||||
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))
|
||||
foundLayer = True
|
||||
break
|
||||
#break
|
||||
|
||||
if not foundLayer:
|
||||
self.layers.append(Layer(frameNumber, (x,y,w,h)))
|
||||
|
||||
|
|
|
|||
2
main.py
2
main.py
|
|
@ -15,7 +15,7 @@ def demo():
|
|||
start = time.time()
|
||||
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["outputPath"] = os.path.join(os.path.dirname(__file__), "./output/short.mp4")
|
||||
|
||||
contours = ContourExtractor(config).extractContours()
|
||||
|
|
|
|||
Loading…
Reference in New Issue