From ab654d77b45c427f68559fd0e960935bec59dacb Mon Sep 17 00:00:00 2001 From: Askill Date: Wed, 7 Oct 2020 15:07:01 +0200 Subject: [PATCH] added config object, not implemented yet --- Config.py | 26 ++++++++++++++++++++++++++ ContourExctractor.py | 11 +++++++---- LayerFactory.py | 2 +- main.py | 2 +- 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 Config.py diff --git a/Config.py b/Config.py new file mode 100644 index 0000000..c066923 --- /dev/null +++ b/Config.py @@ -0,0 +1,26 @@ + +class Config: + c = { + "min_area" : 500, + "max_area" : 28000, + "threashold" : 13, + "xDim" : 0, + "yDim" : 0, + "resizeWidth" : 512, + "inputPath" : "", + "outputPath": "", + "maxLayerLength": 1000, + "minLayerLength": 0, + "fps": 30, + "tolerance": 5, + "maxLength": None, + "" + } + __init__(self): + print(Current Config:) + + def __getitem__(self, key): + return self.c[key] + + def __setitem__(self, key, value): + return self.c[key] = value diff --git a/ContourExctractor.py b/ContourExctractor.py index 2aa5de2..57239ee 100644 --- a/ContourExctractor.py +++ b/ContourExctractor.py @@ -9,6 +9,7 @@ import traceback import _thread import imageio import numpy as np +import time class ContourExtractor: @@ -32,7 +33,7 @@ class ContourExtractor: threashold = self.threashold # initialize the first frame in the video stream - vs = VideoCapture(filename) + vs = cv2.VideoCapture(videoPath) res, image = vs.read() self.xDim = image.shape[1] @@ -41,6 +42,7 @@ class ContourExtractor: # loop over the frames of the video frameCount = 0 extractedContours = dict() + start = time.time() while res: if frameCount > 25*30*60: break @@ -55,7 +57,7 @@ class ContourExtractor: gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #gray = np.asarray(gray[:,:,1]/3 + gray[:,:,2]/3 + gray[:,:,0]/6).astype(np.uint8) - gray = cv2.GaussianBlur(gray, (5, 5), 0) + gray = cv2.GaussianBlur(gray, (10, 10), 0) # if the first frame is None, initialize it if firstFrame is None: @@ -83,9 +85,10 @@ class ContourExtractor: if len(contours) != 0: extractedContours[frameCount] = contours - if frameCount % (60*30) == 0: - print("Minutes processed: ", frameCount/(60*30)) frameCount += 1 + if frameCount % (60*30) == 0: + print(f"{frameCount/(60*30)} Minutes processed at {round((time.time() - start)/(frameCount/(30*60)), 2)}s per minute") + #cv2.imshow( "annotated", thresh ) #cv2.waitKey(10) & 0XFF diff --git a/LayerFactory.py b/LayerFactory.py index 808c5c6..d99215d 100644 --- a/LayerFactory.py +++ b/LayerFactory.py @@ -53,7 +53,7 @@ class LayerFactory: # inserts all the fucking contours as layers? for frameNumber, contours in data.items(): if frameNumber%5000 == 0: - print(frameNumber/max(data.keys())) + print(f"{round(frameNumber/max(data.keys()), 2)}% done with Layer extraction") for (x,y,w,h) in contours: foundLayer = False diff --git a/main.py b/main.py index 95a3cdd..3ec2b03 100644 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ def demo(): footagePath = os.path.join(os.path.dirname(__file__), "./generate test footage/3.mp4") #analyzer = Analyzer(footagePath) - print("Time consumed reading video: ", time.time() - start) + #print("Time consumed reading video: ", time.time() - start) contours = ContourExtractor().extractContours(footagePath, resizeWidth) print("Time consumed in working: ", time.time() - start) layerFactory = LayerFactory(contours)