Skip to content

Commit

Permalink
fix multi-level deskewing:
Browse files Browse the repository at this point in the history
- angle already applied must be sum of angle applied on parent level
  and on current level
- not all image features are monotonic
  - some do propagate through all hierarchy levels:
    binarized, grayscale_normalized, despeckled
  - some must be treated level-local (to make sense and allow for
    relative coordinate consistency):
    deskewed, rotated-90, rotated-180, rotated-270, dewarped
  • Loading branch information
bertsky committed Oct 15, 2019
1 parent a4ede35 commit 27140d8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ocrd/ocrd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,12 @@ def image_from_segment(self, segment, parent_image, parent_coords,
orientation = orientation - (orientation % 90)
skew = (angle % 360) - orientation
skew = 180 - (180 - skew) % 360 # map to [-45,45]
segment_coords['angle'] = parent_coords['angle'] # nothing applied yet (depends on filters)
log.debug("segment '%s' has orientation=%d skew=%.2f",
segment.id, orientation, skew)
else:
orientation = 0
skew = 0
segment_coords['angle'] = parent_coords['angle'] # nothing applied yet (depends on filters)

if (orientation and
not 'rotated-%d' % orientation in feature_filter.split(',')):
Expand All @@ -638,7 +638,7 @@ def image_from_segment(self, segment, parent_image, parent_coords,
0.5 * segment_xywh['h']]))
segment_xywh['w'], segment_xywh['h'] = adjust_canvas_to_transposition(
[segment_xywh['w'], segment_xywh['h']], transposition)
segment_coords['angle'] = orientation
segment_coords['angle'] += orientation
if (skew and
not 'deskewed' in feature_filter.split(',')):
# Rotate around center in affine coordinate transform:
Expand All @@ -650,9 +650,13 @@ def image_from_segment(self, segment, parent_image, parent_coords,
0.5 * segment_xywh['h']]))
segment_coords['angle'] += skew

# initialize AlternativeImage@comments classes from parent:
segment_coords['features'] = parent_coords['features'] + ',cropped'

# initialize AlternativeImage@comments classes from parent, except
# for those operations that can apply on multiple hierarchy levels:
segment_coords['features'] = ','.join(
[feature for feature in parent_coords['features'].split(',')
if feature in ['binarized', 'grayscale_normalized',
'despeckled', 'dewarped']])

alternative_image = None
alternative_images = segment.get_AlternativeImage()
if alternative_images:
Expand Down

0 comments on commit 27140d8

Please sign in to comment.