@@ -178,17 +178,24 @@ def __init__(self, k=16, N=63, n_grid=9,
178
178
179
179
self .gis = ImageSignature (n = n_grid , crop_percentiles = crop_percentile , * signature_args , ** signature_kwargs )
180
180
181
- def add_image (self , path , img = None ):
181
+ def add_image (self , path , img = None , bytestream = False ):
182
182
"""Add a single image to the database
183
183
184
184
Args:
185
185
path (string): path or identifier for image. If img=None, then path is assumed to be
186
186
a URL or filesystem path
187
- img (Optional[string]): raw image data. In this case, path will still be stored, but
188
- a signature will be generated from data in img (default None)
187
+ img (Optional[string]): usually raw image data. In this case, path will still be stored, but
188
+ a signature will be generated from data in img. If bytestream is False, but img is
189
+ not None, then img is assumed to be the URL or filesystem path. Thus, you can store
190
+ image records with a different 'path' than the actual image location (default None)
191
+ bytestream (Optional[boolean]): will the image be passed as raw bytes?
192
+ That is, is the 'path_or_image' argument an in-memory image? If img is None but, this
193
+ argument will be ignored. If img is not None, and bytestream is False, then the behavior
194
+ is as described in the explanation for the img argument
195
+ (default False)
189
196
190
197
"""
191
- rec = make_record (path , self .gis , self .k , self .N , img = img )
198
+ rec = make_record (path , self .gis , self .k , self .N , img = img , bytestream = bytestream )
192
199
self .insert_single_record (rec )
193
200
194
201
def search_image (self , path , all_orientations = False , bytestream = False ):
@@ -266,7 +273,7 @@ def search_image(self, path, all_orientations=False, bytestream=False):
266
273
return r
267
274
268
275
269
- def make_record (path , gis , k , N , img = None ):
276
+ def make_record (path , gis , k , N , img = None , bytestream = False ):
270
277
"""Makes a record suitable for database insertion.
271
278
272
279
Note:
@@ -281,8 +288,15 @@ def make_record(path, gis, k, N, img=None):
281
288
signature
282
289
k (int): width of words for encoding
283
290
N (int): number of words for encoding
284
- img (Optional[string]): raw image data. In this case, path will still be stored, but
285
- a signature will be generated from data in img (default None)
291
+ img (Optional[string]): usually raw image data. In this case, path will still be stored, but
292
+ a signature will be generated from data in img. If bytestream is False, but img is
293
+ not None, then img is assumed to be the URL or filesystem path. Thus, you can store
294
+ image records with a different 'path' than the actual image location (default None)
295
+ bytestream (Optional[boolean]): will the image be passed as raw bytes?
296
+ That is, is the 'path_or_image' argument an in-memory image? If img is None but, this
297
+ argument will be ignored. If img is not None, and bytestream is False, then the behavior
298
+ is as described in the explanation for the img argument
299
+ (default False)
286
300
287
301
Returns:
288
302
An image record.
@@ -314,7 +328,7 @@ def make_record(path, gis, k, N, img=None):
314
328
record = dict ()
315
329
record ['path' ] = path
316
330
if img is not None :
317
- signature = gis .generate_signature (img , bytestream = True )
331
+ signature = gis .generate_signature (img , bytestream = bytestream )
318
332
else :
319
333
signature = gis .generate_signature (path )
320
334
0 commit comments