[英]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.