def next(self):
     row = self.csvreader.next()
     bounds = [float(x) for x in row['bounds'].replace('(','').replace(')','').replace(' ','').split(',')]
     row['bounds'] = bounds
     row['waypoints'] = ''
     if len(bounds) == 4:
         row['waypoints'] = CoordUtils.waypoints_for_linestring(
                 [(bounds[1],bounds[0]),(bounds[3],bounds[2])],
                 32)
     return row
示例#2
0
 def next(self):
     row = self.csvreader.next()
     bounds = [
         float(x)
         for x in row['bounds'].replace('(', '').replace(')', '').replace(
             ' ', '').split(',')
     ]
     row['bounds'] = bounds
     row['waypoints'] = ''
     if len(bounds) == 4:
         row['waypoints'] = CoordUtils.waypoints_for_linestring(
             [(bounds[1], bounds[0]), (bounds[3], bounds[2])], 32)
     return row
示例#3
0
 def next(self):
     if self.i < len(self.trees):
         i = self.i
         self.i += 1
         tree = self.trees[i]
         tree_kml_id = tree.name.split('.')[1]
         tree_id = ''
         et = etree.fromstring('<root>'+tree.description+'</root>')
         for li in et.findall('ul/li'):
             atrname = li.find(".//*[@class='atr-name']")
             if (atrname is not None) and (atrname.text == "TREEID"):
                 atrval = li.find(".//*[@class='atr-value']")
                 tree_id = atrval.text
         tree_latlng = [tree.geometry.y,tree.geometry.x]
         tree_stateplane = CoordUtils.stateplane_for_latlng(tree_latlng)
         return {'id': tree_id,
             'kml_id': tree_kml_id,
             'stateplane': tree_stateplane,
             'latlng': tree_latlng}
     else:
         raise StopIteration()
示例#4
0
def main(argv):
    usage_string = 'python tools/cut_training_images --trees_dir data/trees --map_dir data/maps/2014 --streets_dir data/streets --slices_dir data/slices/2014_64px --slice_size=64'
    trees_dir = ''
    map_dir = ''
    streets_dir = ''
    slices_dir = ''
    slice_size = 0

    try:
        opts, args = getopt.getopt(argv,"h", ["trees_dir=","map_dir=","slices_dir=","slice_size=","streets_dir="])
    except getopt.GetoptError:
        print usage_string
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            print usage_string
        elif opt == '--trees_dir':
            trees_dir = arg
        elif opt == '--map_dir':
            map_dir = arg
        elif opt == '--streets_dir':
            streets_dir = arg
        elif opt == '--slices_dir':
            slices_dir = arg
        elif opt == '--slice_size':
            slice_size = int(arg)

    if not os.path.exists(trees_dir):
        print "trees dir missing"
        sys.exit(2)
    if not os.path.exists(map_dir):
        print "map dir missing"
        sys.exit(2)
    if not os.path.exists(streets_dir):
        print "streets dir missing"
        sys.exit(2)
    if len(slices_dir) == 0:
        print "slices dir not specified"
        sys.exit(2)

    if not os.path.exists(slices_dir):
        os.makedirs(slices_dir)
    slices_0_dir = '{}/0'.format(slices_dir)
    slices_1_dir = '{}/1'.format(slices_dir)
    if not os.path.exists(slices_0_dir):
        os.makedirs(slices_0_dir)
    if not os.path.exists(slices_1_dir):
        os.makedirs(slices_1_dir)

    tile_map = TileMap(map_dir)
    trees = list(TreeList(trees_dir))
    street_list = StreetList(streets_dir)
    for street in street_list:
        i = 0
        for waypoint_latlng in street['waypoints']:
            waypoint = CoordUtils.stateplane_for_latlng(waypoint_latlng)
            i = i + 1
            l1_radius = slice_size/2
            trees_seen = []
            # TODO faster please
            for tree in trees:
                if (
                    tree['stateplane'][0] > waypoint[0]-l1_radius and
                    tree['stateplane'][0] < waypoint[0]+l1_radius and
                    tree['stateplane'][1] > waypoint[1]-l1_radius and
                    tree['stateplane'][1] < waypoint[1]+l1_radius):
                    trees_seen.append(tree)
            label = (0 if (len(trees_seen) == 0) else 1)
            try:
                region = tile_map.crop_around_stateplane(waypoint,slice_size)
                slice_fn = '{}/{}/st_{}_{}-sp_{},{}-ll_{},{}.jpg'.format(
                    slices_dir,label,
                    street['id'],i,
                    waypoint[0],waypoint[1],
                    waypoint_latlng[0],waypoint_latlng[1])
                region.save(slice_fn)
                print slice_fn
            except TileMapBoundsError:
                print "WARNING: waypoint out of bounds: {}".format(waypoint)
                pass
示例#5
0
def main(argv):
    usage_string = 'python tools/cut_training_images --trees_dir data/trees --map_dir data/maps/2014 --streets_dir data/streets --slices_dir data/slices/2014_64px --slice_size=64'
    trees_dir = ''
    map_dir = ''
    streets_dir = ''
    slices_dir = ''
    slice_size = 0

    try:
        opts, args = getopt.getopt(argv, "h", [
            "trees_dir=", "map_dir=", "slices_dir=", "slice_size=",
            "streets_dir="
        ])
    except getopt.GetoptError:
        print usage_string
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            print usage_string
        elif opt == '--trees_dir':
            trees_dir = arg
        elif opt == '--map_dir':
            map_dir = arg
        elif opt == '--streets_dir':
            streets_dir = arg
        elif opt == '--slices_dir':
            slices_dir = arg
        elif opt == '--slice_size':
            slice_size = int(arg)

    if not os.path.exists(trees_dir):
        print "trees dir missing"
        sys.exit(2)
    if not os.path.exists(map_dir):
        print "map dir missing"
        sys.exit(2)
    if not os.path.exists(streets_dir):
        print "streets dir missing"
        sys.exit(2)
    if len(slices_dir) == 0:
        print "slices dir not specified"
        sys.exit(2)

    if not os.path.exists(slices_dir):
        os.makedirs(slices_dir)
    slices_0_dir = '{}/0'.format(slices_dir)
    slices_1_dir = '{}/1'.format(slices_dir)
    if not os.path.exists(slices_0_dir):
        os.makedirs(slices_0_dir)
    if not os.path.exists(slices_1_dir):
        os.makedirs(slices_1_dir)

    tile_map = TileMap(map_dir)
    trees = list(TreeList(trees_dir))
    street_list = StreetList(streets_dir)
    for street in street_list:
        i = 0
        for waypoint_latlng in street['waypoints']:
            waypoint = CoordUtils.stateplane_for_latlng(waypoint_latlng)
            i = i + 1
            l1_radius = slice_size / 2
            trees_seen = []
            # TODO faster please
            for tree in trees:
                if (tree['stateplane'][0] > waypoint[0] - l1_radius
                        and tree['stateplane'][0] < waypoint[0] + l1_radius
                        and tree['stateplane'][1] > waypoint[1] - l1_radius
                        and tree['stateplane'][1] < waypoint[1] + l1_radius):
                    trees_seen.append(tree)
            label = (0 if (len(trees_seen) == 0) else 1)
            try:
                region = tile_map.crop_around_stateplane(waypoint, slice_size)
                slice_fn = '{}/{}/segment-{}-{}.jpg'.format(
                    slices_dir, label, street['kml_id'], i)
                region.save(slice_fn)
                print slice_fn
            except TileMapBoundsError:
                print "WARNING: waypoint out of bounds: {}".format(waypoint)
                pass
示例#6
0
 def pixels_around_latlng(self, latlng, width):
     stateplane = CoordUtils.stateplane_for_latlng(latlng)
     return self.pixels_around_stateplane(stateplane)
示例#7
0
 def tilepixel_with_latlng(self, latlng):
     stateplane = CoordUtils.stateplane_for_latlng(latlng)
     return self.tilepixel_with_stateplane(stateplane)
示例#8
0
 def pixels_around_latlng(self,latlng,width):
     stateplane = CoordUtils.stateplane_for_latlng(latlng);
     return self.pixels_around_stateplane(stateplane)
示例#9
0
 def tilepixel_with_latlng(self,latlng):
     stateplane = CoordUtils.stateplane_for_latlng(latlng);
     return self.tilepixel_with_stateplane(stateplane)