Can google vision API accept external image url?

I am reading documentation on a vision API request schema. In the image source, I see only the option of using the url of GCS image paths. Is it possible to use an external image URL, for example http://example.com/images/image01.jpg ?

+11
google-cloud-vision
source share
5 answers

Yes, this works fine:

{ "requests": [ { "features": [ { "type": "WEB_DETECTION" } ], "image": { "source": { "imageUri": "http://i3.kym-cdn.com/photos/images/facebook/000/242/592/1c8.jpg" } } } ] } 
+9
source share

Yes, it’s possible, but ONLY using Google Cloud Storage URLs. Try the following:

 { "requests": [ { "image": { "source": { gcsImageUri: 'gs://something.com/image', }, }, "features": ... "imageContext": ... }, ] } 
+4
source share

Yes, you can do this with any image if it is less than 4 MB. It should not be in Google Cloud Storage.

Here is an example of 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 Godoc: https://godoc.org/cloud.google.com/go/vision/apiv1#NewImageFromURI

Status of documents:

NewImageFromURI returns an image that refers to an object in Google Cloud Storage (when the uri has the form "gs: // BUCKET / OBJECT") or to a public URL.

+1
source share

The answer is 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] 
0
source share

Yes, Google Cloud Vision API Accepts external URL images. I just used this image to get the labels:

 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!!!!!!!!!!! 

You must specify it in the correct format using the urllib library and comment on the image opening part as follows:

 url = url_file opener = urllib.urlopen(url) # with open(photo_file, 'rb') as image: image_content = base64.b64encode(opener.read()) 
-4
source share

All Articles