Google Cloud Vision Search Product Python 客户端 - 如何return 超过 10 个结果?

Google Cloud Vision Search Product Python Client - How to return more than 10 results?

根据 Google 文档示例,我有以下代码:

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

我一直试图获得 25 个结果而不是 10 个,但无法使用 python 客户端

找到解决方案

我想我需要使用一个功能

    #features = [{"type": vision.enums.Feature.Type.PRODUCT_SEARCH, "max_results": 25}]

但是后来不知道怎么用。 这似乎适用于 annotate_image 但我不清楚它如何与 product_search.

一起使用

编辑: link 我遵循的文档: https://cloud.google.com/vision/product-search/docs/searching?hl=cs

谢谢

答案是在调用product_search

时直接使用max_results
    response = image_annotator_client.product_search(
        image, image_context=image_context, max_results=25
    )

我找不到这个方法的文档我只是通过查看其他方法的文档猜到了它,例如:https://googleapis.dev/ruby/google-cloud-vision/latest/Google/Cloud/Vision/V1p3beta1/ImageAnnotatorClient.html#document_text_detection