试图将base_64编码的图像传递给Google身份验证

问题描述 投票:0回答:1

所以我正在做一个小项目(一个宁静的服务,所以json格式,代码中未提及),其中代码接受base_64图像数据并将其解码为图像,因此我可以将其转换回图片,但我无法在图片上使用google vision(googel ocr)提取文本。唯一不起作用的部分是以下代码块:


from flask import Flask,request,jsonify
import os,io,re,glob,base64
from google.cloud import vision
from google.cloud.vision import types
from PIL import Image
app = Flask(__name__)
os.environ['GOOGLE_APPLICATION_CREDENTIALS']=r'date_scanner.json'
@app.route('/jason_example',methods=['POST'])
def jason_example():
    req_data=request.get_json()
    base_64_image_content=req_data['imgcnt']
#the issue starts from here 
    image = base64.b64decode(base_64_image_content)
    image=Image.open(io.BytesIO(image))
    image=vision.types.Image(content=content)
    response=client.text_detection(image=image)
    texts=response.text_annotations`
    enter code here
python-3.x base64 ocr google-vision
1个回答
0
投票

无需使用Image.open,无论如何我认为这是PIL方法。您应该可以使用base64.decodebytes将其直接解码为字节字符串,如this answer中所述,

© www.soinside.com 2019 - 2024. All rights reserved.