首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Lens API/SDK

Google Lens API/SDK
EN

Stack Overflow用户
提问于 2022-03-23 15:59:01
回答 1查看 6.9K关注 0票数 4

我正在通过谷歌云视觉API搜索图像中的相关产品。但是,我发现我需要首先创建一个产品集(并上传图像),然后在我创建的集合上搜索。

有什么API,我可以通过它提供图像(不需要创建任何产品集)和搜索谷歌(或任何特定的网站,如亚马逊)的相关产品(和他们的eCommerce链接)?基本上是模仿谷歌镜头为其应用程序所做的。如果没有,是否有谷歌镜头移动SDK为同一用例,即找到相关的产品(及其eCommerce URI)提供的图像??

更新1

我对此做了更多的研究,并发现了Web检测API。这确实在某种程度上达到了目的。但是,我不能过滤来自特定网站的结果(例如:- Amazon)。是否有一种方法来过滤来自特定域的结果?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-24 16:46:32

使用Vision,您可以从图像中的web属性、人脸和文本中检测。

一个选项是在列出资源、评估或操作时使用筛选返回更具体的结果。使用?filter="[filter_name=]filter-value返回与筛选值匹配的所有JSON对象。您可以在这个链接中看到更多信息。

另一个选项是在显示结果之前进行筛选。您可以看到这个示例,其中的从Web返回链接和云存储包含图像中的特定颜色。

您可以看到这个例子:

代码语言:javascript
复制
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]

下一步是迭代类似于此示例的结果,并过滤包含域的链接。查看域名内的网页链接。

代码语言:javascript
复制
for entity in web_detection.web_entities:
if (str(entity.description).find(domain) >-1)
  print(entity.description)

在本例中,您将迭代每个结果和过滤器,试图在描述中找到域并在屏幕上显示它。

另一个选项是以JSON格式操作结果。在这场追逐中,你需要:

  • 解析JSON
  • 过滤JSON

您可以看到这个例子:

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71590340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档