@@ -385,7 +385,8 @@ def _process_segment(self, parent, parent_image, parent_coords, page_id, zoom, l
385
385
# combine all assigned new lines to single outline polygon
386
386
if len (new_lines ) > 1 :
387
387
LOG .debug ("joining %d new line polygons for '%s'" , len (new_lines ), line .id )
388
- new_polygon = join_polygons ([intersections [(i , j )] for i in new_lines ], loc = line .id )
388
+ new_polygon = join_polygons ([intersections [(i , j )] for i in new_lines ],
389
+ loc = line .id , scale = scale )
389
390
line_polygons [j ] = new_polygon
390
391
# convert back to absolute (page) coordinates:
391
392
line_polygon = coordinates_for_segment (new_polygon .exterior .coords [:- 1 ],
@@ -460,7 +461,8 @@ def spread_dist(lines, old_labels, new_labels, binarized, components, coords,
460
461
else :
461
462
# get alpha shape
462
463
poly = join_polygons ([make_valid (Polygon (contour ))
463
- for contour in contours ], loc = line .id )
464
+ for contour in contours ],
465
+ loc = line .id , scale = scale )
464
466
poly = poly .exterior .coords [:- 1 ]
465
467
polygon = coordinates_for_segment (poly , None , coords )
466
468
polygon = polygon_for_parent (polygon , line .parent_object_ )
@@ -478,7 +480,7 @@ def diff_polygons(poly1, poly2):
478
480
poly = make_valid (poly )
479
481
return poly
480
482
481
- def join_polygons (polygons , loc = '' ):
483
+ def join_polygons (polygons , loc = '' , scale = 20 ):
482
484
"""construct concave hull (alpha shape) from input polygons"""
483
485
# compoundp = unary_union(polygons)
484
486
# jointp = compoundp.convex_hull
@@ -493,14 +495,14 @@ def join_polygons(polygons, loc=''):
493
495
# (otherwise alphashape will jump across the interior)
494
496
points = [poly .exterior .interpolate (dist ).coords [0 ] # .xy
495
497
for poly in polygons
496
- for dist in np .arange (0 , poly .length , 5.0 )]
498
+ for dist in np .arange (0 , poly .length , scale / 2 )]
497
499
#alpha = alphashape.optimizealpha(points) # too slow
498
- alpha = 0.05
500
+ alpha = 0.03
499
501
jointp = alphashape .alphashape (points , alpha )
500
502
tries = 0
501
503
# from descartes import PolygonPatch
502
504
# import matplotlib.pyplot as plt
503
- while jointp .type in ['MultiPolygon' , 'GeometryCollection' ]:
505
+ while jointp .type in ['MultiPolygon' , 'GeometryCollection' ] or len ( jointp . interiors ) :
504
506
# plt.figure()
505
507
# plt.gca().scatter(*zip(*points))
506
508
# for geom in jointp.geoms:
0 commit comments