easy-ocr / src /app.py
Hanchin's picture
feat(ocr): use base64 image
b6edd87 unverified
raw
history blame contribute delete
656 Bytes
from flask import Flask, request, jsonify
import easyocr
from PIL import Image
import base64
from io import BytesIO
app = Flask(__name__)
reader = easyocr.Reader(['ja', 'en'])
@app.route("/")
def index():
return "hello"
@app.route("/api/easy", methods=["POST"])
def easy():
json_data = request.get_json()
try:
image = json_data["image"]
except Exception:
raise Exception("Invalid Param")
if not isinstance(image, str) or image == "":
raise Exception("Invalid Param")
image = Image.open(BytesIO(base64.b64decode(image)))
texts = reader.readtext(image, detail=0)
return jsonify({"texts": texts})