Exemplo n.º 1
0
def test_hashing(read_asset, config_injector):
    config_injector({
        'elasticsearch': {
            'host': 'localhost',
            'port': 9200,
            'index': 'szurubooru_test',
        },
    })
    image_hash.purge()
    image_hash.add_image('test', read_asset('jpeg.jpg'))

    paths = image_hash.get_all_paths()
    results_exact = image_hash.search_by_image(read_asset('jpeg.jpg'))
    results_similar = image_hash.search_by_image(
        read_asset('jpeg-similar.jpg'))

    assert len(paths) == 1
    assert len(results_exact) == 1
    assert len(results_similar) == 1
    assert results_exact[0].path == 'test'
    assert results_exact[0].score == 63
    assert results_exact[0].distance == 0
    assert results_similar[0].path == 'test'
    assert results_similar[0].score == 17
    assert abs(results_similar[0].distance - 0.20599895341812172) < 1e-8
Exemplo n.º 2
0
def test_hashing(read_asset, config_injector):
    config_injector({
        'elasticsearch': {
            'host': 'localhost',
            'port': 9200,
            'index': 'szurubooru_test',
            'user': '******',
            'pass': None,
        },
    })

    if not image_hash.get_session().ping():
        pytest.xfail('Unable to connect to ElasticSearch, '
                     'perhaps it is not available for this test?')

    image_hash.purge()
    image_hash.add_image('test', read_asset('jpeg.jpg'))

    paths = image_hash.get_all_paths()
    results_exact = image_hash.search_by_image(read_asset('jpeg.jpg'))
    results_similar = image_hash.search_by_image(
        read_asset('jpeg-similar.jpg'))

    assert len(paths) == 1
    assert len(results_exact) == 1
    assert len(results_similar) == 1
    assert results_exact[0].path == 'test'
    assert results_exact[0].score == 63
    assert results_exact[0].distance == 0
    assert results_similar[0].path == 'test'
    assert results_similar[0].score == 17
    assert abs(results_similar[0].distance - 0.20599895341812172) < 1e-8
Exemplo n.º 3
0
def search_by_image(image_content: bytes) -> List[PostLookalike]:
    ret = []
    for result in image_hash.search_by_image(image_content):
        ret.append(
            PostLookalike(score=result.score,
                          distance=result.distance,
                          post=get_post_by_id(result.path)))
    return ret
Exemplo n.º 4
0
def search_by_image(image_content: bytes) -> List[PostLookalike]:
    ret = []
    for result in image_hash.search_by_image(image_content):
        post = try_get_post_by_id(result.path)
        if post:
            ret.append(PostLookalike(
                score=result.score,
                distance=result.distance,
                post=post))
    return ret
Exemplo n.º 5
0
def search_by_image(image_content):
    for result in image_hash.search_by_image(image_content):
        yield PostLookalike(
            score=result.score,
            distance=result.distance,
            post=get_post_by_id(result.path))