【问题标题】:why does Node Client for Google Cloud Vision API does not take aspect ratio into account为什么 Google Cloud Vision API 的节点客户端不考虑纵横比
【发布时间】:2021-04-27 23:52:20
【问题描述】:

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

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

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

知道为什么吗?

【问题讨论】:

    标签: node.js google-vision


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 2021-01-17
      相关资源
      最近更新 更多