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')) ...@@ -9,6 +9,7 @@ doc = yaml.load(open('freset.yaml', 'r'))
9 bil_op = doc["bilateralFilterData"] 9 bil_op = doc["bilateralFilterData"]
10 th_op = doc["thresholdData"] 10 th_op = doc["thresholdData"]
11 11
12 +
12 def main(): 13 def main():
13 parser = argparse.ArgumentParser(description='OCR program') 14 parser = argparse.ArgumentParser(description='OCR program')
14 parser.add_argument('img_file', type=str, help="Input Image File Name") 15 parser.add_argument('img_file', type=str, help="Input Image File Name")
...@@ -30,16 +31,17 @@ def tesseract_orc_to_file(img): ...@@ -30,16 +31,17 @@ def tesseract_orc_to_file(img):
30 with open('result\\foo.txt', "w") as f: 31 with open('result\\foo.txt', "w") as f:
31 f.write(text) 32 f.write(text)
32 33
33 -def select_freset(type, img): 34 +
35 +def select_freset(op, img):
34 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 36 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
35 - if type < 7: 37 + if op < 7:
36 gray = cv2.bilateralFilter(gray, int(bil_op[0]), int(bil_op[1]), int(bil_op[2])) 38 gray = cv2.bilateralFilter(gray, int(bil_op[0]), int(bil_op[1]), int(bil_op[2]))
37 - _, img = cv2.threshold(gray, int(th_op['threshVal'][type % 3]), 39 + _, img = cv2.threshold(gray, int(th_op['threshVal'][op % 3]),
38 - int(th_op['threshMax'][0]), cv2.THRESH_BINARY_INV if type%2 else cv2.THRESH_BINARY) 40 + int(th_op['threshMax'][0]), cv2.THRESH_BINARY_INV if op % 2 else cv2.THRESH_BINARY)
39 - elif type < 13: 41 + elif op < 13:
40 - _, img = cv2.threshold(gray, int(th_op['threshVal'][type % 3]), 42 + _, img = cv2.threshold(gray, int(th_op['threshVal'][op % 3]),
41 int(th_op['threshMax'][0]), 43 int(th_op['threshMax'][0]),
42 - cv2.THRESH_BINARY_INV if type % 2 else cv2.THRESH_BINARY) 44 + cv2.THRESH_BINARY_INV if op % 2 else cv2.THRESH_BINARY)
43 tesseract_orc_to_file(img) 45 tesseract_orc_to_file(img)
44 46
45 47
......