Esempio n. 1
0
def resize_and_save(df, img_name, true_idx, size='80x50', fraction=0.125):
    '''
    INPUT:  (1) Pandas DF
            (2) string: image name
            (3) integer: the true index in the df of the image
            (4) string: to append to filename
            (5) float: fraction to scale images by
    OUTPUT: None

    Resize and save the images in a new directory.
    Try to read the image. If it fails, download it to the raw data directory.
    Finally, read in the full size image and resize it.
    '''
    try:
        img = imread(img_name)
    except:
        cardinal_dir = img_name[-5:-4]
        cardinal_translation = {'N': 0, 'E': 90, 'S': 180, 'W': 270}
        coord = (df.ix[true_idx]['lat'], df.ix[true_idx]['lng'])
        print 'Saving new image...'
        print coord, cardinal_dir, cardinal_translation[cardinal_dir]
        save_image(coord, cardinal_translation[cardinal_dir], loc='newdata')
    finally:
        img_name_to_write = ('newdata_' + size + '/' +
                             img_name[8:-4] + size + '.png')
        if os.path.isfile(img_name_to_write) == False:
            img = imread(img_name)
            resized = imresize(img, fraction)
            print 'Writing file...'
            imsave(img_name_to_write, resized)
Esempio n. 2
0
def resize_and_save(df, img_name, true_idx, size='80x50', fraction=0.125):
    '''
    INPUT:  (1) Pandas DF
            (2) string: image name
            (3) integer: the true index in the df of the image
            (4) string: to append to filename
            (5) float: fraction to scale images by
    OUTPUT: None

    Resize and save the images in a new directory.
    Try to read the image. If it fails, download it to the raw data directory.
    Finally, read in the full size image and resize it.
    '''
    try:
        img = imread(img_name)
    except:
        cardinal_dir = img_name[-5:-4]
        cardinal_translation = {'N': 0, 'E': 90, 'S': 180, 'W': 270}
        coord = (df.ix[true_idx]['lat'], df.ix[true_idx]['lng'])
        print 'Saving new image...'
        print coord, cardinal_dir, cardinal_translation[cardinal_dir]
        save_image(coord, cardinal_translation[cardinal_dir], loc='newdata')
    finally:
        img_name_to_write = ('newdata_' + size + '/' + img_name[8:-4] + size +
                             '.png')
        if os.path.isfile(img_name_to_write) == False:
            img = imread(img_name)
            resized = imresize(img, fraction)
            print 'Writing file...'
            imsave(img_name_to_write, resized)
Esempio n. 3
0
def download_images(df, loc='newdata'):
    '''
    INPUT:  (1) Pandas DataFrame with locations to download images
            (2) string: what folder to save new images to
    OUTPUT: None

    Download images from Google Maps Streetview API using
    the function defined in imageScraper.
    The API maxes out at 25000 images a day (6250 total locations,
    NESW for each location)
    '''
    how_many_images_downloaded = 0
    for lt, lg in zip(df['lat'][14244:], df['lng'][14244:]):
        for heading in [0, 90, 180, 270]:
            print how_many_images_downloaded
            how_many_images_downloaded += 1
            save_image((lt, lg), heading, loc=loc)
Esempio n. 4
0
def download_images(df, loc='newdata'):
    '''
    INPUT:  (1) Pandas DataFrame with locations to download images
            (2) string: what folder to save new images to
    OUTPUT: None

    Download images from Google Maps Streetview API using
    the function defined in imageScraper.
    The API maxes out at 25000 images a day (6250 total locations,
    NESW for each location)
    '''
    how_many_images_downloaded = 0
    for lt, lg in zip(df['lat'][14244:], df['lng'][14244:]):
        for heading in [0, 90, 180, 270]:
            print how_many_images_downloaded
            how_many_images_downloaded += 1
            save_image((lt, lg), heading, loc=loc)