示例#1
0
def siftImage(url):
    """
    """
    print >> sys.stderr, 'download...',

    bytes = StringIO.StringIO(urllib.urlopen(url).read())
    image = PIL.Image.open(bytes).convert('RGBA')

    print >> sys.stderr, image.size

    handle, sift_filename = tempfile.mkstemp(prefix='decode-', suffix='.sift')
    os.close(handle)

    handle, pgm_filename = tempfile.mkstemp(prefix='decode-', suffix='.pgm')
    os.close(handle)

    # fit to 1000x1000
    scale = min(1., 1000. / max(image.size))

    # write the PGM
    pgm_size = int(image.size[0] * scale), int(image.size[1] * scale)
    image.convert('L').resize(pgm_size, PIL.Image.ANTIALIAS).save(pgm_filename)

    print >> sys.stderr, 'sift...', pgm_size,

    basedir = os.path.dirname(os.path.realpath(__file__)).replace(' ', '\ ')
    status, output = commands.getstatusoutput(
        "%(basedir)s/bin/sift --peak-thresh=8 -o '%(sift_filename)s' '%(pgm_filename)s'"
        % locals())
    data = open(sift_filename, 'r')

    assert status == 0, 'Sift execution returned %s instead of 0' % status

    features = [matchup.row2feature(row) for row in data]

    print >> sys.stderr, len(features), 'features'

    os.unlink(sift_filename)
    os.unlink(pgm_filename)

    return image, features, scale
示例#2
0
    def __init__(self, basepath):
        data = open(basepath + '.sift', 'r')
        self.features = [matchup.row2feature(row) for row in data]

        point = open(basepath + '.txt', 'r')
        self.anchor = Point(*[int(c) for c in point.read().split()])