【问题标题】:Google Vision API谷歌视觉 API
【发布时间】:2017-06-14 21:12:22
【问题描述】:

我正在尝试将数据发布到 Google Vision API。但我总是得到 400 响应代码 - 错误的请求。我已经没有想法了。

我已阅读并尝试使用这些链接:

https://cloud.google.com/vision/docs/requests-and-responses https://cloud.google.com/vision/docs/detecting-text https://developers.google.com/apis-explorer/?hl=ru#p/vision/v1/vision.images.annotate

我想到了这个:

这是我要发布的数据:

var dataToSend = {
        "requests": [
           {
               "image": {
                   "content": imageData
               },
               "features": [
                  {
                      "type": "TYPE_UNSPECIFIED",
                      "maxResults": 50
                  },
                  {
                      "type": "LANDMARK_DETECTION",
                      "maxResults": 50
                  },
                  {
                      "type": "FACE_DETECTION",
                      "maxResults": 50
                  },
                  {
                      "type": "LOGO_DETECTION",
                      "maxResults": 50
                  },
                  {
                      "type": "LABEL_DETECTION",
                      "maxResults": 50
                  },
                  {
                      "type": "TEXT_DETECTION",
                      "maxResults": 50
                  },
                  {
                      "type": "SAFE_SEARCH_DETECTION",
                      "maxResults": 50
                  },
                  {
                      "type": "IMAGE_PROPERTIES",
                      "maxResults": 50
                  }
               ]
           }
        ]
    };

这是我的帖子:

$.ajax({
        url: "https://vision.googleapis.com/v1/images:annotate?fields=responses&key={MY CREATED KEY}",
        type: "POST",
        data: dataToSend,
        success: function (reponse) {
            console.log(reponse);
        },
    });

这是来自控制台的数据(示例内容为空白(不发布 wole base64)):

下面是回复:

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"requests[0][features][0][type]\": Cannot bind query parameter. Field 'requests[0][features][0][type]' could not be found in request message.\nInvalid JSON payload received. Unknown name \"requests[0][features][0][maxResults]\": Cannot bind query parameter. Field 'requests[0][features][0][maxResults]' could not be found in request message.\nInvalid JSON payload received. Unknown name \"requests[0][image][content]\": Cannot bind query parameter. Field 'requests[0][image][content]' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"requests[0][features][0][type]\": Cannot bind query parameter. Field 'requests[0][features][0][type]' could not be found in request message."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"requests[0][features][0][maxResults]\": Cannot bind query parameter. Field 'requests[0][features][0][maxResults]' could not be found in request message."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"requests[0][image][content]\": Cannot bind query parameter. Field 'requests[0][image][content]' could not be found in request message."
          }
        ]
      }
    ]
  }
}

我的错误在哪里?

【问题讨论】:

  • 你把图片转成base 64格式了吗

标签: javascript json google-api google-cloud-platform google-cloud-vision


【解决方案1】:

所以我发现了问题所在。我的照片超过了大约 4MB 的数据大小限制

【讨论】:

    【解决方案2】:

    是的,您还可以缩小现有照片的大小。 为此,您可以使用一些可用的工具。 它们提供缩小的照片尺寸,以便您的视觉 api 可以提供准确的结果。 我使用了提供尺寸减小的 imagix,您也可以提供像 500*500 这样的像素尺寸。

    【讨论】:

      【解决方案3】:

      可能需要以下处理。

      var dataToSend = JSON.stringify({ 你的 json });

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-31
        相关资源
        最近更新 更多