为什么Google Cloud Vision API的Node Client没有考虑纵横比



我正在尝试使用Google Cloud Vision API的节点客户端。我设法使用在远程图像上获得裁剪提示

const [result] = await clientVision.cropHints(`gs://mybucket/${image.name}`,  
{imageContext : {cropHintsParams : {aspectRatios : [1]}}});

但是长宽比没有被考虑在内。我可以将aspectRatios的值更改为1或4或浮点1.33333,我得到的顶点坐标相同。默认的纵横比似乎是1.77。

知道为什么吗?

我最终使用了rest api:

function getHints(aspect, path) {
return new Promise((resolve, reject) => {
axios.post('https://vision.googleapis.com/v1/images:annotate?key=xxxxxxxxxxxxxxxxxx', {
"requests": [
{
"image": {
"source": {
"gcsImageUri": `gs://myproject/${path}`
}
},
"features": [
{
"type": "CROP_HINTS"
}
],
"imageContext": {
"cropHintsParams": {
"aspectRatios": [
aspect
]
}
}
}
]
}).then((response) => {
console.info(response.data['responses'])
var vertices = response.data['responses'][0].cropHintsAnnotation.cropHints[0].boundingPoly.vertices;

if (vertices[0].x == undefined) {
vertices[0].x = 0
}
if (vertices[0].y == undefined) {
vertices[0].y = 0
}
if (vertices[1].x == undefined) {
vertices[1].x = 0
}
if (vertices[1].y == undefined) {
vertices[1].y = 0
}
if (vertices[2].x == undefined) {
vertices[2].x = 0
}
if (vertices[2].y == undefined) {
vertices[2].y = 0
}
if (vertices[3].x == undefined) {
vertices[3].x = 0
}
if (vertices[3].y == undefined) {
vertices[3].y = 0
}
resolve(vertices)
}).catch(error => {
console.log(error.response)
});

})

我用它是这样的:

var hints = await getHints(1.777777778, path)

最新更新