diff --git a/fourcell/calibrate.py b/fourcell/calibrate.py index efe6c22..a853dc7 100644 --- a/fourcell/calibrate.py +++ b/fourcell/calibrate.py @@ -4,7 +4,7 @@ import numpy as np import math from os.path import exists, basename from common import image_resize, display, normalize_angle -from json import load +from json import load,dumps DEBUG = True @@ -26,11 +26,8 @@ if len(sys.argv) < 2: print('Please provide path of normalized scan to calibrate to') exit(1) -if len(sys.argv) < 3: - print('Please provide path to output svg template') - exit(2) -normalImage = sys.argv[-2] +normalImage = sys.argv[-1] if not exists(normalImage) : print('Normalized scan does not exist, please provide one that does') @@ -42,7 +39,6 @@ if not exists(normalText) : print('Corresponding normalized scan text does not exist, please generate one') exit(3) -outputTmpl = sys.argv[-1] print(f'Calibrating to scan {basename(normalImage)}') @@ -59,7 +55,7 @@ if not orientation : print(f'Scan is not in portrait mode, exiting...') exit(3) -print(holePunches) +#print(holePunches) def get_distance(ref, point): # print('ref: {} , point: {}'.format(ref, point)) @@ -220,4 +216,87 @@ if DEBUG : cv2.line(clean, bottomRightBR, bottomRightBL, (0,0,255,), 3) cv2.line(clean, bottomRightTL, bottomRightBL, (0,0,255,), 3) +jsonOut = { + 'width' : width, + 'height' : height, + 'holePunches' : holePunches, + '0' : { + '0' : { + 'x' : bottomLeftTL[0], + 'y' : bottomLeftTL[1] + }, + '1' : { + 'x' : bottomLeftTR[0], + 'y' : bottomLeftTR[1] + }, + '2' : { + 'x' : bottomLeftBR[0], + 'y' : bottomLeftBR[1] + }, + '3' : { + 'x' : bottomLeftBL[0], + 'y' : bottomLeftBL[1] + } + }, + '1' : { + '0' : { + 'x' : topLeftTL[0], + 'y' : topLeftTL[1] + }, + '1' : { + 'x' : topLeftTR[0], + 'y' : topLeftTR[1] + }, + '2' : { + 'x' : topLeftBR[0], + 'y' : topLeftBR[1] + }, + '3' : { + 'x' : topLeftBL[0], + 'y' : topLeftBL[1] + } + }, + '2' : { + '0' : { + 'x' : topRightTL[0], + 'y' : topRightTL[1] + }, + '1' : { + 'x' : topRightTR[0], + 'y' : topRightTR[1] + }, + '2' : { + 'x' : topRightBR[0], + 'y' : topRightBR[1] + }, + '3' : { + 'x' : topRightBL[0], + 'y' : topRightBL[1] + } + }, + '3' : { + '0' : { + 'x' : bottomRightTL[0], + 'y' : bottomRightTL[1] + }, + '1' : { + 'x' : bottomRightTR[0], + 'y' : bottomRightTR[1] + }, + '2' : { + 'x' : bottomRightBR[0], + 'y' : bottomRightBR[1] + }, + '3' : { + 'x' : bottomRightBL[0], + 'y' : bottomRightBL[1] + } + } +} + +calibrationFile = f'{normalImage}.calibration.json' +with open(calibrationFile, 'w') as output: + output.write(dumps(jsonOut, sort_keys = True, indent = 4)) + print(f'Wrote calibration file to {calibrationFile}') + display(clean)