Skip to content

Commit d75e58d

Browse files
author
Robert Sachunsky
committed
update to shapely 1.8
1 parent b856f5b commit d75e58d

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

ocrd_cis/ocropy/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ def compute_segmentation(binary,
11411141
LOG.debug('sorting labels by reading order')
11421142
llabels = morph.reading_order(llabels,rl,bt)[llabels]
11431143
DSAVE('llabels_ordered', llabels)
1144-
1144+
11451145
#segmentation = llabels*binary
11461146
#return segmentation
11471147
return llabels, hlines, vlines, images, colseps, scale

ocrd_cis/ocropy/resegment.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from itertools import chain
55
import numpy as np
66
from skimage import draw
7-
from shapely.geometry import Polygon, asPolygon, LineString
7+
from shapely.geometry import Polygon, LineString
88
from shapely.prepared import prep
99
from shapely.ops import unary_union
1010
import alphashape
@@ -209,7 +209,7 @@ def _process_segment(self, parent, parent_image, parent_coords, page_id, zoom, l
209209
segment_polygon = coordinates_of_segment(segment, parent_image, parent_coords)
210210
segment_polygon = make_valid(Polygon(segment_polygon)).buffer(margin)
211211
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]
213213
# draw.polygon: If any segment_polygon lies outside of parent
214214
# (causing negative/above-max indices), either fully or partially,
215215
# 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
224224
segment.id, page_id if fullpage else parent.id)
225225
segment_polygon = coordinates_of_segment(segment, parent_image, parent_coords)
226226
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]
228228
ignore_bin[draw.polygon(segment_polygon[:, 1],
229229
segment_polygon[:, 0],
230230
parent_bin.shape)] = False
@@ -271,7 +271,7 @@ def _process_segment(self, parent, parent_image, parent_coords, page_id, zoom, l
271271
# left-hand side if left-to-right, and vice versa
272272
scale * (-1) ** line_ltr, single_sided=True)],
273273
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]
275275
line_y, line_x = draw.polygon(line_polygon[:, 1],
276276
line_polygon[:, 0],
277277
parent_bin.shape)
@@ -284,8 +284,8 @@ def _process_segment(self, parent, parent_image, parent_coords, page_id, zoom, l
284284
parent_bin, seps=ignore_bin, zoom=zoom, fullpage=fullpage,
285285
maxseps=0, maxcolseps=len(ignore), maximages=0)
286286
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)
289289
return
290290
LOG.info("Found %d new line labels for %d existing lines on %s '%s'",
291291
new_line_labels.max(), len(lines), tag, parent.id)
@@ -476,7 +476,7 @@ def diff_polygons(poly1, poly2):
476476
if poly.type == 'MultiPolygon':
477477
poly = poly.convex_hull
478478
if poly.minimum_clearance < 1.0:
479-
poly = asPolygon(np.round(poly.exterior.coords))
479+
poly = Polygon(np.round(poly.exterior.coords))
480480
poly = make_valid(poly)
481481
return poly
482482

@@ -517,7 +517,7 @@ def join_polygons(polygons, loc='', scale=20):
517517
if jointp.minimum_clearance < 1.0:
518518
# follow-up calculations will necessarily be integer;
519519
# so anticipate rounding here and then ensure validity
520-
jointp = asPolygon(np.round(jointp.exterior.coords))
520+
jointp = Polygon(np.round(jointp.exterior.coords))
521521
jointp = make_valid(jointp)
522522
return jointp
523523

ocrd_cis/ocropy/segment.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from skimage import draw
66
from skimage.morphology import convex_hull_image
77
import cv2
8-
from shapely.geometry import Polygon, asPolygon
8+
from shapely.geometry import Polygon, LineString
99
from shapely.prepared import prep
1010
from shapely.ops import unary_union
1111

@@ -125,15 +125,16 @@ def masks2polygons(bg_labels, fg_bin, name, min_area=None, simplify=None):
125125
polygon = polygon.simplify(tolerance)
126126
if polygon.is_valid:
127127
break
128-
polygon = polygon.exterior.coords[:-1] # keep open
129-
if len(polygon) < 4:
128+
poly = polygon.exterior.coords[:-1] # keep open
129+
if len(poly) < 4:
130130
LOG.warning('Label %d contour %d has less than 4 points for %s',
131131
label, i, name)
132132
continue
133-
results.append((label, polygon))
133+
results.append((label, poly))
134134
result_labels[contour_labels == i+1] = len(results)
135135
return results, result_labels
136136

137+
137138
class OcropySegment(Processor):
138139

139140
def __init__(self, *args, **kwargs):
@@ -761,7 +762,7 @@ def make_intersection(poly1, poly2):
761762
if interp.minimum_clearance < 1.0:
762763
# follow-up calculations will necessarily be integer;
763764
# so anticipate rounding here and then ensure validity
764-
interp = asPolygon(np.round(interp.exterior.coords))
765+
interp = Polygon(np.round(interp.exterior.coords))
765766
interp = make_valid(interp)
766767
return interp
767768

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
'scipy',
4444
'numpy>=1.17.0',
4545
'pillow>=7.1.2',
46-
'shapely>=1.7.1,<1.8',
46+
'shapely>=1.7.1',
4747
'scikit-image',
4848
'alphashape',
4949
'opencv-python-headless',

0 commit comments

Comments
 (0)