Begin the calibrate script which will read the .txt file made by the normalize script. JSON would make more sense.
This commit is contained in:
parent
9b48e52736
commit
ab9e31b49e
|
@ -1 +1,2 @@
|
|||
env
|
||||
__pycache__
|
|
@ -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)
|
Loading…
Reference in New Issue