Write hole punch file as json

This commit is contained in:
Matt McWilliams 2022-11-24 12:10:05 -05:00
parent ab9e31b49e
commit 81d79a1602
1 changed files with 14 additions and 5 deletions

View File

@ -2,6 +2,7 @@ import sys
import cv2 import cv2
import numpy as np import numpy as np
import math import math
from json import dumps
from os.path import exists from os.path import exists
from common import image_resize, display, normalize_angle from common import image_resize, display, normalize_angle
@ -134,6 +135,15 @@ def find_hole_punches (img) :
return holePunches 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) : def correct_rotation (img, original, holePunches) :
horizLines = [ horizLines = [
(3, 1), (3, 1),
@ -349,9 +359,8 @@ print(f'Writing normalized image to {normalImage}')
cv2.imwrite(normalImage, normal) cv2.imwrite(normalImage, normal)
evaluation = find_hole_punches(normal) evaluation = find_hole_punches(normal)
jsonOut = simplify_hole_punches(evaluation)
with open(f'{normalImage}.txt', 'w') as evalFile : with open(f'{normalImage}.json', 'w') as output:
for hp in evaluation: output.write(dumps(jsonOut, sort_keys = True, indent = 4))
evalFile.write(f'{hp["order"] + 1} : {hp["x"]},{hp["y"]}\n') print(f'Wrote hole punch definition file to {normalImage}.json')
#display(normal)