forked from AI-General/document-classification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassify.py
34 lines (25 loc) · 843 Bytes
/
classify.py
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
import sys
import easyocr
reader = easyocr.Reader(['en'])
def classify_image(image_path):
result = reader.readtext(image_path)
text = "Not Recognized"
for item in result:
if item[2] > 0.5 and ('1099-INT' in item[1] or '1099 - INT' in item[1]):
text = '1099-INT'
break
if text == "Not Recognized":
for item in result:
if item[2] > 0.5 and ('W-2' in item[1] or 'W - 2' in item[1]):
text = 'W-2'
break
return text
if __name__ == "__main__":
default_image_path = 'dataset/dataset/1099 - INT 2021.jpg'
# Check if an argument was provided
if len(sys.argv) > 1:
image_path = sys.argv[1]
else:
image_path = default_image_path
result = classify_image(image_path)
print("Document type: ", result)