def query2(querydir, querysurf, dbdir, mainOutputDir, nClosestCells, copytopmatch, params, copy_top_n_percell=0):
    lat, lon = info.getQuerySURFCoord(querysurf)
    closest_cells = util.getclosestcells(lat, lon, dbdir)
    assert dict(closest_cells)['37.8732916331,-122.268346029'] < 236 or dict(closest_cells)['37.8714489427,-122.272389514'] < 236 or dict(closest_cells)['37.8696062215,-122.273737308'] < 236
    built = [
        '37.8732916331,-122.268346029',
        '37.8714489427,-122.272389514',
        '37.8696062215,-122.273737308',
    ]
    closest_cells = filter(lambda c: c[0] in built, closest_cells)
    outputFilePaths = []
    cells_in_range = [(cell, dist) for cell, dist in closest_cells[0:nClosestCells] if dist < cellradius + ambiguity+matchdistance]
    latquery, lonquery = info.getQuerySURFCoord(querysurf)
    if verbosity > 0:
        print "checking query: {0} \t against {1} \t cells".format(querysurf, len(cells_in_range))
    for cell, dist in cells_in_range:
        latcell, loncell = cell.split(',')
        latcell = float(latcell)
        loncell = float(loncell)
        actualdist = info.distance(latquery, lonquery, latcell, loncell)
        if verbosity > 1:
            print "querying cell: {0}, distance: {1} with:{2}".format(cell, actualdist, querysurf)
        outputFilePath = os.path.join(mainOutputDir, querysurf + ',' + cell + ',' + str(actualdist)  + ".res")
        outputFilePaths.append(outputFilePath)
    # start query
    query.run_parallel(dbdir, [c for c,d in cells_in_range], querydir, querysurf, outputFilePaths, params)
    # end query
    for cell, dist in cells_in_range:
        latcell, loncell = cell.split(',')
        latcell = float(latcell)
        loncell = float(loncell)
        actualdist = info.distance(latquery, lonquery, latcell, loncell)
        outputFilePath = os.path.join(mainOutputDir, querysurf + ',' + cell + ',' + str(actualdist)  + ".res")
        if copy_top_n_percell > 0:
            outputDir = os.path.join(mainOutputDir, querysurf + ',' + cell + ',' + str(actualdist))
            copy_topn_results(os.path.join(dbdir, cell), outputDir, outputFilePath, 4)
#    combined = combine_until_dup(outputFilePaths, 1000)
    combined = combine_topn_votes(outputFilePaths, float('inf'))
#    combined = filter_in_range(combined, querysurf)
#    write_scores(querysurf, combined, "/media/data/combined")
    [g, y, r, b, o] = check_topn_img(querysurf, combined, topnresults)
    if copytopmatch:
        match = g or y or r or b or o
        copy_top_match(querydir, querysurf.split('surf.npy')[0], combined, match)
    return [g, y, r, b, o]
def get_num_imgs_in_range(range, celldir, querydir='/home/zhangz/.gvfs/data on 128.32.43.40/query3/'):
    queries = util.getSURFFileNames(querydir)
    total_in_range=0
    for querysurf in queries:
        lat, lon = info.getQuerySURFCoord(querysurf)
        cell, dist = util.getclosestcell(lat, lon, celldir)
        numinrange = util.getNumJPGInRange(lat, lon, os.path.join(celldir,cell), range)
        total_in_range+=numinrange
    print "average # of imgs within {0} meters of query: {1}".format(range, float(total_in_range)/len(queries))
def filter_in_range(ranked_matches, querysurf):
    qlat, qlon = info.getQuerySURFCoord(querysurf)
    weighted_matches = []
    for matchedimg, score in ranked_matches:
        clat = float(matchedimg.split(",")[0])
        clon = float(matchedimg.split(",")[1][0:-5])
        distance = info.distance(qlat, qlon, clat, clon)
        if distance < ambiguity+matchdistance:
            weighted_matches.append((matchedimg, 2 * score))
    weighted_matches.sort(key=lambda x: x[1], reverse=True)
    return weighted_matches
Exemplo n.º 4
0
def filter_in_range(ranked_matches, querysurf):
    qlat, qlon = info.getQuerySURFCoord(querysurf)
    weighted_matches = []
    for matchedimg, score in ranked_matches:
        clat = float(matchedimg.split(",")[0])
        clon = float(matchedimg.split(",")[1][0:-5])
        distance = info.distance(qlat, qlon, clat, clon)
        if distance < ambiguity + matchdistance:
            weighted_matches.append((matchedimg, 2 * score))
    weighted_matches.sort(key=lambda x: x[1], reverse=True)
    return weighted_matches
Exemplo n.º 5
0
def get_num_imgs_in_range(
        range,
        celldir,
        querydir='/home/zhangz/.gvfs/data on 128.32.43.40/query3/'):
    queries = util.getSURFFileNames(querydir)
    total_in_range = 0
    for querysurf in queries:
        lat, lon = info.getQuerySURFCoord(querysurf)
        cell, dist = util.getclosestcell(lat, lon, celldir)
        numinrange = util.getNumJPGInRange(lat, lon,
                                           os.path.join(celldir, cell), range)
        total_in_range += numinrange
    print "average # of imgs within {0} meters of query: {1}".format(
        range,
        float(total_in_range) / len(queries))
Exemplo n.º 6
0
def query2(querydir,
           querysurf,
           dbdir,
           mainOutputDir,
           nClosestCells,
           copytopmatch,
           params,
           copy_top_n_percell=0):
    lat, lon = info.getQuerySURFCoord(querysurf)
    closest_cells = util.getclosestcells(lat, lon, dbdir)
    assert dict(closest_cells)['37.8732916331,-122.268346029'] < 236 or dict(
        closest_cells)['37.8714489427,-122.272389514'] < 236 or dict(
            closest_cells)['37.8696062215,-122.273737308'] < 236
    built = [
        '37.8732916331,-122.268346029',
        '37.8714489427,-122.272389514',
        '37.8696062215,-122.273737308',
    ]
    closest_cells = filter(lambda c: c[0] in built, closest_cells)
    outputFilePaths = []
    cells_in_range = [(cell, dist)
                      for cell, dist in closest_cells[0:nClosestCells]
                      if dist < cellradius + ambiguity + matchdistance]
    latquery, lonquery = info.getQuerySURFCoord(querysurf)
    if verbosity > 0:
        print "checking query: {0} \t against {1} \t cells".format(
            querysurf, len(cells_in_range))
    for cell, dist in cells_in_range:
        latcell, loncell = cell.split(',')
        latcell = float(latcell)
        loncell = float(loncell)
        actualdist = info.distance(latquery, lonquery, latcell, loncell)
        if verbosity > 1:
            print "querying cell: {0}, distance: {1} with:{2}".format(
                cell, actualdist, querysurf)
        outputFilePath = os.path.join(
            mainOutputDir,
            querysurf + ',' + cell + ',' + str(actualdist) + ".res")
        outputFilePaths.append(outputFilePath)
    # start query
    query.run_parallel(dbdir, [c for c, d in cells_in_range], querydir,
                       querysurf, outputFilePaths, params)
    # end query
    for cell, dist in cells_in_range:
        latcell, loncell = cell.split(',')
        latcell = float(latcell)
        loncell = float(loncell)
        actualdist = info.distance(latquery, lonquery, latcell, loncell)
        outputFilePath = os.path.join(
            mainOutputDir,
            querysurf + ',' + cell + ',' + str(actualdist) + ".res")
        if copy_top_n_percell > 0:
            outputDir = os.path.join(
                mainOutputDir, querysurf + ',' + cell + ',' + str(actualdist))
            copy_topn_results(os.path.join(dbdir, cell), outputDir,
                              outputFilePath, 4)


#    combined = combine_until_dup(outputFilePaths, 1000)
    combined = combine_topn_votes(outputFilePaths, float('inf'))
    #    combined = filter_in_range(combined, querysurf)
    #    write_scores(querysurf, combined, "/media/data/combined")
    [g, y, r, b, o] = check_topn_img(querysurf, combined, topnresults)
    if copytopmatch:
        match = g or y or r or b or o
        copy_top_match(querydir,
                       querysurf.split('surf.npy')[0], combined, match)
    return [g, y, r, b, o]