diff --git a/fourcell/.gitignore b/fourcell/.gitignore index 0a764a4..3cf8c6d 100644 --- a/fourcell/.gitignore +++ b/fourcell/.gitignore @@ -1 +1,2 @@ env +__pycache__ \ No newline at end of file diff --git a/fourcell/calibrate.py b/fourcell/calibrate.py new file mode 100644 index 0000000..b6de376 --- /dev/null +++ b/fourcell/calibrate.py @@ -0,0 +1,62 @@ +import sys +import cv2 +import numpy as np +import math +from os.path import exists, basename +from common import image_resize, display, normalize_angle + +#clockwise from top left +order = [ 1, 3, 4, 6, 5, 2 ] + +def read_text (textPath) : + holePunches = {} + with open(textPath) as t: + for line in t: + i = int(line[0]) + parts = line.split(' : ') + vals = parts[1].split(',') + holePunches[i] = { + 'x' : int(vals[0]), + 'y' : int(vals[1]) + } + return holePunches + +# +# CALIBRATE +# + +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] + +if not exists(normalImage) : + print('Normalized scan does not exist, please provide one that does') + exit(2) + +normalText = normalImage + '.txt' + +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)}') + +holePunches = read_text(normalText) +original = cv2.imread(normalImage) +img = original.copy() +height, width = img.shape[:2] +orientation = height > width + +if not orientation : + print(f'Scan is not in portrait mode, exiting...') + exit(3) + +display(img) \ No newline at end of file