Reputation: 1
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?
{
"responses": [
{
"webDetection": {
"webEntities": [
{
"entityId": "/m/09l9f",
"score": 0.6879023,
"description": "Carnival"
},
// ... other web entities
],
"bestGuessLabels": [
{
"label": "carnival"
}
]
}
}
]
}
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!
Upvotes: 0
Views: 70