-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocr.py
112 lines (86 loc) · 2.68 KB
/
ocr.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# ocr module from easy ocr library
'''
How to use code
#from ocr import ankocr
#t=ankocr.get_text('test.jpeg')
t is the list of text detected in the document image
'''
# +from nis import cat
import convertapi
import requests
from PyPDF2 import PdfReader
import easyocr as eocr
import cv2
import numpy as np
import os
import sys
import pickle as pkl
import PyPDF2
import pdfplumber
from pdf2image import convert_from_path
class ankocr:
def __init__(self):
print("kr raha hu ruk ja..")
def get_text(image):
reader = eocr.Reader(['en'])
text = reader.readtext(image,detail=0)
return text
def get_adharid(image):
t = ankocr.get_text(image)
try:
return t[t.index('MALE')+1]
except:
return [t.index('FEMALE')+1]
def get_adharname(image):
t=ankocr.get_text(image)
try:
return t[t.index('Government of India')+2]
except:
return t[t.index('GOVERNMENT OF INDIA')+2]
# pan
def get_panid(image):
t=ankocr.get_text(image)
try:
return t[t.index('Permanent Account Number Card')+1]
except:
prompt= "not found or wrong data! manual action required"
return prompt
def get_panname(image):
t=ankocr.get_text(image)
try:
return t[t.index('NAME')+1]
except:
prompt= "not found or wrong data! manual action required"
return prompt
# pdf extract
# jee allotment
def get_appno(image):
t=ankocr.get_text(image)
# print(t)
try:
return t[t.index('Application Number:')+1]
except:
prompt= "not found or wrong data! manual action required"
return prompt
# 12th marks
def get_12_roll(image):
t=ankocr.get_text(image)
# print(t)
try:
return t[t.index('12th Roll Number:')+1]
except:
prompt= "not found or wrong data! manual action required"
return prompt
# print(ankocr.pdf_to_text('allotletter.pdf'))
# pdf to image by api
def api_p2i(file):
convertapi.api_secret = 'cGujnI0KQ05odKHs'
convertapi.convert('png', {
'File': 'allotletter.pdf'
}, from_format = 'pdf').save_files('save.png')
return 'save.png'
# delete image file
def delete(file):
os.remove(file)
return True
# ankocr.delete('save.png')