4
4
from itertools import chain
5
5
import numpy as np
6
6
from skimage import draw
7
- from shapely .geometry import Polygon , asPolygon , LineString
7
+ from shapely .geometry import Polygon , LineString
8
8
from shapely .prepared import prep
9
9
from shapely .ops import unary_union
10
10
import alphashape
@@ -209,7 +209,7 @@ def _process_segment(self, parent, parent_image, parent_coords, page_id, zoom, l
209
209
segment_polygon = coordinates_of_segment (segment , parent_image , parent_coords )
210
210
segment_polygon = make_valid (Polygon (segment_polygon )).buffer (margin )
211
211
line_polygons .append (prep (segment_polygon ))
212
- segment_polygon = np .array (segment_polygon .exterior , np .int )[:- 1 ]
212
+ segment_polygon = np .array (segment_polygon .exterior . coords , np .int )[:- 1 ]
213
213
# draw.polygon: If any segment_polygon lies outside of parent
214
214
# (causing negative/above-max indices), either fully or partially,
215
215
# then this will silently ignore them. The caller does not need
@@ -224,7 +224,7 @@ def _process_segment(self, parent, parent_image, parent_coords, page_id, zoom, l
224
224
segment .id , page_id if fullpage else parent .id )
225
225
segment_polygon = coordinates_of_segment (segment , parent_image , parent_coords )
226
226
segment_polygon = make_valid (Polygon (segment_polygon )).buffer (margin )
227
- segment_polygon = np .array (segment_polygon .exterior , np .int )[:- 1 ]
227
+ segment_polygon = np .array (segment_polygon .exterior . coords , np .int )[:- 1 ]
228
228
ignore_bin [draw .polygon (segment_polygon [:, 1 ],
229
229
segment_polygon [:, 0 ],
230
230
parent_bin .shape )] = False
@@ -271,7 +271,7 @@ def _process_segment(self, parent, parent_image, parent_coords, page_id, zoom, l
271
271
# left-hand side if left-to-right, and vice versa
272
272
scale * (- 1 ) ** line_ltr , single_sided = True )],
273
273
loc = line .id , scale = scale ))
274
- line_polygon = np .array (line_polygon .exterior , np .int )[:- 1 ]
274
+ line_polygon = np .array (line_polygon .exterior . coords , np .int )[:- 1 ]
275
275
line_y , line_x = draw .polygon (line_polygon [:, 1 ],
276
276
line_polygon [:, 0 ],
277
277
parent_bin .shape )
@@ -284,8 +284,8 @@ def _process_segment(self, parent, parent_image, parent_coords, page_id, zoom, l
284
284
parent_bin , seps = ignore_bin , zoom = zoom , fullpage = fullpage ,
285
285
maxseps = 0 , maxcolseps = len (ignore ), maximages = 0 )
286
286
except Exception as err :
287
- LOG .warning ('Cannot line-segment %s "%s": %s' ,
288
- tag , page_id if fullpage else parent .id , err )
287
+ LOG .error ('Cannot line-segment %s "%s": %s' ,
288
+ tag , page_id if fullpage else parent .id , err )
289
289
return
290
290
LOG .info ("Found %d new line labels for %d existing lines on %s '%s'" ,
291
291
new_line_labels .max (), len (lines ), tag , parent .id )
@@ -476,7 +476,7 @@ def diff_polygons(poly1, poly2):
476
476
if poly .type == 'MultiPolygon' :
477
477
poly = poly .convex_hull
478
478
if poly .minimum_clearance < 1.0 :
479
- poly = asPolygon (np .round (poly .exterior .coords ))
479
+ poly = Polygon (np .round (poly .exterior .coords ))
480
480
poly = make_valid (poly )
481
481
return poly
482
482
@@ -517,7 +517,7 @@ def join_polygons(polygons, loc='', scale=20):
517
517
if jointp .minimum_clearance < 1.0 :
518
518
# follow-up calculations will necessarily be integer;
519
519
# so anticipate rounding here and then ensure validity
520
- jointp = asPolygon (np .round (jointp .exterior .coords ))
520
+ jointp = Polygon (np .round (jointp .exterior .coords ))
521
521
jointp = make_valid (jointp )
522
522
return jointp
523
523
0 commit comments