From 27140d83da7ee7e6ffb9a507c0ec67aee1f9f164 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Tue, 15 Oct 2019 17:27:27 +0200 Subject: [PATCH] fix multi-level deskewing: - 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 --- ocrd/ocrd/workspace.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ocrd/ocrd/workspace.py b/ocrd/ocrd/workspace.py index 7d2a1d3bde..facfe0df63 100644 --- a/ocrd/ocrd/workspace.py +++ b/ocrd/ocrd/workspace.py @@ -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(',')): @@ -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: @@ -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: