繁体   English   中英

Google Vision API

[英]Google Vision API

我正在尝试将数据发布到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);
        },
    });

这是来自控制台的数据( 示例中的内容为空白 (不发布错误的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."
          }
        ]
      }
    ]
  }
}

我的错在哪里?

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

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

可能需要进行以下处理。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM