【问题标题】:Limiting the response from Google Cloud Vision API限制来自 Google Cloud Vision API 的响应
【发布时间】:2019-04-03 01:16:15
【问题描述】:

目前使用 google cloud vision api 从文档图像中提取文本。

现状 - API 运行良好,可返回大量数据,包括单词所在位置的边界框。

期望的结果 - 仅查询从图像中提取的单词,而不是所有关于单词边界框和顶点位置的元数据(这就像 99% 的响应并出来大约 250k,当我想要的只是文字时,这是一个巨大的浪费)

const vision = require('@google-cloud/vision');
const client = new vision.ImageAnnotatorClient();

// Performs label detection on the image file
client
  .documentTextDetection('../assets/images_to_ocr/IMG_0942-min.jpg')
  .then(results => {
    console.log('result:', result);

  })
  .catch(err => {
    console.error('ERROR:', err);
  });

【问题讨论】:

  • 我看到这个已经回答了,但是由于 GCV 工程师应该阅读了这些线程,所以这里有另一个对这个功能的请求。我得到了很多话,对于我不需要的大部分多余的东西来说,这是一个完整的兆字节。应该能够在请求中说明您要请求什么数据!

标签: google-cloud-vision


【解决方案1】:

目前,nodeJS 的 Google Cloud Vision 客户端库没有请求部分响应的选项,就像您所要求的那样。 无论如何,如果您只想显示文本而不是任何其他元数据,您可以像这样过滤响应:

const fullTextAnnotation = results[0].fullTextAnnotation;
console.log(`Full text: ${fullTextAnnotation.text}`);

你会在'fullTextAnnotation'中得到完整的响应,然后你可以得到fullTextAnnotation.text来只得到带有'\n'字符的文本来分隔文本块,没有任何元数据。

如果您对使用其他东西而不是 nodeJS 感兴趣,Java 客户端库具有用于 Annotate 类的 setFields() 方法,并且还可以从 API Explorer 中使用部分字段掩码来查看效果。

【讨论】:

    猜你喜欢
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 2016-06-02
    • 1970-01-01
    相关资源
    最近更新 更多