added json config support
This commit is contained in:
parent
8c7bf95ff3
commit
a3504b77dd
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
4
main.py
4
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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue