def query2(querydir, querysift, dbdir, mainOutputDir, nClosestCells, copytopmatch, params, copy_top_n_percell=0):
    lat, lon = info.getQuerySIFTCoord(querysift)
    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.getQuerySIFTCoord(querysift)
    if verbosity > 0:
        print "checking query: {0} \t against {1} \t cells".format(querysift, 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, querysift)
        outputFilePath = os.path.join(mainOutputDir, querysift + ',' + cell + ',' + str(actualdist)  + ".res")
        outputFilePaths.append(outputFilePath)
    # start query
    query.run_parallel(dbdir, [c for c,d in cells_in_range], querydir, querysift, 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, querysift + ',' + cell + ',' + str(actualdist)  + ".res")
        if copy_top_n_percell > 0:
            outputDir = os.path.join(mainOutputDir, querysift + ',' + 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, querysift)
#    write_scores(querysift, combined, "/media/data/combined")
    [g, y, r, b, o] = check_topn_img(querysift, combined, topnresults)
    if copytopmatch:
        match = g or y or r or b or o
        copy_top_match(querydir, querysift.split('sift.txt')[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.getSiftFileNames(querydir)
    total_in_range=0
    for querysift in queries:
        lat, lon = info.getQuerySIFTCoord(querysift)
        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.º 3
0
 def iter2():
   for file in util.getSiftFileNames(self.querydir):
     image = _Query()
     if self.QUERY == 'query2':
       image.pgm_scale = 512/2592.0
     image.siftpath = os.path.join(self.querydir, file)
     image.jpgpath = os.path.join(self.querydir, image.siftname[:-8] + '.JPG')
     image.setSensorCoord(*info.add_error(info.getQuerySIFTCoord(file), self.added_error))
     if self.QUERY != 'query4-matlab':
       image.check()
     yield image
def filter_in_range(ranked_matches, querysift):
    qlat, qlon = info.getQuerySIFTCoord(querysift)
    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
def skew_location(querysift, radius):
    center = info.getQuerySIFTCoord(querysift)
    length = 2*radius
    points = []
    corner = info.moveLocation(center[0], center[1], (2**.5)*radius, -45)
    for i in range(length+1):
        row = info.moveLocation(corner[0], corner[1], i, 180)
        for j in range(length+1):
            point = info.moveLocation(row[0],row[1], j, 90)
            if info.distance(center[0],center[1], point[0], point[1]) <= radius:
                points.append(point)
    return points
Exemplo n.º 6
0
def writeQueryCoords(querydir, fname):
    """writes coordinates for all querysift in path into a file fname for use in google earth"""
    if not os.path.exists(querydir):
        print "invalid path"
        return
    f = open(fname, "w")
    for querysift in getSiftFileNames(querydir):
        lat, lon = info.getQuerySIFTCoord(querysift)
        lat = str(lat)
        lon = str(lon)
        f.write(',' + querysift.split(',')[0] + ',' + lon + ',' + lat + '' + '\n')
    f.close()
Exemplo n.º 7
0
def match(siftfile, lat=None, lon=None):
    if lat == None or lon == None:
        lat, lon = info.getQuerySIFTCoord(siftfile)
    stats, matchedimg, matches, combined = context.match(
        siftfile, matchdir, lat, lon)
    return matchedimg, matches
Exemplo n.º 8
0
def match(siftfile, lat=None, lon=None):
    if lat == None or lon == None:
        lat, lon = info.getQuerySIFTCoord(siftfile)
    stats, matchedimg, matches, combined = context.match(siftfile, matchdir, lat, lon)
    return matchedimg, matches