-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathocr_core.py
29 lines (29 loc) · 873 Bytes
/
ocr_core.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
try:
from PIL import Image
except ImportError:
import Image
from PIL import ImageEnhance
import pytesseract
from io import BytesIO
pytesseract.pytesseract.tesseract_cmd = '/app/.apt/usr/bin/tesseract'
def ocr_core(filename):
"""
This function will handle the core OCR processing of images.
"""
print(filename)
print(str(filename))
xyz=str(filename).split(" ")[1].split(".")
ima=Image.open(filename)
image=Image.open(filename)
print(xyz[len(xyz)-1].replace("'",""))
if xyz[len(xyz)-1].replace("'","")=="png":
print("MAnoj sir")
with BytesIO() as f:
ima.save(f, format='JPEG')
ima_jpg = ima.convert('RGB')
image = Image.open(ima_jpg)
try:
text = pytesseract.image_to_string(image,lang="eng+hin")
return text
except Exception as ex:
return ex