2020-10-03 22:27:36 +00:00
|
|
|
import numpy as np
|
|
|
|
|
import cv2
|
|
|
|
|
import imutils
|
2020-09-20 20:01:54 +00:00
|
|
|
class Layer:
|
2020-10-13 22:16:39 +00:00
|
|
|
#bounds = [[(x,y,w,h), ],]
|
2020-09-29 20:23:04 +00:00
|
|
|
|
2020-09-29 19:53:35 +00:00
|
|
|
startFrame = None
|
|
|
|
|
lastFrame = None
|
2020-09-30 17:22:10 +00:00
|
|
|
length = None
|
2020-09-24 20:48:04 +00:00
|
|
|
|
2020-09-28 20:28:23 +00:00
|
|
|
def __init__(self, startFrame, data):
|
2020-09-24 15:14:59 +00:00
|
|
|
self.startFrame = startFrame
|
2020-09-28 20:28:23 +00:00
|
|
|
self.lastFrame = startFrame
|
2020-09-30 17:22:10 +00:00
|
|
|
|
2020-09-29 20:23:04 +00:00
|
|
|
self.data = []
|
2020-10-03 22:27:36 +00:00
|
|
|
self.bounds = []
|
2020-10-11 20:54:12 +00:00
|
|
|
self.bounds.append([data])
|
2020-09-30 17:22:10 +00:00
|
|
|
#print("Layer constructed")
|
2020-09-24 20:48:04 +00:00
|
|
|
|
|
|
|
|
def add(self, frameNumber, data):
|
2020-10-11 20:54:12 +00:00
|
|
|
if not self.startFrame + len(self.bounds) < frameNumber:
|
|
|
|
|
if len(self.bounds[self.startFrame - frameNumber]) >= 1:
|
|
|
|
|
self.bounds[self.startFrame - frameNumber].append(data)
|
|
|
|
|
else:
|
2020-09-29 20:23:04 +00:00
|
|
|
self.lastFrame = frameNumber
|
2020-10-11 20:54:12 +00:00
|
|
|
self.bounds.append([data])
|
|
|
|
|
|
2020-10-05 20:24:38 +00:00
|
|
|
self.getLength()
|
|
|
|
|
|
2020-09-30 17:22:10 +00:00
|
|
|
def getLength(self):
|
2020-10-05 20:24:38 +00:00
|
|
|
self.length = len(self.bounds)
|
2020-09-30 17:22:10 +00:00
|
|
|
return self.length
|
2020-10-03 22:27:36 +00:00
|
|
|
|
2020-10-07 12:32:41 +00:00
|
|
|
def fill(self, inputPath, resizeWidth):
|
2020-10-03 22:27:36 +00:00
|
|
|
'''reads in the contour data, needed for export'''
|
|
|
|
|
|
|
|
|
|
cap = cv2.VideoCapture(inputPath)
|
|
|
|
|
self.data = [None]*len(self.bounds)
|
|
|
|
|
i = 0
|
|
|
|
|
cap.set(1, self.startFrame)
|
|
|
|
|
while i < len(self.bounds):
|
|
|
|
|
ret, frame = cap.read()
|
|
|
|
|
|
|
|
|
|
if ret:
|
2020-10-07 12:32:41 +00:00
|
|
|
frame = imutils.resize(frame, width=resizeWidth)
|
2020-10-03 22:27:36 +00:00
|
|
|
(x, y, w, h) = self.bounds[i]
|
|
|
|
|
self.data[i] = frame[y:y+h, x:x+w]
|
|
|
|
|
i+=1
|
|
|
|
|
cap.release()
|
2020-10-16 08:36:52 +00:00
|
|
|
|
2020-10-03 22:27:36 +00:00
|
|
|
|
|
|
|
|
|
2020-09-30 17:22:10 +00:00
|
|
|
|