Skip to content

Commit

Permalink
docs: Fixed docstring and export as xml dim bug (#586)
Browse files Browse the repository at this point in the history
* fix docstring and export as xml dim bug

* apply changes

Co-authored-by: Felix <felix.dittrich@memoresa.de>
  • Loading branch information
felixdittrich92 and Felix authored Nov 5, 2021
1 parent c882689 commit e96acd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions doctr/io/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class Page(Element):
Args:
blocks: list of block elements
page_idx: the index of the page in the input raw document
dimensions: the page size in pixels in format (width, height)
dimensions: the page size in pixels in format (height, width)
orientation: a dictionary with the value of the rotation angle in degress and confidence of the prediction
language: a dictionary with the language value and confidence of the prediction
"""
Expand Down Expand Up @@ -276,7 +276,7 @@ def export_as_xml(self, file_title: str = 'docTR - XML export (hOCR)') -> Tuple[
block_count: int = 1
line_count: int = 1
word_count: int = 1
width, height = self.dimensions
height, width = self.dimensions
language = self.language if 'language' in self.language.keys() else 'en'
# Create the XML root element
page_hocr = ETElement('html', attrib={'xmlns': 'http://www.w3.org/1999/xhtml', 'xml:lang': str(language)})
Expand Down
10 changes: 5 additions & 5 deletions doctr/utils/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def rect_patch(
Args:
geometry: bounding box of the element
page_dimensions: dimensions of the Page
page_dimensions: dimensions of the Page in format (height, width)
label: label to display when hovered
color: color to draw box
alpha: opacity parameter to fill the boxes, 0 = transparent
Expand Down Expand Up @@ -80,7 +80,7 @@ def polygon_patch(
Args:
geometry: bounding box of the element
page_dimensions: dimensions of the Page
page_dimensions: dimensions of the Page in format (height, width)
label: label to display when hovered
color: color to draw box
alpha: opacity parameter to fill the boxes, 0 = transparent
Expand Down Expand Up @@ -121,7 +121,7 @@ def create_obj_patch(
Args:
geometry: bounding box (straight or rotated) of the element
page_dimensions: dimensions of the page
page_dimensions: dimensions of the page in format (height, width)
Returns:
a matplotlib Patch
Expand Down Expand Up @@ -273,8 +273,8 @@ def synthesize_page(
for word in line["words"]:
# Get aboslute word geometry
(xmin, ymin), (xmax, ymax) = word["geometry"]
xmin, xmax = int(w * xmin), int(w * xmax)
ymin, ymax = int(h * ymin), int(h * ymax)
xmin, xmax = int(round(w * xmin)), int(round(w * xmax))
ymin, ymax = int(round(h * ymin)), int(round(h * ymax))

# White drawing context adapted to font size, 0.75 factor to convert pts --> pix
font = get_font(font_family, int(0.75 * (ymax - ymin)))
Expand Down

0 comments on commit e96acd1

Please sign in to comment.