14

我正在阅读有关视觉 API 请求模式的文档。在图像源中,我只看到使用 GCS 图像路径的 url 的选项。是否可以使用像http://example.com/images/image01.jpg这样的外部图片网址?

4

5 回答 5

13

是的,这工作得很好:

{
  "requests": [
    {
      "features": [
        {
          "type": "WEB_DETECTION"
        }
      ],
      "image": {
        "source": {
          "imageUri": "http://i3.kym-cdn.com/photos/images/facebook/000/242/592/1c8.jpg"
        }
      }
    }
  ]
}
于 2017-04-19T09:18:40.503 回答
4

是的,它可以,但只能使用谷歌云存储 URL。尝试这个:

{
  "requests": [
    {
      "image": {
        "source": {
          gcsImageUri: 'gs://something.com/image',
        },
      },
      "features": ...
      "imageContext": ...
    },
  ]
}
于 2016-03-10T00:45:24.900 回答
2

是的,只要图像小于 4Mb,您就可以对任何图像执行此操作。它不必位于 Google Cloud Storage 上。

这是使用 Golang 客户端库的示例:

// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

// [START vision_quickstart]
// Sample vision-quickstart uses the Google Cloud Vision API to label an image.
package main

import (
    "fmt"
    "log"

    // Imports the Google Cloud Vision API client package.
    vision "cloud.google.com/go/vision/apiv1"
    "golang.org/x/net/context"
)

func main() {
    ctx := context.Background()

    // Creates a client.
    client, err := vision.NewImageAnnotatorClient(ctx)
    if err != nil {
        log.Fatalf("Failed to create client: %v", err)
    }

    image := vision.NewImageFromURI("https://www.denaligrizzlybear.com/assets/images/scenic-denali.jpg")

    labels, err := client.DetectLabels(ctx, image, nil, 10)
    if err != nil {
        log.Fatalf("Failed to detect labels: %v", err)
    }

    fmt.Println("Labels:")
    for _, label := range labels {
        fmt.Println(label.Description)
    }
}

这是 Godoc 上的功能:https ://godoc.org/cloud.google.com/go/vision/apiv1#NewImageFromURI

文档状态:

NewImageFromURI 返回一个图像,该图像引用 Google Cloud Storage 中的对象(当 uri 的格式为“gs://BUCKET/OBJECT”时)或公共 URL。

于 2017-10-25T17:36:54.193 回答
2

回答python用户。

def detect_labels_uri(uri):
    """Detects labels in the file located in Google Cloud Storage or on the
    Web."""
    from google.cloud import vision
    client = vision.ImageAnnotatorClient()
    image = vision.types.Image()
    image.source.image_uri = uri

    response = client.label_detection(image=image)
    labels = response.label_annotations
    print('Labels:')

    for label in labels:
        print(label.description)
# [END vision_label_detection_gcs]
于 2019-06-23T10:06:19.790 回答
-4

是的,Google Cloud Vision API接受外部 URL 图片。我只是用这张图片来获取标签:

python label_sample.py -u "https://upload.wikimedia.org/wikipedia/commons/e/e6/Bleeding_finger.jpg"

Found label: red with 96.47 percent probability!!!!!!!!!!!
Found label: color with 95.46 percent probability!!!!!!!!!!!
Found label: pink with 92.15 percent probability!!!!!!!!!!!
Found label: finger with 91.06 percent probability!!!!!!!!!!!
Found label: hand with 90.45 percent probability!!!!!!!!!!!
Found label: nail with 73.23 percent probability!!!!!!!!!!!
Found label: lip with 73.09 percent probability!!!!!!!!!!!
Found label: jewellery with 68.84 percent probability!!!!!!!!!!!
Found label: produce with 68.39 percent probability!!!!!!!!!!!
Found label: macro photography with 67.86 percent probability!!!!!!!!!!!

您必须使用 urllib 库以正确的格式为其提供 url 并注释打开图像的部分,如下所示:

url = url_file
opener = urllib.urlopen(url)

#    with open(photo_file, 'rb') as image:
image_content = base64.b64encode(opener.read())
于 2016-09-03T08:29:53.250 回答