Skip to content

Commit 0ac2573

Browse files
committed
bugfix in tile script and updates to the params for get_4way_intersection_point
1 parent aeb2065 commit 0ac2573

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ The `get_intersection_point` method is the most critical part to customize for a
135135
3. Identifying the point closest to the expected corner position, while also matching an expected angle and distance from an anchor point.
136136

137137
![corner for 4way intersection point](/samples/corner3.png)
138-
- **`get_4way_intersection_point`**: This is a more robust version for crosshair-style corners. It specifically looks for intersections where four lines meet, making it less prone to errors from stray lines in the map collar.
138+
- **`get_4way_intersection_point`**: This is a more robust version for crosshair-style corners. It works by:
139+
1. Isolating lines based on their color.
140+
2. Optionally removing any text that might interfere with line detection.
141+
3. Ignoring the edges of the corner image patch to avoid spurious intersections with the border.
142+
4. Detecting all horizontal and vertical lines and finding their intersection points.
143+
5. Validating each intersection by checking for the presence of lines extending in all four directions (up, down, left, right) from the intersection point. This ensures it's a true 4-way "crosshair" intersection.
144+
6. It is designed to be very specific and will fail if it doesn't find exactly one 4-way intersection.
139145

140146
![corner for biggest contour corner](/samples/corner2.png)
141147
- **`get_biggest_contour_corner`**: This strategy is designed for corners that are marked by a solid shape or a filled area (e.g., a colored square or circle). It works by:

topo_map_processor/processor.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,12 +1074,16 @@ def get_nearest_intersection_point(self, img,
10741074

10751075
return ip
10761076

1077-
def get_4way_intersection_point(self, img, line_color,
1077+
def get_4way_intersection_point(self, img, line_color, remove_text,
10781078
find_line_scale, find_line_iter,
1079-
cwidth, ext_thresh):
1079+
cwidth, ext_thresh, direction,
1080+
remove_corner_edges_ratio):
10801081
img_mask = self.get_color_mask(img, line_color)
10811082

1082-
self.remove_text(img_mask)
1083+
if remove_text:
1084+
self.remove_text(img_mask)
1085+
1086+
self.remove_corner_edges(img_mask, direction, remove_corner_edges_ratio)
10831087

10841088
h, w = img_mask.shape[:2]
10851089
self.show_image(img_mask)
@@ -1106,7 +1110,8 @@ def get_4way_intersection_point(self, img, line_color,
11061110
if len(four_corner_ips) > 1:
11071111
continue
11081112

1109-
self.show_points(four_corner_ips, img_mask, [0, 255, 0])
1113+
self.show_points(four_corner_ips, img_mask, [0, 255, 0])
1114+
11101115
if len(four_corner_ips) > 1:
11111116
raise Exception(f'multiple intersection points found - {len(four_corner_ips)}')
11121117

topo_map_processor/tools/tile.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from pathlib import Path
1111
from multiprocessing import set_start_method, cpu_count
12+
from pprint import pprint
1213

1314
from osgeo_utils.gdal2tiles import submain as gdal2tiles_main
1415

@@ -56,6 +57,14 @@ def get_tiler_cmd_params(tile_extension, tile_quality):
5657

5758
raise ValueError(f'Unsupported tile extension: {tile_extension}, {SUPPORTED_FORMATS=}')
5859

60+
def get_format(tile_extension):
61+
if tile_extension == 'webp':
62+
return 'webp'
63+
if tile_extension == 'jpeg':
64+
return 'jpeg'
65+
if tile_extension == 'png':
66+
return 'png'
67+
raise ValueError(f'Unsupported tile extension: {tile_extension}, {SUPPORTED_FORMATS=}')
5968

6069

6170
def cli():
@@ -131,17 +140,22 @@ def cli():
131140

132141
metadata_file = tiles_dir / 'tiles.json'
133142

143+
fmt = get_format(args.tile_extension)
144+
134145
# it is not really a proper tilejson spec.. it is the basic things needed to populate a pmtiles metadata
135146
metadata = {
136147
'type': 'baselayer',
137-
'format': format,
148+
'format': fmt,
138149
'attribution': attribution_text,
139150
'description': args.description,
140151
'name': args.name,
141152
'version': '1',
142153
'maxzoom': args.max_zoom,
143154
'minzoom': args.min_zoom,
144155
}
156+
157+
print(f'writing metadata to {metadata_file}')
158+
pprint(metadata)
145159
metadata_file.write_text(json.dumps(metadata, indent=2))
146160

147161
print('All Done!!')

0 commit comments

Comments
 (0)