first video synopsis working kinda jank tho
This commit is contained in:
parent
ea2891ff17
commit
40d6339c3c
|
|
@ -8,15 +8,17 @@ import os
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import traceback
|
import traceback
|
||||||
import _thread
|
import _thread
|
||||||
|
import imageio
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
class ContourExtractor:
|
class ContourExtractor:
|
||||||
|
|
||||||
#X = {frame_number: contours, }
|
#X = {frame_number: [(contour, (x,y,w,h)), ...], }
|
||||||
extractedContours = dict()
|
extractedContours = dict()
|
||||||
|
|
||||||
def __init__(self, videoPath):
|
def __init__(self, videoPath):
|
||||||
print("ContourExtractror initiated")
|
print("ContourExtractor initiated")
|
||||||
print(videoPath)
|
|
||||||
|
|
||||||
min_area = 100
|
min_area = 100
|
||||||
max_area = 30000
|
max_area = 30000
|
||||||
|
|
@ -37,10 +39,10 @@ class ContourExtractor:
|
||||||
# resize the frame, convert it to grayscale, and blur it
|
# resize the frame, convert it to grayscale, and blur it
|
||||||
if frame is None:
|
if frame is None:
|
||||||
return
|
return
|
||||||
#frame = imutils.resize(frame, width=500)
|
frame = imutils.resize(frame, width=500)
|
||||||
cv2.imshow( "frame", frame )
|
cv2.imshow( "frame", frame )
|
||||||
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
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 the first frame is None, initialize it
|
||||||
if firstFrame is None:
|
if firstFrame is None:
|
||||||
|
|
@ -58,15 +60,17 @@ class ContourExtractor:
|
||||||
cnts = imutils.grab_contours(cnts)
|
cnts = imutils.grab_contours(cnts)
|
||||||
|
|
||||||
# loop over the contours
|
# loop over the contours
|
||||||
|
contours = []
|
||||||
for c in cnts:
|
for c in cnts:
|
||||||
if cv2.contourArea(c) < min_area or cv2.contourArea(c) > max_area:
|
if cv2.contourArea(c) < min_area or cv2.contourArea(c) > max_area:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
(x, y, w, h) = cv2.boundingRect(c)
|
(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"
|
text = "Occupied"
|
||||||
|
|
||||||
self.extractedContours[frameCount] = cnts
|
self.extractedContours[frameCount] = contours
|
||||||
frameCount += 1
|
frameCount += 1
|
||||||
|
|
||||||
#cv2.imshow( "annotated", frame )
|
#cv2.imshow( "annotated", frame )
|
||||||
|
|
@ -77,14 +81,24 @@ class ContourExtractor:
|
||||||
|
|
||||||
values = self.extractedContours.values()
|
values = self.extractedContours.values()
|
||||||
frame = np.zeros(shape=[1080, 1920, 3], dtype=np.uint8)
|
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:
|
frame[y:y+v.shape[0], x:x+v.shape[1]] = v
|
||||||
for v in x:
|
frames.append(frame)
|
||||||
(x, y, w, h) = cv2.boundingRect(v)
|
writer.append_data(np.array(frame))
|
||||||
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
|
#cv2.imshow("changes overlayed", frame)
|
||||||
|
#cv2.waitKey(10) & 0XFF
|
||||||
|
#cv2.waitKey(0)
|
||||||
|
#cv2.destroyAllWindows()
|
||||||
|
|
||||||
cv2.imshow("changes overlayed", frame)
|
writer.close()
|
||||||
cv2.waitKey(0)
|
return frames
|
||||||
cv2.destroyAllWindows()
|
|
||||||
|
|
||||||
|
|
|
||||||
13
Exporter.py
13
Exporter.py
|
|
@ -1,3 +1,12 @@
|
||||||
|
import imageio
|
||||||
|
import numpy as np
|
||||||
class Exporter:
|
class Exporter:
|
||||||
def __init__(self):
|
fps = 30
|
||||||
print("Layer constructed")
|
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.
Binary file not shown.
17
main.py
17
main.py
|
|
@ -1,11 +1,14 @@
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from ContourExctractor import ContourExtractor
|
from ContourExctractor import ContourExtractor
|
||||||
|
from Exporter import Exporter
|
||||||
#TODO
|
#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")
|
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/out.mp4")
|
||||||
|
|
||||||
|
|
@ -13,11 +16,13 @@ def init():
|
||||||
contourExtractor = ContourExtractor(footagePath)
|
contourExtractor = ContourExtractor(footagePath)
|
||||||
print("Time consumed in working: ",time.time() - start)
|
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__":
|
if __name__ == "__main__":
|
||||||
init()
|
demo()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue