From 81d79a1602cfc8627eb5969fc168324c439e865f Mon Sep 17 00:00:00 2001 From: mattmcw Date: Thu, 24 Nov 2022 12:10:05 -0500 Subject: [PATCH] Write hole punch file as json --- fourcell/normalize.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/fourcell/normalize.py b/fourcell/normalize.py index b795d9b..2d0407f 100644 --- a/fourcell/normalize.py +++ b/fourcell/normalize.py @@ -2,6 +2,7 @@ import sys import cv2 import numpy as np import math +from json import dumps from os.path import exists from common import image_resize, display, normalize_angle @@ -134,6 +135,15 @@ def find_hole_punches (img) : return holePunches +def simplify_hole_punches (holePunches) : + simple = {} + for hp in holePunches : + simple[hp['order']] = { + 'x' : hp['x'], + 'y' : hp['y'] + } + return simple + def correct_rotation (img, original, holePunches) : horizLines = [ (3, 1), @@ -349,9 +359,8 @@ print(f'Writing normalized image to {normalImage}') cv2.imwrite(normalImage, normal) evaluation = find_hole_punches(normal) +jsonOut = simplify_hole_punches(evaluation) -with open(f'{normalImage}.txt', 'w') as evalFile : - for hp in evaluation: - evalFile.write(f'{hp["order"] + 1} : {hp["x"]},{hp["y"]}\n') - -#display(normal) \ No newline at end of file +with open(f'{normalImage}.json', 'w') as output: + output.write(dumps(jsonOut, sort_keys = True, indent = 4)) + print(f'Wrote hole punch definition file to {normalImage}.json')