-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmdapp.py
More file actions
50 lines (36 loc) · 1.53 KB
/
cmdapp.py
File metadata and controls
50 lines (36 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
import sys
import os
import logging
import preProcess
import plot
import applyOCR
import cv2
def main():
parser = argparse.ArgumentParser(description='Extract text from images.')
parser.add_argument('image_path', default="./imgs/", type=str, help='path to the image')
parser.add_argument('output_path', default="./runs/", type=str, help='path to save the extracted text')
parser.add_argument('--preprocess', action='store_true', help='preprocess the image')
parser.add_argument('--plot', action='store_true', help='plot the image')
args = parser.parse_args()
if not os.path.exists(args.image_path):
logging.error('Image path does not exist.')
sys.exit(1)
if args.preprocess:
preProcess.ImagePreprocessor()
# multiple preprocess methods can be applied here
# for example, apply thresholding to the image
image = cv2.imread(args.image_path)
image = preProcess.ImagePreprocessor.grayScale(image)
image = preProcess.ImagePreprocessor.removeNoise(image)
#image = preProcess.ImagePreprocessor.thresholding(image)
#image = preProcess.ImagePreprocessor.canny(image)
if args.plot:
plot.plotImage(image, 'Preprocessed Image')
# apply OCR to preprocessed image
text = applyOCR.applyOCR(image)
applyOCR.saveText(text)
logging.info('Text extracted successfully.')
logging.info(f'Text saved to {args.output_path}')
if __name__ == '__main__':
main()