Ejemplo n.º 1
0
def create_and_save(name, images, file_path):
    index = imsearch.init(name)
    index.cleanIndex()
    index.addImageBatch(images)
    index.createIndex()
    index.saveIndex(file_path)
    index.cleanIndex()
Ejemplo n.º 2
0
    def test_init(self, mock_index, config_init_mock):
        instance = mock_index()
        instance.name = 'test'

        index = imsearch.init('test', MONGO_URI='mongodb://localhost:27017/')
        self.assertEqual(index, instance)
        self.assertEqual(index.name, 'test')
        config_init_mock.assert_called_with(
            {'MONGO_URI': 'mongodb://localhost:27017/'})
Ejemplo n.º 3
0
def create_index_with_config(name):
    '''
    parameters:
        name: name of the index (unique identifier name)
        MONGO_URI
        REDIS_URI
        DETECTOR_MODE:  select 'local' or 'remote'. 
                        local: detector backend should be running on the same machine
                        remote: Process should not start detector backend
        pass any configuration you want to expose as environment variable. 
    '''
    index = imsearch.init(name=name,
                          MONGO_URI='mongodb://*****:*****@123.456.78.111:6379/0',
                          DETECTOR_MODE='local')
Ejemplo n.º 4
0
def create_index(name, images):
    # Initialize the index
    index = imsearch.init(name)

    # Clear the index and data if any exists
    index.cleanIndex()

    # Add single image to index (image path locally stored)
    index.addImage(images[0])

    # Add image using URL with same interface
    index.addImage(
        "https://www.wallpaperup.com/uploads/wallpapers/2014/04/14/332423/d5c09641cb3af3a18087937d55125ae3-700.jpg")

    # Add images in batch (List of image paths locally stored)
    index.addImageBatch(images[1:])

    # Build the index
    index.createIndex()

    return index
Ejemplo n.º 5
0
import cv2
import glob
import os, sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import imsearch

all_images = glob.glob(
    os.path.join(os.path.dirname(__file__), '..', 'images/*.jpg'))

index = imsearch.init('test')
# index.cleanIndex()
# index.addImageBatch(all_images[0:25])
# index.addImage(all_images[25])
index.createIndex()

similar = index.knnQuery(all_images[25], policy='object')
qImage = imsearch.utils.load_image(all_images[25])

# similar = index.knnQuery('https://www.wallpaperup.com/uploads/wallpapers/2014/04/14/332423/d5c09641cb3af3a18087937d55125ae3-700.jpg', policy='object')
# qImage = imsearch.utils.load_image('https://www.wallpaperup.com/uploads/wallpapers/2014/04/14/332423/d5c09641cb3af3a18087937d55125ae3-700.jpg')

cv2.imshow('qImage', qImage)
for _i, _s in similar:
    rImage = cv2.imread(_i['image'])
    print([x['name'] for x in _i['primary']])
    print(_s)
    cv2.imshow('rImage', rImage)
    cv2.waitKey(0)
Ejemplo n.º 6
0
    'BUCKET_NAME': aws_config_file['BUCKET_NAME'],
    'STORAGE_MODE': 's3'
}


def show_results(similar, qImage):
    qImage = imsearch.utils.check_load_image(qImage)
    qImage = cv2.cvtColor(qImage, cv2.COLOR_RGB2BGR)
    cv2.imshow('qImage', qImage)
    for _i, _s in similar:
        rImage = cv2.cvtColor(imsearch.utils.check_load_image(_i['image']),
                              cv2.COLOR_RGB2BGR)
        print([x['name'] for x in _i['primary']])
        print(_s)
        cv2.imshow('rImage', rImage)
        cv2.waitKey(0)


if __name__ == "__main__":
    all_images = glob.glob(
        os.path.join(os.path.dirname(__file__), '..', 'images/*.jpg'))
    index = imsearch.init(name='test', **aws_config)
    index.cleanIndex()
    index.addImageBatch(all_images)
    index.createIndex()

    # query with image URL
    img_url = 'https://www.wallpaperup.com/uploads/wallpapers/2014/04/14/332423/d5c09641cb3af3a18087937d55125ae3-700.jpg'
    similar = index.knnQuery(image_path=img_url, k=10, policy='global')
    show_results(similar, img_url)
Ejemplo n.º 7
0
import cv2
import glob
import os, sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import imsearch

all_images = glob.glob(
    os.path.join(os.path.dirname(__file__), '..', 'images/*.jpg'))

index = imsearch.init(
    'test',
    MONGO_URI='mongodb://*****:*****@216.165.71.213:6379/0')
# index.cleanIndex()
# index.addImageBatch(all_images[0:25])
# index.addImage(all_images[25])
index.createIndex()

# similar = index.knnQuery(all_images[25], policy='object')
# qImage = imsearch.utils.load_image(all_images[25])

similar = index.knnQuery(
    'https://www.wallpaperup.com/uploads/wallpapers/2014/04/14/332423/d5c09641cb3af3a18087937d55125ae3-700.jpg',
    policy='object')
qImage = imsearch.utils.load_image(
    'https://www.wallpaperup.com/uploads/wallpapers/2014/04/14/332423/d5c09641cb3af3a18087937d55125ae3-700.jpg'
)

cv2.imshow('qImage', qImage)