first video synopsis working kinda jank tho

This commit is contained in:
Askill 2020-09-23 22:02:46 +02:00
parent ea2891ff17
commit 40d6339c3c
6 changed files with 51 additions and 23 deletions

View File

@ -8,15 +8,17 @@ import os
import numpy as np
import traceback
import _thread
import imageio
import numpy as np
class ContourExtractor:
#X = {frame_number: contours, }
#X = {frame_number: [(contour, (x,y,w,h)), ...], }
extractedContours = dict()
def __init__(self, videoPath):
print("ContourExtractror initiated")
print(videoPath)
print("ContourExtractor initiated")
min_area = 100
max_area = 30000
@ -37,10 +39,10 @@ class ContourExtractor:
# resize the frame, convert it to grayscale, and blur it
if frame is None:
return
#frame = imutils.resize(frame, width=500)
frame = imutils.resize(frame, width=500)
cv2.imshow( "frame", frame )
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (31, 31), 0)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
# if the first frame is None, initialize it
if firstFrame is None:
@ -58,15 +60,17 @@ class ContourExtractor:
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:
continue
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
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] = cnts
self.extractedContours[frameCount] = contours
frameCount += 1
#cv2.imshow( "annotated", frame )
@ -77,14 +81,24 @@ class ContourExtractor:
values = self.extractedContours.values()
frame = np.zeros(shape=[1080, 1920, 3], dtype=np.uint8)
#frame = imutils.resize(frame, width=500)
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]
#cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
for x in values:
for v in x:
(x, y, w, h) = cv2.boundingRect(v)
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()
cv2.imshow("changes overlayed", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
writer.close()
return frames

View File

@ -1,3 +1,12 @@
import imageio
import numpy as np
class Exporter:
def __init__(self):
print("Layer constructed")
fps = 30
def __init__(self, data, outputPath):
print("Exporter initiated")
fps = self.fps
writer = imageio.get_writer(outputPath, fps=fps)
for frame in data:
writer.append_data(np.array(frame))
writer.close()

Binary file not shown.

17
main.py
View File

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

BIN
short.mp4 Normal file

Binary file not shown.