【问题标题】:how to directly send base 64 encoded string of image in google cloud vision API?如何在谷歌云视觉 API 中直接发送 base 64 编码的图像字符串?
【发布时间】:2021-05-04 14:36:59
【问题描述】:

我使用以下代码,它看起来像 client.text_detection 必须接收图像。相反,我只想发送图像的 base64 编码文本字符串。最好的方法是什么?

def detect_text(path): """Detects text in the file.""" client = vision.ImageAnnotatorClient()

    with io.open(path, 'rb') as image_file:
        content = image_file.read()
    
    image = vision.Image(content=content)
    response = client.text_detection(image=image)
    texts = response.text_annotations
    print('Texts:')
    
    for text in texts:
        print('\n"{}"'.format(text.description))
    
        vertices = (['({},{})'.format(vertex.x, vertex.y)
                    for vertex in text.bounding_poly.vertices])
    
        print('bounds: {}'.format(','.join(vertices)))
    
    if response.error.message:
        raise Exception(
            '{}\nFor more info on error messages, check: '
            'https://cloud.google.com/apis/design/errors'.format(
                response.error.message))

【问题讨论】:

  • 看起来您正在发送请求中的图像内容。你有错误吗?错误是什么?
  • 根据您的代码,我假设您正在关注此tutorial。您不需要使用此 python 示例进行 base64 编码,它适用于您的图像路径。
  • 如果您仍然想只发送 base64 编码的字符串,您能告诉我们您到目前为止所做的尝试吗?

标签: python json google-cloud-platform encode google-vision


【解决方案1】:
uploadImage() async {
const url = 'input web url here';
const header = {
  "Content-Type": "application/json",
  "Api-Key": "input key here"
};`enter code here`
if(uploadimage == null) return;
String base64Image = base64Encode(uploadimage.readAsBytesSync());

var body = jsonEncode({
  'images': [base64Image],
 
});

final response = await http.post(url, headers: header, body: body);


print(response.statusCode);

【讨论】:

    猜你喜欢
    • 2018-01-23
    • 1970-01-01
    • 2018-07-21
    • 2019-07-28
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多