-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
34 lines (31 loc) · 844 Bytes
/
views.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 os
import sys
import pytesseract
import cv2
import requests
from urllib.parse import unquote
from flask import request
IMAGEPATH = "data"
def read_ocr():
"""
"""
content = request.json
image = content['image']
lang = content['lang']
config = content['config']
response = requests.get(image)
image_name = unquote(os.path.basename(image))
image_path = os.path.join(IMAGEPATH, image_name)
with open(image_path, 'wb') as file:
file.write(response.content)
img_arr = cv2.imread(image_path)
text = pytesseract.image_to_string(img_arr, lang=lang, config=config)
if os.path.isfile(image_path):
os.unlink(image_path)
return {"text":text}
def root():
"""
Root Endpoint
Returns: Link to the API documentation
"""
return {"API Documentation":''}