python - 如何显示 Clarifai API 搜索 Python 图像对象

标签 python image api clarifai

我正在关注 Clarifai 网站上的 API 教程,专门使用搜索教程 ( https://developer-preview.clarifai.com/quick-start/ )

from clarifai.rest import ClarifaiApp

app = ClarifaiApp("{clientId}", "{clientSecret}")

# before search, first need to upload a few images
app.inputs.create_image_from_url("https://samples.clarifai.com/puppy.jpeg")

# search by predicted concept
result = app.inputs.search_by_predicted_concepts(concept='dog')
print(result)

当我查看 API 返回的内容时,它是一个包含图像对象的列表,如下所示:

[<clarifai.rest.client.Image object at 0x103215f50>]

如何显示此 Image 对象以查看其包含的内容并将其保存到 .png 等文件中?

最佳答案

首先,您可能想要撤销您的 key ,因为它们在这里已被泄露。

其次是你的问题,当你得到结果时,你会得到一个 Image() 对象的列表。

例如,

imgs = app.inputs.search(bla)

如果你运行vars(imgs[0])你会看到

In [14]: vars(imgs[0])
Out[14]:
{'allow_dup_url': False,
 'base64': None,
 'concepts': None,
 'crop': [0.1, 0.3, 0.5, 0.7],
 'file_obj': None,
 'filename': None,
 'input_id': u'sdfsdsdfds1a837e19a10f9',
 'metadata': None,
 'not_concepts': None,
 'url': u'https://s3.amazonaws.com/clarifai-api/img/prod/bla.jpeg'}

imgs[0] 是一个对象。您基本上可以通过以下方式获取属性 imgs[0].urlimgs[0].input_id 或类似的内容。

希望这能解决您的问题。

关于python - 如何显示 Clarifai API 搜索 Python 图像对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40380882/

相关文章:

api - 我的 URI 应该如何构建才能被视为 RESTful?

python - 时间序列的简单 tsplot

python - 自动 __repr__ 方法

jquery - 如何检查是否支持naturalWidth?

javascript - 使用 Vimeo API 3 限制返回的数据

django - data._mutable= True 在 Django 休息框架

python - Pycryptodome 无法解密数据

python - 在 Keras 中将模型合并为一个

php从数据库加载图像(pdf)

c# - 查找图像内容并在其周围绘制矩形