-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathocr_itt.py
68 lines (56 loc) · 1.8 KB
/
ocr_itt.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from tesserocr import PyTessBaseAPI
import argparse
parser = argparse.ArgumentParser("Enter Image Path")
parser.add_argument('-i' , '--image' , help="Image Path")
args = parser.parse_args()
images = ['b.jpg']
images[0] = args.image
count = 0
count2 = 0
count3 = 0
with PyTessBaseAPI() as api:
for img in images:
api.Init(lang = 'hin')
api.SetImageFile(img)
# print api.AllWordConfidences()
arr = list(api.AllWordConfidences())
sumarr = sum(arr) / float(len(arr))
with PyTessBaseAPI() as api:
for img in images:
api.Init(lang = 'eng')
api.SetImageFile(img)
# print api.AllWordConfidences()
arr2 = list(api.AllWordConfidences())
sumarr2 = sum(arr2) / float(len(arr2))
with PyTessBaseAPI() as api:
for img in images:
api.Init(lang = 'spa')
api.SetImageFile(img)
# print api.AllWordConfidences()
arr3 = list(api.AllWordConfidences())
sumarr3 = sum(arr3) / float(len(arr3))
n = min(len(arr) , len(arr2) , len(arr3))
for i in range(0 , n):
if (arr[i] > arr2[i]) & (arr[i] > arr3[i]):
count += 1
elif (arr2[i] > arr[i]) & (arr2[i] > arr3[i]):
count2 += 1
elif (arr3[i] > arr[i]) & (arr3[i] > arr2[i]):
count3 += 1
else:
pass
if (count3 > count2) & (count3 > count):
print("Spanish")
print("Confidence score is " + str(sumarr3))
api.Init(lang = 'spa')
api.SetImageFile(images[0])
elif (count2 > count) & (count2 > count3):
print("English")
print("Confidence score is " + str(sumarr2))
api.Init(lang = 'eng')
api.SetImageFile(images[0])
else:
print ("Hindi")
print("Confidence score is " + str(sumarr))
api.Init(lang = 'hin')
api.SetImageFile(images[0])