Following the Google doc example I have this code:
def get_similar_products_uri(
project_id, location, product_set_id, product_category, image_uri, filter
):
image_annotator_client = vision.ImageAnnotatorClient()
image_source = vision.types.ImageSource(image_uri=image_uri)
image = vision.types.Image(source=image_source)
product_set_path = product_search_client.product_set_path(
project=project_id, location=location, product_set=product_set_id
)
product_search_params = vision.types.ProductSearchParams(
product_set=product_set_path,
product_categories=[product_category],
filter=filter,
)
image_context = vision.types.ImageContext(
product_search_params=product_search_params
)
response = image_annotator_client.product_search(image, image_context=image_context)
results = response.product_search_results.results
return results
I have been trying to get 25 results instead of 10 but could not find a solution using the python client
I think I need to use a Feature
#features = [{"type": vision.enums.Feature.Type.PRODUCT_SEARCH, "max_results": 25}]
but then I did not know how to use it.
It seems that this would work for annotate_image
but it is not obvious to me how it works with product_search
.
EDIT: link to the documentation I followed: https://cloud.google.com/vision/product-search/docs/searching?hl=cs
Thanks
The answer is using max_results
directly while calling product_search
response = image_annotator_client.product_search(
image, image_context=image_context, max_results=25
)
I could not find the documentation for this method I just guessed it by looking at the documentation of other methods such as: https://googleapis.dev/ruby/google-cloud-vision/latest/Google/Cloud/Vision/V1p3beta1/ImageAnnotatorClient.html#document_text_detection