Justin C.
Justin C.

Reputation: 382

How to display the Clarifai API Search Python Image Object

I am following the API tutorial on the Clarifai site specifically working with the search tutorial(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)

When I look at what the API returns it is a list that contains an image object as follows:

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

How can I display this Image object to look at what it contains and save it to a file such as .png?

Upvotes: 1

Views: 647

Answers (1)

Robert Wen
Robert Wen

Reputation: 56

First off, you probably want to revoke your keys as they are compromised here.

Secondly to your question, when you get the result, you get a list of Image() objects.

For example,

imgs = app.inputs.search(bla)

If you run vars(imgs[0]) you will see

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] is an object. You can basically get the attributes by imgs[0].url, imgs[0].input_id or something like that.

Hopefully this addresses your question.

Upvotes: 2

Related Questions