Vue.js / Django REST应用中的Google Vision

问题描述

我想在我的Vue.js / Django REST应用程序中实现google Vision API。我已经浏览了官方文档,但是我仍然不知道该怎么做。 看来该API仅在服务器端可用(C#,Go,Java,Node ...),但我想在Vue.js中使用客户端。

似乎我们也可以通过以下端点访问API:https://vision.googleapis.com/v1/images:annotate?key=YOUR_GOOGLE_PROJECT_API_KEY, 是否可以使用axios将我的图片发送到该端点并返回结果?我应该如何格式化我的请求?

解决方法

如果有人希望在Vue.js / Django应用中实现Google Vision Api,这就是我的解决方法:

checkImageLabels: function() {
      this.picToCheck = this.image.dataUrl.replace(/^data:image\/[a-z]+;base64,/,"");
      const data = {
        "requests" : [{
          "features": [{
            "type": "LABEL_DETECTION"
          }],"image": {
            "content": this.picToCheck
          }
        }]
      }
      axios.post(`https://vision.googleapis.com/v1/images:annotate?key=${this.apiKey}`,data)  
    }

您必须将“ axios”导入到您的项目中并使用有效的Google Cloud APIKey。至于输入格式,我使用base64图片,并使用正则表达式清除标题。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...