diff --git a/Application/Config.py b/Application/Config.py index 351abbc..1b57bf2 100644 --- a/Application/Config.py +++ b/Application/Config.py @@ -1,8 +1,12 @@ +import json +import os + + class Config: c = { "min_area": 300, "max_area": 900000, - "threashold": 7, + "threshold": 7, "resizeWidth": 700, "inputPath": None, "outputPath": None, @@ -16,8 +20,16 @@ class Config: "avgNum": 10, } - def __init__(self): + def __init__(self, config_path): """This is basically just a wrapper for a json / python dict""" + if os.path.isfile(config_path): + print("using supplied configuration at", config_path) + # fail if config can not be parsed + with open(config_path) as file: + self.c = json.load(file) + else: + print("using default configuration") + print("Current Config:") for key, value in self.c.items(): print(f"{key}:\t\t{value}") diff --git a/Application/ContourExctractor.py b/Application/ContourExctractor.py index df4f108..aebd639 100644 --- a/Application/ContourExctractor.py +++ b/Application/ContourExctractor.py @@ -29,7 +29,7 @@ class ContourExtractor: self.extracted_masks = dict() self.min_area = config["min_area"] self.max_area = config["max_area"] - self.threashold = config["threashold"] + self.threshold = config["threshold"] self.resize_width = config["resizeWidth"] self.video_path = config["inputPath"] self.x_dim = 0 @@ -74,7 +74,7 @@ class ContourExtractor: gray = self.prepare_frame(frame) frame_delta = cv2.absdiff(gray, first_frame) - thresh = cv2.threshold(frame_delta, self.threashold, 255, cv2.THRESH_BINARY)[1] + thresh = cv2.threshold(frame_delta, self.threshold, 255, cv2.THRESH_BINARY)[1] # dilate the thresholded image to fill in holes, then find contours thresh = cv2.dilate(thresh, None, iterations=10) # cv2.imshow("changes x", thresh) diff --git a/README.md b/README.md index 08a1c79..a17a117 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ On my configuration 1 minutes of of the original Video can be processed in about "min_area": 100, min area in pixels, of a single contour, smaller is ignored "max_area": 9000000, max area in pixels, of a single contour, larger is ignored - "threashold": 6, luminance difference threashold, sensitivity of movement detection + "threshold": 6, luminance difference threshold, sensitivity of movement detection "resizeWidth": 600, video is scaled down internally "inputPath": None, overwritten in main.py "outputPath": None, overwritten in main.py diff --git a/demo_config.json b/demo_config.json new file mode 100644 index 0000000..6b1c175 --- /dev/null +++ b/demo_config.json @@ -0,0 +1,16 @@ +{ + "min_area": 300, + "max_area": 900000, + "threshold": 7, + "resizeWidth": 700, + "inputPath": null, + "outputPath": null, + "maxLayerLength": 5000, + "minLayerLength": 40, + "tolerance": 20, + "maxLength": null, + "ttolerance": 50, + "videoBufferLength": 250, + "LayersPerContour": 220, + "avgNum": 10 +} \ No newline at end of file diff --git a/main.py b/main.py index 51c0b76..d6accac 100644 --- a/main.py +++ b/main.py @@ -47,9 +47,11 @@ if __name__ == "__main__": help='input video to extract movement from') parser.add_argument('output', metavar='output_dir', type=str, nargs="?", default="output", help='output directory to save results and cached files into') + parser.add_argument('config', metavar='config', type=str, nargs="?", default=None, + help='relative path to config.json') args = parser.parse_args() - config = Config() + config = Config(args.config) input_path = os.path.join(os.path.dirname(__file__), args.input) output_path = os.path.join(os.path.dirname(__file__), args.output)