Skip to content

Commit

Permalink
Merge pull request #371 from bertsky/increase-image-size-tolerance
Browse files Browse the repository at this point in the history
image_from_*: increase tolerance for size mismatch after rotation to 2px
  • Loading branch information
kba authored Dec 18, 2019
2 parents a2df716 + cbc6add commit 5ae2d56
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ocrd/ocrd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ def image_from_page(self, page, page_id,
[page_xywh['w'], page_xywh['h']], skew)
# FIXME we should enforce consistency here (i.e. rotation always reshapes,
# and rescaling never happens)
if not (w_new - 1.5 < page_image.width < w_new + 1.5 and
h_new - 1.5 < page_image.height < h_new + 1.5):
if not (w_new - 2 < page_image.width < w_new + 2 and
h_new - 2 < page_image.height < h_new + 2):
log.error('page "%s" image (%s; %dx%d) has not been reshaped properly (%dx%d) during rotation',
page_id, page_coords['features'],
page_image.width, page_image.height,
Expand Down Expand Up @@ -741,15 +741,16 @@ def image_from_segment(self, segment, parent_image, parent_coords,
# and rescaling never happens)
w_new, h_new = adjust_canvas_to_rotation(
[segment_xywh['w'], segment_xywh['h']], skew)
if not (w_new - 1.5 < segment_image.width < w_new + 1.5 and
h_new - 1.5 < segment_image.height < h_new + 1.5):
if not (w_new - 2 < segment_image.width < w_new + 2 and
h_new - 2 < segment_image.height < h_new + 2):
log.error('segment "%s" image (%s; %dx%d) has not been reshaped properly (%dx%d) during rotation',
segment.id, segment_coords['features'],
segment_image.width, segment_image.height,
w_new, h_new)
else:
if not (segment_xywh['w'] - 1.5 < segment_image.width < segment_xywh['w'] + 1.5 and
segment_xywh['h'] - 1.5 < segment_image.height < segment_xywh['h'] + 1.5):
# FIXME: currently unavoidable with line-level dewarping (which increases height)
if not (segment_xywh['w'] - 2 < segment_image.width < segment_xywh['w'] + 2 and
segment_xywh['h'] - 2 < segment_image.height < segment_xywh['h'] + 2):
log.error('segment "%s" image (%s; %dx%d) has not been cropped properly (%dx%d)',
segment.id, segment_coords['features'],
segment_image.width, segment_image.height,
Expand Down

0 comments on commit 5ae2d56

Please sign in to comment.