class SignatureMongo(SignatureDatabaseBase):
"""MongoDB driver for image-match
"""
def __init__(self, collection, *args, **kwargs):
"""Additional MongoDB setup
Args:
collection (collection): a MongoDB collection instance
args (Optional): Variable length argument list to pass to base constructor
kwargs (Optional): Arbitrary keyword arguments to pass to base constructor
Examples:
>>> from image_match.mongodb_driver import SignatureMongo
>>> from pymongo import MongoClient
>>> client = MongoClient(connect=False)
>>> c = client.images.images
>>> ses = SignatureMongo(c)
>>> ses.add_image('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')
>>> ses.search_image('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')
[
{'dist': 0.0,
'id': u'AVM37nMg0osmmAxpPvx6',
'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',
'score': 0.28797293}
]
"""
self.collection = collection
# Extract index fields, if any exist yet
if self.collection.count() > 0:
self.index_names = [field for field in self.collection.find_one({}).keys()
if field.find('simple') > -1]
super(SignatureMongo, self).__init__(*args, **kwargs)