Your Name

main refactoring

Showing 1 changed file with 9 additions and 7 deletions
......@@ -9,6 +9,7 @@ doc = yaml.load(open('freset.yaml', 'r'))
bil_op = doc["bilateralFilterData"]
th_op = doc["thresholdData"]
def main():
parser = argparse.ArgumentParser(description='OCR program')
parser.add_argument('img_file', type=str, help="Input Image File Name")
......@@ -30,16 +31,17 @@ def tesseract_orc_to_file(img):
with open('result\\foo.txt', "w") as f:
f.write(text)
def select_freset(type, img):
def select_freset(op, img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
if type < 7:
if op < 7:
gray = cv2.bilateralFilter(gray, int(bil_op[0]), int(bil_op[1]), int(bil_op[2]))
_, img = cv2.threshold(gray, int(th_op['threshVal'][type % 3]),
int(th_op['threshMax'][0]), cv2.THRESH_BINARY_INV if type%2 else cv2.THRESH_BINARY)
elif type < 13:
_, img = cv2.threshold(gray, int(th_op['threshVal'][type % 3]),
_, img = cv2.threshold(gray, int(th_op['threshVal'][op % 3]),
int(th_op['threshMax'][0]), cv2.THRESH_BINARY_INV if op % 2 else cv2.THRESH_BINARY)
elif op < 13:
_, img = cv2.threshold(gray, int(th_op['threshVal'][op % 3]),
int(th_op['threshMax'][0]),
cv2.THRESH_BINARY_INV if type % 2 else cv2.THRESH_BINARY)
cv2.THRESH_BINARY_INV if op % 2 else cv2.THRESH_BINARY)
tesseract_orc_to_file(img)
......