utilized exporter module

This commit is contained in:
Askill 2020-09-24 15:47:49 +02:00
parent 40d6339c3c
commit b45efb1c86
7 changed files with 28 additions and 29 deletions

View File

@ -15,32 +15,38 @@ class ContourExtractor:
#X = {frame_number: [(contour, (x,y,w,h)), ...], }
extractedContours = dict()
min_area = 990
max_area = 30000
threashold = 25
xDim = 0
yDim = 0
def __init__(self, videoPath):
print("ContourExtractor initiated")
min_area = 100
max_area = 30000
threashold = 10
min_area = self.min_area
max_area = self.max_area
threashold = self.threashold
# initialize the first frame in the video stream
vs = cv2.VideoCapture(videoPath)
res = vs.read()[0]
res, image = vs.read()
self.xDim = image.shape[1]
self.yDim = image.shape[0]
firstFrame = None
# loop over the frames of the video
frameCount = 0
while res:
res, frame = vs.read()
# resize the frame, convert it to grayscale, and blur it
if frame is None:
print("ContourExtractor: frame was None")
return
frame = imutils.resize(frame, width=500)
cv2.imshow( "frame", frame )
cv2.imshow( "frame", frame)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
@ -50,16 +56,12 @@ class ContourExtractor:
continue
frameDelta = cv2.absdiff(gray, firstFrame)
thresh = cv2.threshold(frameDelta, threashold, 255, cv2.THRESH_BINARY)[1]
# dilate the thresholded image to fill in holes, then find contours
thresh = cv2.dilate(thresh, None, iterations=3)
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
# loop over the contours
contours = []
for c in cnts:
if cv2.contourArea(c) < min_area or cv2.contourArea(c) > max_area:
@ -68,8 +70,6 @@ class ContourExtractor:
(x, y, w, h) = cv2.boundingRect(c)
contours.append((frame[y:y+h, x:x+w], (x, y, w, h)))
#cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
text = "Occupied"
self.extractedContours[frameCount] = contours
frameCount += 1
@ -78,27 +78,22 @@ class ContourExtractor:
#cv2.waitKey(10) & 0XFF
def displayContours(self):
values = self.extractedContours.values()
frame = np.zeros(shape=[1080, 1920, 3], dtype=np.uint8)
frame = imutils.resize(frame, width=512)
frames = []
writer = imageio.get_writer(os.path.join(os.path.dirname(__file__), "./short.mp4"), fps=30)
for xx in values:
for v1 in xx:
(x, y, w, h) = v1[1]
v = v1[0]
frame = np.zeros(shape=[self.yDim, self.xDim, 3], dtype=np.uint8)
frame = imutils.resize(frame, width=512)
#cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
frame[y:y+v.shape[0], x:x+v.shape[1]] = v
frames.append(frame)
writer.append_data(np.array(frame))
#cv2.imshow("changes overlayed", frame)
#cv2.waitKey(10) & 0XFF
#cv2.waitKey(0)
#cv2.destroyAllWindows()
writer.close()
return frames

View File

@ -2,11 +2,14 @@ import imageio
import numpy as np
class Exporter:
fps = 30
def __init__(self, data, outputPath):
def __init__(self):
print("Exporter initiated")
def export(self, frames, outputPath):
fps = self.fps
writer = imageio.get_writer(outputPath, fps=fps)
for frame in data:
for frame in frames:
writer.append_data(np.array(frame))
writer.close()
writer.close()

Binary file not shown.

BIN
generate test footage/2.mp4 Normal file

Binary file not shown.

View File

@ -4,20 +4,21 @@ from ContourExctractor import ContourExtractor
from Exporter import Exporter
#TODO
# finden von relevanten Stellen anhand von zu findenen metriken für vergleichsbilder
# diff zu den ref bildern aufnehmen
# zeichenn on contour inhalt
# X diff zu den ref bildern aufnehmen
# zeichen von contour inhalt
# langes video
def demo():
print("startup")
footagePath = os.path.join(os.path.dirname(__file__), "./generate test footage/out.mp4")
footagePath = os.path.join(os.path.dirname(__file__), "./generate test footage/2.mp4")
start = time.time()
contourExtractor = ContourExtractor(footagePath)
print("Time consumed in working: ",time.time() - start)
frames = contourExtractor.displayContours()
#exporter = Exporter(frames,os.path.join(os.path.dirname(__file__), "./short.mp4"))
Exporter().export(frames,os.path.join(os.path.dirname(__file__), "./short.mp4"))
def init():
print("not needed yet")

BIN
short.mp4

Binary file not shown.