Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Missing Image URLs in Cloud Vision API Web Detection

I'm using the Google Cloud Vision API's Web Detection feature, but I'm encountering an issue where the image URLs ("fullMatchingImages", "partialMatchingImages", "visuallySimilarImages") are not being returned in the response. I'm only getting the label-related fields ("webEntities", "bestGuessLabels").

I've tried the following:

  • Calling the API from my own Python implementation.

  • Using the "Try it out" feature in the API documentation.

In both cases, the image URLs are missing. The labels are being returned correctly, so I believe the API call itself is fine.

Has anyone else encountered this issue? Any suggestions on how to resolve it?

Even with "Try it out", I'm getting the following response (image URLs are missing):

{
  "responses": [
    {
      "webDetection": {
        "webEntities": [
          {
            "entityId": "/m/09l9f",
            "score": 0.6879023,
            "description": "Carnival"
          },
          // ... other web entities
        ],
        "bestGuessLabels": [
          {
            "label": "carnival"
          }
        ]
      }
    }
  ]
}

Code Snippet (Python):

import os

from dotenv import load_dotenv
from google.cloud import vision
from google.oauth2 import service_account

load_dotenv()

credentials_dict = {
    "type": os.getenv("GCP_TYPE"),
    "project_id": os.getenv("GCP_PROJECT_ID"),
    "private_key_id": os.getenv("GCP_PRIVATE_KEY_ID"),
    "private_key": os.getenv("GCP_PRIVATE_KEY").replace("\\n", "\n"),
    "client_email": os.getenv("GCP_CLIENT_EMAIL"),
    "client_id": os.getenv("GCP_CLIENT_ID"),
    "auth_uri": os.getenv("GCP_AUTH_URI"),
    "token_uri": os.getenv("GCP_TOKEN_URI"),
    "auth_provider_x509_cert_url": os.getenv("GCP_AUTH_PROVIDER_X509_CERT_URL"),
    "client_x509_cert_url": os.getenv("GCP_CLIENT_X509_CERT_URL"),
    "universe_domain": os.getenv("GCP_UNIVERSE_DOMAIN"),
}
credentials = service_account.Credentials.from_service_account_info(credentials_dict)
client = vision.ImageAnnotatorClient(credentials=credentials)

image = vision.Image()
image.source.image_uri = "gs://cloud-samples-data/vision/web/carnaval.jpeg"

features = [vision.Feature(type_=vision.Feature.Type.WEB_DETECTION)]

response = client.annotate_image({"image": image, "features": features})

web_detection = response.web_detection

# Image URLs are missing
print(web_detection.full_matching_images)  # Output: []
print(web_detection.partial_matching_images)  # Output: []
print(web_detection.visually_similar_images)  # Output: []

# Labels are present
print(web_detection.web_entities)  # Output: [<Entity...>, ...]
print(web_detection.best_guess_labels)  # Output: [<Entity...>, ...]

Any help would be greatly appreciated!

 
0 1 597
1 REPLY 1

Hi @haruka,

Welcome to Google Cloud Community!

It seems you've already put in considerable effort into troubleshooting the issue. Here are several suggestions that you might find helpful in resolving the issue:

  • Check Image Source: Ensure that the images you are using are accessible and properly formatted. The Vision API supports images from web URIs, Google Cloud Storage, or local files. If the images are hosted online, verify that the URLs are correct and publicly accessible.
  • API Quota and Limits: Sometimes, exceeding API quotas or limits can cause incomplete responses. Check your Google Cloud Console to ensure you’re within your usage limits.
  • Request Parameters: Double check the parameters in your API request. Ensure that you’re including all necessary fields for retrieving image URLs and that the request is correctly formatted. The request should specify the web detection feature.
  • API Version: Make sure you’re using the latest version of the Google Cloud Vision API. Sometimes, updates or changes in the API can affect the response format.
  • Documentation and Tutorials: You can refer to the Web Detection tutorial, which could be useful for comparing your results. Additionally, you might want to try your inputs on the Vision API web page. Moreover, you can visit this documentation guide for more information. These resources provide detailed examples and may help you spot any discrepancies in your implementation.

I hope the above information is helpful.