added json config support

This commit is contained in:
Askill 2022-10-11 21:35:37 +02:00
parent 8c7bf95ff3
commit a3504b77dd
5 changed files with 36 additions and 6 deletions

View File

@ -1,8 +1,12 @@
import json
import os
class Config: class Config:
c = { c = {
"min_area": 300, "min_area": 300,
"max_area": 900000, "max_area": 900000,
"threashold": 7, "threshold": 7,
"resizeWidth": 700, "resizeWidth": 700,
"inputPath": None, "inputPath": None,
"outputPath": None, "outputPath": None,
@ -16,8 +20,16 @@ class Config:
"avgNum": 10, "avgNum": 10,
} }
def __init__(self): def __init__(self, config_path):
"""This is basically just a wrapper for a json / python dict""" """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:") print("Current Config:")
for key, value in self.c.items(): for key, value in self.c.items():
print(f"{key}:\t\t{value}") print(f"{key}:\t\t{value}")

View File

@ -29,7 +29,7 @@ class ContourExtractor:
self.extracted_masks = dict() self.extracted_masks = dict()
self.min_area = config["min_area"] self.min_area = config["min_area"]
self.max_area = config["max_area"] self.max_area = config["max_area"]
self.threashold = config["threashold"] self.threshold = config["threshold"]
self.resize_width = config["resizeWidth"] self.resize_width = config["resizeWidth"]
self.video_path = config["inputPath"] self.video_path = config["inputPath"]
self.x_dim = 0 self.x_dim = 0
@ -74,7 +74,7 @@ class ContourExtractor:
gray = self.prepare_frame(frame) gray = self.prepare_frame(frame)
frame_delta = cv2.absdiff(gray, first_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 # dilate the thresholded image to fill in holes, then find contours
thresh = cv2.dilate(thresh, None, iterations=10) thresh = cv2.dilate(thresh, None, iterations=10)
# cv2.imshow("changes x", thresh) # cv2.imshow("changes x", thresh)

View File

@ -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 "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 "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 "resizeWidth": 600, video is scaled down internally
"inputPath": None, overwritten in main.py "inputPath": None, overwritten in main.py
"outputPath": None, overwritten in main.py "outputPath": None, overwritten in main.py

16
demo_config.json Normal file
View File

@ -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
}

View File

@ -47,9 +47,11 @@ if __name__ == "__main__":
help='input video to extract movement from') help='input video to extract movement from')
parser.add_argument('output', metavar='output_dir', type=str, nargs="?", default="output", parser.add_argument('output', metavar='output_dir', type=str, nargs="?", default="output",
help='output directory to save results and cached files into') 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() args = parser.parse_args()
config = Config() config = Config(args.config)
input_path = os.path.join(os.path.dirname(__file__), args.input) input_path = os.path.join(os.path.dirname(__file__), args.input)
output_path = os.path.join(os.path.dirname(__file__), args.output) output_path = os.path.join(os.path.dirname(__file__), args.output)