Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of ocrd_tesserocr common functionality into core #268

Merged
merged 19 commits into from
Aug 21, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions ocrd/ocrd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ def image_from_page(self, page, page_id):

Given a PageType object, `page`, extract its PIL.Image from
AlternativeImage if it exists. Otherwise extract the PIL.Image
from imageFilename and crop it if a Border exists. Otherwise
from imageFilename and cut it if a Border exists. Otherwise
just return it.

When cropping, respect any orientation angle annotated for
When cuting, respect any orientation angle annotated for
kba marked this conversation as resolved.
Show resolved Hide resolved
the page (from page-level deskewing) by rotating the
cropped image, respectively.
cut image, respectively.

If the resulting page image is larger than the bounding box of
`page`, pass down the page's box coordinates with an offset of
Expand Down Expand Up @@ -281,8 +281,8 @@ def image_from_page(self, page, page_id):

alternative_image = page.get_AlternativeImage()
if alternative_image:
# (e.g. from page-level cropping, binarization, deskewing or despeckling)
# assumes implicit cropping (i.e. page_xywh has been applied already)
# (e.g. from page-level cutting, binarization, deskewing or despeckling)
kba marked this conversation as resolved.
Show resolved Hide resolved
# assumes implicit cutting (i.e. page_xywh has been applied already)
kba marked this conversation as resolved.
Show resolved Hide resolved
log.debug("Using AlternativeImage %d (%s) for page '%s'",
len(alternative_image), alternative_image[-1].get_comments(),
page_id)
Expand All @@ -293,7 +293,7 @@ def image_from_page(self, page, page_id):
page_polygon = np.array(polygon_from_points(page_points))
# create a mask from the page polygon:
page_image = image_from_polygon(page_image, page_polygon)
# recrop into page rectangle:
# crop into page rectangle:
kba marked this conversation as resolved.
Show resolved Hide resolved
page_image = crop_image(page_image,
box=(page_xywh['x'],
page_xywh['y'],
Expand All @@ -318,21 +318,21 @@ def image_from_segment(self, segment, parent_image, parent_xywh):
its absolute coordinates, `parent_xywh`, and a PAGE
segment (TextRegion / TextLine / Word / Glyph) object
logically contained in it, `segment`, extract its PIL.Image
from AlternativeImage (if it exists), or via cropping from
from AlternativeImage (if it exists), or via cutting from
`parent_image`.

When cropping, respect any orientation angle annotated for
When cutting, respect any orientation angle annotated for
the parent (from parent-level deskewing) by compensating the
segment coordinates in an inverse transformation (translation
to center, rotation, re-translation).
Also, mind the difference between annotated and actual size
of the parent (usually from deskewing), by a respective offset
into the image. Cropping uses a polygon mask (not just the
into the image. Cutting uses a polygon mask (not just the
rectangle).

When cropping, respect any orientation angle annotated for
When cutting, respect any orientation angle annotated for
the segment (from segment-level deskewing) by rotating the
cropped image, respectively.
cutted image, respectively.

If the resulting segment image is larger than the bounding box of
`segment`, pass down the segment's box coordinates with an offset
Expand All @@ -348,7 +348,7 @@ def image_from_segment(self, segment, parent_image, parent_xywh):
segment_xywh['angle'] = -(segment.get_orientation() or 0)
alternative_image = segment.get_AlternativeImage()
if alternative_image:
# (e.g. from segment-level cropping, binarization, deskewing or despeckling)
# (e.g. from segment-level cutting, binarization, deskewing or despeckling)
log.debug("Using AlternativeImage %d (%s) for segment '%s'",
len(alternative_image), alternative_image[-1].get_comments(),
segment.id)
Expand All @@ -359,7 +359,7 @@ def image_from_segment(self, segment, parent_image, parent_xywh):
segment_polygon = coordinates_of_segment(segment, parent_image, parent_xywh)
# create a mask from the segment polygon:
segment_image = image_from_polygon(parent_image, segment_polygon)
# recrop into segment rectangle:
# crop into segment rectangle:
kba marked this conversation as resolved.
Show resolved Hide resolved
segment_image = crop_image(segment_image,
box=(segment_xywh['x'] - parent_xywh['x'],
segment_xywh['y'] - parent_xywh['y'],
Expand Down