Skip to content

Commit 5ae2d56

Browse files
authored
Merge pull request #371 from bertsky/increase-image-size-tolerance
image_from_*: increase tolerance for size mismatch after rotation to 2px
2 parents a2df716 + cbc6add commit 5ae2d56

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

ocrd/ocrd/workspace.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ def image_from_page(self, page, page_id,
479479
[page_xywh['w'], page_xywh['h']], skew)
480480
# FIXME we should enforce consistency here (i.e. rotation always reshapes,
481481
# and rescaling never happens)
482-
if not (w_new - 1.5 < page_image.width < w_new + 1.5 and
483-
h_new - 1.5 < page_image.height < h_new + 1.5):
482+
if not (w_new - 2 < page_image.width < w_new + 2 and
483+
h_new - 2 < page_image.height < h_new + 2):
484484
log.error('page "%s" image (%s; %dx%d) has not been reshaped properly (%dx%d) during rotation',
485485
page_id, page_coords['features'],
486486
page_image.width, page_image.height,
@@ -741,15 +741,16 @@ def image_from_segment(self, segment, parent_image, parent_coords,
741741
# and rescaling never happens)
742742
w_new, h_new = adjust_canvas_to_rotation(
743743
[segment_xywh['w'], segment_xywh['h']], skew)
744-
if not (w_new - 1.5 < segment_image.width < w_new + 1.5 and
745-
h_new - 1.5 < segment_image.height < h_new + 1.5):
744+
if not (w_new - 2 < segment_image.width < w_new + 2 and
745+
h_new - 2 < segment_image.height < h_new + 2):
746746
log.error('segment "%s" image (%s; %dx%d) has not been reshaped properly (%dx%d) during rotation',
747747
segment.id, segment_coords['features'],
748748
segment_image.width, segment_image.height,
749749
w_new, h_new)
750750
else:
751-
if not (segment_xywh['w'] - 1.5 < segment_image.width < segment_xywh['w'] + 1.5 and
752-
segment_xywh['h'] - 1.5 < segment_image.height < segment_xywh['h'] + 1.5):
751+
# FIXME: currently unavoidable with line-level dewarping (which increases height)
752+
if not (segment_xywh['w'] - 2 < segment_image.width < segment_xywh['w'] + 2 and
753+
segment_xywh['h'] - 2 < segment_image.height < segment_xywh['h'] + 2):
753754
log.error('segment "%s" image (%s; %dx%d) has not been cropped properly (%dx%d)',
754755
segment.id, segment_coords['features'],
755756
segment_image.width, segment_image.height,

0 commit comments

Comments
 (0)