@@ -44,22 +44,26 @@ The result is a list of hits:
44
44
[
45
45
{' dist' : 0.0 ,
46
46
' id' : u ' AVM37oZq0osmmAxpPvx7' ,
47
+ ' metadata' : None ,
47
48
' path' : u ' https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg' ,
48
49
' score' : 7.937254 },
49
50
{' dist' : 0.22095170140933634 ,
50
51
' id' : u ' AVM37nMg0osmmAxpPvx6' ,
52
+ ' metadata' : None ,
51
53
' path' : u ' https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg' ,
52
54
' score' : 0.28797293 },
53
55
{' dist' : 0.42557196987336648 ,
54
56
' id' : u ' AVM37p530osmmAxpPvx9' ,
57
+ ' metadata' : None ,
55
58
' path' : u ' https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg' ,
56
59
' score' : 0.0499953 }
57
60
]
58
61
59
62
``dist `` is the normalized distance, like we computed above. Hence, lower numbers
60
63
are better with ``0.0 `` being a perfect match. ``id `` is an identifier assigned by
61
64
the database. ``score `` is computed by Elasticsearch, and higher numbers are
62
- better here. ``path `` is the original path (url or file path).
65
+ better here. ``path `` is the original path (url or file path). ``metadata `` is
66
+ an optional field used for storing extra information about the image (see below).
63
67
64
68
Notice all three Mona Lisa images appear in the results, with the identical
65
69
image being a perfect (``'dist': 0.0 ``) match. If we search instead for the
@@ -76,6 +80,7 @@ You get:
76
80
[
77
81
{' dist' : 0.0 ,
78
82
' id' : u ' AVMyXQFw0osmmAxpPvxz' ,
83
+ ' metadata' : None ,
79
84
' path' : u ' https://upload.wikimedia.org/wikipedia/commons/e/e0/Caravaggio_-_Cena_in_Emmaus.jpg' ,
80
85
' score' : 7.937254 }
81
86
]
@@ -97,10 +102,12 @@ Which now returns only the unmodified, catless Mona Lisas:
97
102
[
98
103
{' dist' : 0.0 ,
99
104
' id' : u ' AVMyXOz30osmmAxpPvxy' ,
105
+ ' metadata' : None ,
100
106
' path' : u ' https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg' ,
101
107
' score' : 7.937254 },
102
108
{' dist' : 0.23889600350807427 ,
103
109
' id' : u ' AVMyXMpV0osmmAxpPvxx' ,
110
+ ' metadata' : None ,
104
111
' path' : u ' https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg' ,
105
112
' score' : 0.28797293 }
106
113
]
@@ -125,14 +132,17 @@ returns
125
132
[
126
133
{' dist' : 0.15454905655638429 ,
127
134
' id' : u ' AVM37oZq0osmmAxpPvx7' ,
135
+ ' metadata' : None ,
128
136
' path' : u ' https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg' ,
129
137
' score' : 1.6818419 },
130
138
{' dist' : 0.24980626832071956 ,
131
139
' id' : u ' AVM37nMg0osmmAxpPvx6' ,
140
+ ' metadata' : None ,
132
141
' path' : u ' https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg' ,
133
142
' score' : 0.16198477 },
134
143
{' dist' : 0.43387141782958921 ,
135
144
' id' : u ' AVM37p530osmmAxpPvx9' ,
145
+ ' metadata' : None ,
136
146
' path' : u ' https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg' ,
137
147
' score' : 0.031996995 }
138
148
]
@@ -150,3 +160,47 @@ Searching for this image will return no results, unless you search with
150
160
ses.search_image(' http://i.imgur.com/T5AusYd.jpg' , all_orientations = True )
151
161
152
162
Then you get the expected matches.
163
+
164
+ Adding metadata
165
+ ^^^^^^^^^^^^^^^
166
+ Sometimes you want to store information with your images independent of the
167
+ reverse image search functionality. You can do that with the ``metadata= ``
168
+ field in the ``add_image `` function.
169
+
170
+ Let's add one of the images again, with some extra data:
171
+
172
+ .. code-block :: python
173
+
174
+ ses.add_image(' https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg' , metadata = {' things' : ' stuff!' })
175
+
176
+ In general, any JSON-like data should work with ``metadata= ``. Now we can search for the image:
177
+
178
+ .. code-block :: python
179
+
180
+ ses.search_image(' https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg' )
181
+
182
+ Returns our previous results along with a new one:
183
+
184
+ .. code-block :: python
185
+
186
+ [
187
+ {' dist' : 0.0 ,
188
+ ' id' : u ' AVYhQYhEDpLcdyATKuy-' ,
189
+ ' metadata' : None ,
190
+ ' path' : u ' https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg' ,
191
+ ' score' : 7.64685 },
192
+ {' dist' : 0.0 ,
193
+ ' id' : u ' AVYhRvoWDpLcdyATKuzE' ,
194
+ ' metadata' : {u ' things' : u ' stuff!' },
195
+ ' path' : u ' https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg' ,
196
+ ' score' : 2.435569 },
197
+ ...
198
+ ]
199
+
200
+ Where we can see a little extra info. ``image-match `` doesn't provide anyway to query
201
+ the metadata directly, but the user can use Elasticsearch's QL, for example with:
202
+
203
+ .. code-block :: python
204
+
205
+ ses.es.search(' images' , body = {' query' : {' match' : {' metadata.things' : ' stuff!' }}})
206
+
0 commit comments