Commit cabbffe9 authored by Michael Murtaugh's avatar Michael Murtaugh

separate features in json

parent 715d09d3
......@@ -7,9 +7,41 @@ from analyze_image import analyze_image
p = ArgumentParser("")
p.add_argument("--cascades", default="./haarcascades", help="location of the cascade XML files, default: ./haarcascades")
p.add_argument("--settings", default="settings.json", help="settings file, default settings.json")
p.add_argument("--resize", default=False, action="store_true")
p.add_argument("--width", type=int, default=640, help="pre-detect resize width")
p.add_argument("--height", type=int, default=480, help="pre-detect resize height")
p.add_argument("--background", default="255,255,255")
p.add_argument("--pad", default=False, action="store_true")
p.add_argument("input", nargs="*", default=[])
args = p.parse_args()
background = tuple([int(x) for x in args.background.split(",")])
def resize (img, w, h, interpolation = cv2.INTER_CUBIC):
ih, iw, ic = img.shape
if (ih > h) or (iw > w):
# try fitting width
sw = w
sh = int(sw * (float(ih)/iw))
if sh > h:
# fit height instead
sh = h
sw = int(sh * (float(iw)/ih))
return cv2.resize(img, (sw, sh), interpolation=interpolation)
return img
def pad (img, w, h, color=(0, 0, 0)):
ih, iw, ic = img.shape
top = (h - ih) / 2
bottom = h - ih - top
left = (w - iw) / 2
right = (w - iw - left)
return cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color)
with open (args.settings) as f:
settings = json.load(f)
......@@ -68,8 +100,14 @@ features = init_features(settings['features'])
for i, path in enumerate(inputs):
print ("{0}/{1} {2}".format(i, numinput, path), file=sys.stderr)
img = cv2.imread(path)
if args.resize:
img = resize(img, args.width, args.height)
if args.pad:
img = pad(img, args.width, args.height, background)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
item = process_features(gray, features)
item['path'] = path
item_features = process_features(gray, features)
item = {"path": path, "features": item_features}
output.append(item)
print (json.dumps(output, indent=2))
......@@ -19,11 +19,10 @@ facecount = 0
eyecount = 0
counts = {}
for x in od:
for key in x.keys():
if key != "path":
if key not in counts:
counts[key] = 0
counts[key] += len(x[key])
for key in x['features'].keys():
if key not in counts:
counts[key] = 0
counts[key] += len(x['features'][key])
print (", ".join(["{0} {1}".format(counts[name], name) for name in sorted(counts.keys()) ] ))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment