def image_matches_for_single_image(imgpath,
                                   bkgid=None,
                                   gweight=0.9,
                                   gmparams=None):
    amdid = imgpath.split('/')[7]
    if bkgid is None:
        bkgid = load_matches()[amdid]

    gm = GlobalMatcher(bkgid, gmparams)
    lm = LocalMatcher(bkgid)

    amdpath = join(FEATURES_PATH, './amadeus/%s/' % amdid)

    gfeats = load_global_features(amdpath)
    lfeats = load_local_features(amdpath)

    img_lf = lfeats[imgpath]
    img_gf = gfeats[imgpath]

    global_list = gm.find_similar(img_gf)
    local_list = lm.find_similar(img_lf)

    combined_list = ensembling([(global_list, gweight),
                                (local_list, 1 - gweight)])

    return combined_list
    dups, sims = image_matches_for_hotel_match(amdid, bkgid, ca, cb, gmparams,
                                               counts)
    pair = "%s %d" % (amdid, bkgid)
    if dups:
        duplicates[pair] = dups

    if sims:
        similar[pair] = sims

    ca.close()
    cb.close()


if __name__ == '__main__':
    matches = load_matches()
    pairs = matches.items()

    manager = Manager()

    duplicates = manager.dict()
    similar = manager.dict()
    # Here we will keep counts of Amadeus images:
    # - listed on DB
    # - successfully downloaded
    # - matched ( duplicate found )
    # - nearly mateched ( very similar image found )
    counts = manager.dict()
    counts['listed'] = 0
    counts['downloaded'] = 0
    counts['matched'] = 0
Exemple #3
0
#!/usr/bin/env python3
import argparse
import os
import tempfile

import cv2
import utils

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('gw_20p_wannot_dirpath')
    parser.add_argument('matches_filepath')
    args = parser.parse_args()

    matches = utils.load_matches(args.matches_filepath)

    output_dirpath = tempfile.mkdtemp()

    # extract top-k matches
    k = 20
    print(f'Extracting top-{k} matches in each page...')
    for page_filename, page_matches in matches.items():
        top_k_page_matches = sorted(page_matches, key=lambda x: x[1])[:k]
        assert len(top_k_page_matches) <= k

        page_image = cv2.imread(
            f'{args.gw_20p_wannot_dirpath}/{page_filename}')
        for i, match_scored in enumerate(top_k_page_matches):
            match = match_scored[0]

            # keep only non-empty keypoints