微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决为什么 Google Cloud Vision API 的 Node Client 不考虑纵横比

我正在尝试将 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。

知道为什么吗?

解决方法

我最终使用了其余的 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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。