【问题标题】:Google Vision API Document Text multiple images in base64 StringGoogle Vision API Document Text 多张图片,采用 base64 字符串
【发布时间】:2018-06-24 10:11:46
【问题描述】:

我使用 Google Vision API OCR(文档文本检测)从扫描的文档(base64 字符串)中获取文本。它适用于一张图片。但是我怎样才能发送多个图像,例如文档的第二页。

我尝试合并 base64 字符串,但它不起作用。

var base64ImagesArrayConcarved = base64ImagesArray.join('')

【问题讨论】:

  • 你是直接调用API还是使用客户端库?
  • 我通过 http 客户端直接从 ionic 3 App 中调用它
  • 我想避免多次请求。因此,我想将多个图像的base64字符串拼接在一个字符串中

标签: google-cloud-vision


【解决方案1】:

Cloud Vision API 有方法files.asyncBatchAnnotate。 这可以在同一个请求中发送一堆文件。要添加单个文件,请使用 async file annotation 请求。在批处理请求中包含两个图像的示例如下:

{
  "requests":[
    {
      "inputConfig": {
        "gcsSource": {
          "uri": "gs://<your bucket name>/image1.jpg"
        },
        "mimeType": "image/jpg"
      },
      "features": [
        {
          "type": "DOCUMENT_TEXT_DETECTION"
        }
      ],
      "outputConfig": {
        "gcsDestination": {
          "uri": "gs://<your bucket name>/output/"
        }
      }
    },
    {
      "inputConfig": {
        "gcsSource": {
          "uri": "gs://<your bucket name>/image2.jpg"
        },
        "mimeType": "image/jpg"
      },
      "features": [
        {
          "type": "DOCUMENT_TEXT_DETECTION"
        }
      ],
      "outputConfig": {
        "gcsDestination": {
          "uri": "gs://<your bucket name>/output/"
        }
      }
    }
  ]
}

如果您专门处理 pdf 文件,我发现 this post 解释了如何使用 asyncBatchAnnotate 发送请求。

【讨论】:

    猜你喜欢
    • 2018-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-10
    • 2019-06-11
    • 1970-01-01
    • 2018-05-14
    相关资源
    最近更新 更多