Write hole punch file as json
This commit is contained in:
parent
ab9e31b49e
commit
81d79a1602
|
@ -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)
|
||||
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')
|
||||
|
|
Loading…
Reference in New Issue