I am reading documentation on vision API request schema. In image source, I only see option of using url of GCS image paths. Is it possible to use external image url like http://example.com/images/image01.jpg ?
I am reading documentation on vision API request schema. In image source, I only see option of using url of GCS image paths. Is it possible to use external image url like http://example.com/images/image01.jpg ?
Yes, you can do this with any image as long as it is smaller than 4Mb. It does not have to be on Google Cloud Storage.
Here is an example using the Golang client library:
// 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)
}
}
Here is the function on the Godoc:https://godoc.org/cloud.google.com/go/vision/apiv1#NewImageFromURI
The docs state:
NewImageFromURI returns an image that refers to an object in Google Cloud Storage (when the uri is of the form "gs://BUCKET/OBJECT") or at a public URL.
Answer for python users.
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]