Google镜头APIs/SDK

Google Lens APIs/SDK

我正在浏览 Google Cloud Vision API 以搜索图像中的相关产品。但是,我发现我需要先创建一个产品集(并上传图片),然后在我创建的集上进行搜索。

有没有 API 我可以通过它提供图像(无需创建任何产品集)并搜索 google(或任何特定网站,如亚马逊)以查找相关产品(及其电子商务)图片中的链接)?基本上复制了 google 镜头为其应用程序所做的事情。如果没有,是否有针对相同用例的任何 google 镜头移动 SDK,即找到提供图像的相关产品(及其电子商务 URI)?

更新 1

我对此进行了更多研究,发现 Web Detection API。这确实在一定程度上达到了目的。但是,我无法过滤来自特定网站的结果(例如:- 亚马逊)。有没有办法过滤来自特定域的结果?

使用 Vision API,您可以从图像中的 Web 属性、面部和文本进行检测。

一个选项是在列出资源、评估或操作时使用过滤以 return 更具体的结果。使用 ?filter="[filter_name=]filter-value return 匹配 filter-value 的所有 JSON 个对象。您可以在此 link.

中查看更多信息

另一种选择是在显示结果之前进行过滤。您可以查看此示例,其中 returns links from the Web 和包含图像中某些颜色的云存储。

你可以看到这个例子:

def detect_properties_uri(uri):
    """Detects image properties in the file located in Google Cloud Storage or
    on the Web."""
    from google.cloud import vision
    client = vision.ImageAnnotatorClient()
    image = vision.Image()
    image.source.image_uri = uri
 
    response = client.image_properties(image=image)
    props = response.image_properties_annotation
    print('Properties:')
 
    for color in props.dominant_colors.colors:
        print('frac: {}'.format(color.pixel_fraction))
        print('\tr: {}'.format(color.color.red))
        print('\tg: {}'.format(color.color.green))
        print('\tb: {}'.format(color.color.blue))
        print('\ta: {}'.format(color.color.alpha))
 
    if response.error.message:
        raise Exception(
            '{}\nFor more info on error messages, check: '
            'https://cloud.google.com/apis/design/errors'.format(
                response.error.message))
# [END vision_image_property_detection_gcs]

下一步是像这样遍历结果 example 并过滤包含域的链接。查看网络链接中的域。

for entity in web_detection.web_entities:
if (str(entity.description).find(domain) >-1)
  print(entity.description)

在这种情况下,您将迭代每个结果,filter 尝试在描述中找到域并将其显示在屏幕上。

另一种选择是以 JSON 格式处理结果。在那次追逐中,你需要:

  • 解析JSON
  • 过滤 JSON

你可以看到这个例子:

import json
 
input_json = """
[
    {
        "type": "1",
        "name": "name 1"
    },
    {
        "type": "2",
        "name": "name 2"
    },
    {
        "type": "1",
        "name": "name 3"
    }
]"""
 
# Transform json input to python objects
input_dict = json.loads(input_json)
 
# Filter python objects with list comprehensions
output_dict = [x for x in input_dict if x['type'] == '1']
 
# Transform python object back into json
output_json = json.dumps(output_dict)
 
# Show json
print output_json