diff --git a/ocrd_tesserocr/crop.py b/ocrd_tesserocr/crop.py index 77d5493..e28eb98 100644 --- a/ocrd_tesserocr/crop.py +++ b/ocrd_tesserocr/crop.py @@ -9,6 +9,7 @@ coordinates_of_segment, bbox_from_polygon, bbox_from_points, + polygon_for_parent, polygon_from_bbox, points_from_polygon, bbox_from_xywh, @@ -27,7 +28,6 @@ from ocrd import Processor from .config import TESSDATA_PREFIX, OCRD_TOOL -from .segment_region import polygon_for_parent TOOL = 'ocrd-tesserocr-crop' LOG = getLogger('processor.TesserocrCrop') diff --git a/ocrd_tesserocr/segment_region.py b/ocrd_tesserocr/segment_region.py index df5e1ec..4867fd2 100644 --- a/ocrd_tesserocr/segment_region.py +++ b/ocrd_tesserocr/segment_region.py @@ -1,7 +1,6 @@ from __future__ import absolute_import import os.path -from shapely.geometry import Polygon from tesserocr import ( PyTessBaseAPI, PSM, RIL, PT @@ -12,6 +11,7 @@ make_file_id, assert_file_grp_cardinality, coordinates_for_segment, + polygon_for_parent, polygon_from_points, polygon_from_x0y0x1y1, points_from_polygon, @@ -23,7 +23,6 @@ MetadataItemType, LabelsType, LabelType, CoordsType, - PageType, OrderedGroupType, ReadingOrderType, RegionRefIndexedType, @@ -304,28 +303,3 @@ def _process_page(self, it, page, page_image, page_coords, page_id): not og.get_UnorderedGroupIndexed()): # schema forbids empty OrderedGroup ro.set_OrderedGroup(None) - -def polygon_for_parent(polygon, parent): - """Clip polygon to parent polygon range. - - (Should be moved to ocrd_utils.coordinates_for_segment.) - """ - childp = Polygon(polygon) - if isinstance(parent, PageType): - if parent.get_Border(): - parentp = Polygon(polygon_from_points(parent.get_Border().get_Coords().points)) - else: - parentp = Polygon([[0,0], [0,parent.get_imageHeight()], - [parent.get_imageWidth(),parent.get_imageHeight()], - [parent.get_imageWidth(),0]]) - else: - parentp = Polygon(polygon_from_points(parent.get_Coords().points)) - if childp.within(parentp): - return polygon - interp = childp.intersection(parentp) - if interp.is_empty: - # FIXME: we need a better strategy against this - raise Exception("intersection of would-be segment with parent is empty") - if interp.type == 'MultiPolygon': - interp = interp.convex_hull - return interp.exterior.coords[:-1] # keep open