|
|
@ -1,23 +1,36 @@
|
|
|
|
# pylint: disable=too-many-locals,wrong-import-position,too-many-lines,too-many-statements,chained-comparison,fixme,broad-except,c-extension-no-member
|
|
|
|
# pylint: disable=too-many-locals,wrong-import-position,too-many-lines,too-many-statements,chained-comparison,fixme,broad-except,c-extension-no-member
|
|
|
|
|
|
|
|
# pylint: disable=import-error
|
|
|
|
from pathlib import Path
|
|
|
|
from pathlib import Path
|
|
|
|
import os.path
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
|
|
|
from .utils.xml import create_page_xml, add_textequiv, xml_reading_order
|
|
|
|
from .utils.xml import create_page_xml, xml_reading_order
|
|
|
|
from .utils.counter import EynollahIdCounter
|
|
|
|
from .utils.counter import EynollahIdCounter
|
|
|
|
|
|
|
|
|
|
|
|
from ocrd_utils import getLogger
|
|
|
|
from ocrd_utils import getLogger
|
|
|
|
from lxml import etree as ET
|
|
|
|
from ocrd_models.ocrd_page import (
|
|
|
|
|
|
|
|
BorderType,
|
|
|
|
|
|
|
|
CoordsType,
|
|
|
|
|
|
|
|
TextEquivType,
|
|
|
|
|
|
|
|
PcGtsType,
|
|
|
|
|
|
|
|
TextLineType,
|
|
|
|
|
|
|
|
TextRegionType,
|
|
|
|
|
|
|
|
ImageRegionType,
|
|
|
|
|
|
|
|
TableRegionType,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
to_xml
|
|
|
|
|
|
|
|
)
|
|
|
|
import numpy as np
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
class EynollahXmlWriter():
|
|
|
|
class EynollahXmlWriter():
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, *, dir_out, image_filename, curved_line):
|
|
|
|
def __init__(self, *, dir_out, image_filename, curved_line, pcgts=None):
|
|
|
|
self.logger = getLogger('eynollah.writer')
|
|
|
|
self.logger = getLogger('eynollah.writer')
|
|
|
|
self.counter = EynollahIdCounter()
|
|
|
|
self.counter = EynollahIdCounter()
|
|
|
|
self.dir_out = dir_out
|
|
|
|
self.dir_out = dir_out
|
|
|
|
self.image_filename = image_filename
|
|
|
|
self.image_filename = image_filename
|
|
|
|
self.image_filename_stem = Path(Path(image_filename).name).stem
|
|
|
|
self.image_filename_stem = Path(Path(image_filename).name).stem
|
|
|
|
self.curved_line = curved_line
|
|
|
|
self.curved_line = curved_line
|
|
|
|
|
|
|
|
self.pcgts = pcgts if pcgts else PcGtsType()
|
|
|
|
self.scale_x = None # XXX set outside __init__
|
|
|
|
self.scale_x = None # XXX set outside __init__
|
|
|
|
self.scale_y = None # XXX set outside __init__
|
|
|
|
self.scale_y = None # XXX set outside __init__
|
|
|
|
self.height_org = None # XXX set outside __init__
|
|
|
|
self.height_org = None # XXX set outside __init__
|
|
|
@ -38,12 +51,12 @@ class EynollahXmlWriter():
|
|
|
|
points_page_print = points_page_print + ' '
|
|
|
|
points_page_print = points_page_print + ' '
|
|
|
|
return points_page_print[:-1]
|
|
|
|
return points_page_print[:-1]
|
|
|
|
|
|
|
|
|
|
|
|
def serialize_lines_in_marginal(self, marginal, all_found_texline_polygons_marginals, marginal_idx, page_coord, all_box_coord_marginals, slopes_marginals, counter):
|
|
|
|
def serialize_lines_in_marginal(self, marginal_region, all_found_texline_polygons_marginals, marginal_idx, page_coord, all_box_coord_marginals, slopes_marginals, counter):
|
|
|
|
for j in range(len(all_found_texline_polygons_marginals[marginal_idx])):
|
|
|
|
for j in range(len(all_found_texline_polygons_marginals[marginal_idx])):
|
|
|
|
textline = ET.SubElement(marginal, 'TextLine')
|
|
|
|
coords = CoordsType()
|
|
|
|
textline.set('id', counter.next_line_id)
|
|
|
|
textline = TextLineType(id=counter.next_line_id, coords=coords)
|
|
|
|
coord = ET.SubElement(textline, 'Coords')
|
|
|
|
marginal_region.add_TextLine(textline)
|
|
|
|
add_textequiv(textline)
|
|
|
|
textline.add_TextEquiv(TextEquivType(Unicode=''))
|
|
|
|
points_co = ''
|
|
|
|
points_co = ''
|
|
|
|
for l in range(len(all_found_texline_polygons_marginals[marginal_idx][j])):
|
|
|
|
for l in range(len(all_found_texline_polygons_marginals[marginal_idx][j])):
|
|
|
|
if not self.curved_line:
|
|
|
|
if not self.curved_line:
|
|
|
@ -64,7 +77,7 @@ class EynollahXmlWriter():
|
|
|
|
points_co += str(int((all_found_texline_polygons_marginals[marginal_idx][j][l][0][0] + page_coord[2]) / self.scale_x))
|
|
|
|
points_co += str(int((all_found_texline_polygons_marginals[marginal_idx][j][l][0][0] + page_coord[2]) / self.scale_x))
|
|
|
|
points_co += ','
|
|
|
|
points_co += ','
|
|
|
|
points_co += str(int((all_found_texline_polygons_marginals[marginal_idx][j][l][0][1] + page_coord[0]) / self.scale_y))
|
|
|
|
points_co += str(int((all_found_texline_polygons_marginals[marginal_idx][j][l][0][1] + page_coord[0]) / self.scale_y))
|
|
|
|
|
|
|
|
|
|
|
|
elif self.curved_line and np.abs(slopes_marginals[marginal_idx]) > 45:
|
|
|
|
elif self.curved_line and np.abs(slopes_marginals[marginal_idx]) > 45:
|
|
|
|
if len(all_found_texline_polygons_marginals[marginal_idx][j][l]) == 2:
|
|
|
|
if len(all_found_texline_polygons_marginals[marginal_idx][j][l]) == 2:
|
|
|
|
points_co += str(int((all_found_texline_polygons_marginals[marginal_idx][j][l][0] + all_box_coord_marginals[marginal_idx][2] + page_coord[2]) / self.scale_x))
|
|
|
|
points_co += str(int((all_found_texline_polygons_marginals[marginal_idx][j][l][0] + all_box_coord_marginals[marginal_idx][2] + page_coord[2]) / self.scale_x))
|
|
|
@ -74,20 +87,16 @@ class EynollahXmlWriter():
|
|
|
|
points_co += str(int((all_found_texline_polygons_marginals[marginal_idx][j][l][0][0] + all_box_coord_marginals[marginal_idx][2] + page_coord[2]) / self.scale_x))
|
|
|
|
points_co += str(int((all_found_texline_polygons_marginals[marginal_idx][j][l][0][0] + all_box_coord_marginals[marginal_idx][2] + page_coord[2]) / self.scale_x))
|
|
|
|
points_co += ','
|
|
|
|
points_co += ','
|
|
|
|
points_co += str(int((all_found_texline_polygons_marginals[marginal_idx][j][l][0][1] + all_box_coord_marginals[marginal_idx][0] + page_coord[0]) / self.scale_y))
|
|
|
|
points_co += str(int((all_found_texline_polygons_marginals[marginal_idx][j][l][0][1] + all_box_coord_marginals[marginal_idx][0] + page_coord[0]) / self.scale_y))
|
|
|
|
|
|
|
|
points += ' '
|
|
|
|
|
|
|
|
coords.set_points(points_co[:-1])
|
|
|
|
|
|
|
|
|
|
|
|
if l < len(all_found_texline_polygons_marginals[marginal_idx][j]) - 1:
|
|
|
|
def serialize_lines_in_region(self, text_region, all_found_texline_polygons, region_idx, page_coord, all_box_coord, slopes, counter):
|
|
|
|
points_co += ' '
|
|
|
|
|
|
|
|
coord.set('points',points_co)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def serialize_lines_in_region(self, textregion, all_found_texline_polygons, region_idx, page_coord, all_box_coord, slopes, counter):
|
|
|
|
|
|
|
|
self.logger.debug('enter serialize_lines_in_region')
|
|
|
|
self.logger.debug('enter serialize_lines_in_region')
|
|
|
|
for j in range(len(all_found_texline_polygons[region_idx])):
|
|
|
|
for j in range(len(all_found_texline_polygons[region_idx])):
|
|
|
|
textline = ET.SubElement(textregion, 'TextLine')
|
|
|
|
coords = CoordsType()
|
|
|
|
textline.set('id', counter.next_line_id)
|
|
|
|
textline = TextLineType(id=counter.next_line_id, coords=coords, TextEquiv=[TextEquivType(index=0, Unicode='')])
|
|
|
|
coord = ET.SubElement(textline, 'Coords')
|
|
|
|
text_region.add_TextLine(textline)
|
|
|
|
add_textequiv(textline)
|
|
|
|
|
|
|
|
region_bboxes = all_box_coord[region_idx]
|
|
|
|
region_bboxes = all_box_coord[region_idx]
|
|
|
|
|
|
|
|
|
|
|
|
points_co = ''
|
|
|
|
points_co = ''
|
|
|
|
for idx_contour_textline, contour_textline in enumerate(all_found_texline_polygons[region_idx][j]):
|
|
|
|
for idx_contour_textline, contour_textline in enumerate(all_found_texline_polygons[region_idx][j]):
|
|
|
|
if not self.curved_line:
|
|
|
|
if not self.curved_line:
|
|
|
@ -119,23 +128,22 @@ class EynollahXmlWriter():
|
|
|
|
points_co += str(int((contour_textline[0][0] + region_bboxes[2]+page_coord[2])/self.scale_x))
|
|
|
|
points_co += str(int((contour_textline[0][0] + region_bboxes[2]+page_coord[2])/self.scale_x))
|
|
|
|
points_co += ','
|
|
|
|
points_co += ','
|
|
|
|
points_co += str(int((contour_textline[0][1] + region_bboxes[0]+page_coord[0])/self.scale_y))
|
|
|
|
points_co += str(int((contour_textline[0][1] + region_bboxes[0]+page_coord[0])/self.scale_y))
|
|
|
|
|
|
|
|
|
|
|
|
points_co += ' '
|
|
|
|
points_co += ' '
|
|
|
|
coord.set('points', points_co[:-1])
|
|
|
|
coords.set_points(points_co[:-1])
|
|
|
|
|
|
|
|
|
|
|
|
def write_pagexml(self, pcgts):
|
|
|
|
def write_pagexml(self, pcgts):
|
|
|
|
self.logger.info("filename stem: '%s'", self.image_filename_stem)
|
|
|
|
out_fname = os.path.join(self.dir_out, self.image_filename_stem) + ".xml"
|
|
|
|
tree = ET.ElementTree(pcgts)
|
|
|
|
self.logger.info("output filename: '%s'", out_fname)
|
|
|
|
tree.write(os.path.join(self.dir_out, self.image_filename_stem) + ".xml")
|
|
|
|
with open(out_fname, 'w') as f:
|
|
|
|
|
|
|
|
f.write(to_xml(pcgts))
|
|
|
|
|
|
|
|
|
|
|
|
def build_pagexml_no_full_layout(self, found_polygons_text_region, page_coord, order_of_texts, id_of_texts, all_found_texline_polygons, all_box_coord, found_polygons_text_region_img, found_polygons_marginals, all_found_texline_polygons_marginals, all_box_coord_marginals, slopes, slopes_marginals, cont_page):
|
|
|
|
def build_pagexml_no_full_layout(self, found_polygons_text_region, page_coord, order_of_texts, id_of_texts, all_found_texline_polygons, all_box_coord, found_polygons_text_region_img, found_polygons_marginals, all_found_texline_polygons_marginals, all_box_coord_marginals, slopes, slopes_marginals, cont_page):
|
|
|
|
self.logger.debug('enter build_pagexml_no_full_layout')
|
|
|
|
self.logger.debug('enter build_pagexml_no_full_layout')
|
|
|
|
|
|
|
|
|
|
|
|
# create the file structure
|
|
|
|
# create the file structure
|
|
|
|
pcgts, page = create_page_xml(self.image_filename, self.height_org, self.width_org)
|
|
|
|
pcgts = create_page_xml(self.image_filename, self.height_org, self.width_org)
|
|
|
|
page_print_sub = ET.SubElement(page, "Border")
|
|
|
|
page = pcgts.get_Page()
|
|
|
|
coord_page = ET.SubElement(page_print_sub, "Coords")
|
|
|
|
page.set_Border(BorderType(Coords=CoordsType(points=self.calculate_page_coords(cont_page))))
|
|
|
|
coord_page.set('points', self.calculate_page_coords(cont_page))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
counter = EynollahIdCounter()
|
|
|
|
counter = EynollahIdCounter()
|
|
|
|
if len(found_polygons_text_region) > 0:
|
|
|
|
if len(found_polygons_text_region) > 0:
|
|
|
@ -144,33 +152,28 @@ class EynollahXmlWriter():
|
|
|
|
xml_reading_order(page, order_of_texts, id_of_marginalia)
|
|
|
|
xml_reading_order(page, order_of_texts, id_of_marginalia)
|
|
|
|
|
|
|
|
|
|
|
|
for mm in range(len(found_polygons_text_region)):
|
|
|
|
for mm in range(len(found_polygons_text_region)):
|
|
|
|
textregion = ET.SubElement(page, 'TextRegion')
|
|
|
|
textregion = TextRegionType(id=counter.next_region_id, type='paragraph',
|
|
|
|
textregion.set('id', counter.next_region_id)
|
|
|
|
Coords=CoordsType(points=self.calculate_polygon_coords(found_polygons_text_region[mm], page_coord)),
|
|
|
|
textregion.set('type', 'paragraph')
|
|
|
|
TextEquiv=[TextEquivType(index=0, Unicode='')])
|
|
|
|
coord_text = ET.SubElement(textregion, 'Coords')
|
|
|
|
page.add_TextRegion(textregion)
|
|
|
|
coord_text.set('points', self.calculate_polygon_coords(found_polygons_text_region[mm], page_coord))
|
|
|
|
|
|
|
|
self.serialize_lines_in_region(textregion, all_found_texline_polygons, mm, page_coord, all_box_coord, slopes, counter)
|
|
|
|
self.serialize_lines_in_region(textregion, all_found_texline_polygons, mm, page_coord, all_box_coord, slopes, counter)
|
|
|
|
add_textequiv(textregion)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for mm in range(len(found_polygons_marginals)):
|
|
|
|
for mm in range(len(found_polygons_marginals)):
|
|
|
|
marginal = ET.SubElement(page, 'TextRegion')
|
|
|
|
marginal = TextRegionType(id=counter.next_region_id, type='marginalia',
|
|
|
|
marginal.set('id', counter.next_region_id)
|
|
|
|
Coords=CoordsType(points=self.calculate_polygon_coords(found_polygons_marginals[mm], page_coord)))
|
|
|
|
marginal.set('type', 'marginalia')
|
|
|
|
page.add_TextRegion(marginal)
|
|
|
|
coord_text = ET.SubElement(marginal, 'Coords')
|
|
|
|
|
|
|
|
coord_text.set('points', self.calculate_polygon_coords(found_polygons_marginals[mm], page_coord))
|
|
|
|
|
|
|
|
self.serialize_lines_in_marginal(marginal, all_found_texline_polygons_marginals, mm, page_coord, all_box_coord_marginals, slopes_marginals, counter)
|
|
|
|
self.serialize_lines_in_marginal(marginal, all_found_texline_polygons_marginals, mm, page_coord, all_box_coord_marginals, slopes_marginals, counter)
|
|
|
|
|
|
|
|
|
|
|
|
for mm in range(len(found_polygons_text_region_img)):
|
|
|
|
for mm in range(len(found_polygons_text_region_img)):
|
|
|
|
textregion = ET.SubElement(page, 'ImageRegion')
|
|
|
|
img_region = ImageRegionType(id=counter.next_region_id, Coords=CoordsType())
|
|
|
|
textregion.set('id', counter.next_region_id)
|
|
|
|
page.add_ImageRegion(img_region)
|
|
|
|
coord_text = ET.SubElement(textregion, 'Coords')
|
|
|
|
|
|
|
|
points_co = ''
|
|
|
|
points_co = ''
|
|
|
|
for lmm in range(len(found_polygons_text_region_img[mm])):
|
|
|
|
for lmm in range(len(found_polygons_text_region_img[mm])):
|
|
|
|
points_co += str(int((found_polygons_text_region_img[mm][lmm,0,0] + page_coord[2]) / self.scale_x))
|
|
|
|
points_co += str(int((found_polygons_text_region_img[mm][lmm,0,0] + page_coord[2]) / self.scale_x))
|
|
|
|
points_co += ','
|
|
|
|
points_co += ','
|
|
|
|
points_co += str(int((found_polygons_text_region_img[mm][lmm,0,1] + page_coord[0]) / self.scale_y))
|
|
|
|
points_co += str(int((found_polygons_text_region_img[mm][lmm,0,1] + page_coord[0]) / self.scale_y))
|
|
|
|
points_co += ' '
|
|
|
|
points_co += ' '
|
|
|
|
coord_text.set('points', points_co[:-1])
|
|
|
|
img_region.get_Coords().set_points(points_co[:-1])
|
|
|
|
|
|
|
|
|
|
|
|
return pcgts
|
|
|
|
return pcgts
|
|
|
|
|
|
|
|
|
|
|
@ -178,10 +181,9 @@ class EynollahXmlWriter():
|
|
|
|
self.logger.debug('enter build_pagexml_full_layout')
|
|
|
|
self.logger.debug('enter build_pagexml_full_layout')
|
|
|
|
|
|
|
|
|
|
|
|
# create the file structure
|
|
|
|
# create the file structure
|
|
|
|
pcgts, page = create_page_xml(self.image_filename, self.height_org, self.width_org)
|
|
|
|
pcgts = create_page_xml(self.image_filename, self.height_org, self.width_org)
|
|
|
|
page_print_sub = ET.SubElement(page, "Border")
|
|
|
|
page = pcgts.get_Page()
|
|
|
|
coord_page = ET.SubElement(page_print_sub, "Coords")
|
|
|
|
page.set_Border(BorderType(Coords=CoordsType(points=self.calculate_page_coords(cont_page))))
|
|
|
|
coord_page.set('points', self.calculate_page_coords(cont_page))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
counter = EynollahIdCounter()
|
|
|
|
counter = EynollahIdCounter()
|
|
|
|
_counter_marginals = EynollahIdCounter(region_idx=len(order_of_texts))
|
|
|
|
_counter_marginals = EynollahIdCounter(region_idx=len(order_of_texts))
|
|
|
@ -189,52 +191,37 @@ class EynollahXmlWriter():
|
|
|
|
xml_reading_order(page, order_of_texts, id_of_marginalia)
|
|
|
|
xml_reading_order(page, order_of_texts, id_of_marginalia)
|
|
|
|
|
|
|
|
|
|
|
|
for mm in range(len(found_polygons_text_region)):
|
|
|
|
for mm in range(len(found_polygons_text_region)):
|
|
|
|
textregion=ET.SubElement(page, 'TextRegion')
|
|
|
|
textregion = TextRegionType(id=counter.next_region_id, type='paragraph',
|
|
|
|
textregion.set('id', counter.next_region_id)
|
|
|
|
TextEquiv=[TextEquivType(index=0, Unicode='')],
|
|
|
|
textregion.set('type', 'paragraph')
|
|
|
|
Coords=CoordsType(points=self.calculate_polygon_coords(found_polygons_text_region[mm], page_coord)))
|
|
|
|
coord_text = ET.SubElement(textregion, 'Coords')
|
|
|
|
page.add_TextRegion(textregion)
|
|
|
|
coord_text.set('points', self.calculate_polygon_coords(found_polygons_text_region[mm], page_coord))
|
|
|
|
|
|
|
|
self.serialize_lines_in_region(textregion, all_found_texline_polygons, mm, page_coord, all_box_coord, slopes, counter)
|
|
|
|
self.serialize_lines_in_region(textregion, all_found_texline_polygons, mm, page_coord, all_box_coord, slopes, counter)
|
|
|
|
add_textequiv(textregion)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.logger.debug('len(found_polygons_text_region_h) %s', len(found_polygons_text_region_h))
|
|
|
|
self.logger.debug('len(found_polygons_text_region_h) %s', len(found_polygons_text_region_h))
|
|
|
|
for mm in range(len(found_polygons_text_region_h)):
|
|
|
|
for mm in range(len(found_polygons_text_region_h)):
|
|
|
|
textregion=ET.SubElement(page, 'TextRegion')
|
|
|
|
textregion = TextRegionType(id=counter.next_region_id, type='header',
|
|
|
|
textregion.set('id', counter.next_region_id)
|
|
|
|
TextEquiv=[TextEquivType(index=0, Unicode='')],
|
|
|
|
textregion.set('type','header')
|
|
|
|
Coords=CoordsType(points=self.calculate_polygon_coords(found_polygons_text_region_h[mm], page_coord)))
|
|
|
|
coord_text = ET.SubElement(textregion, 'Coords')
|
|
|
|
page.add_TextRegion(textregion)
|
|
|
|
coord_text.set('points', self.calculate_polygon_coords(found_polygons_text_region_h[mm], page_coord))
|
|
|
|
|
|
|
|
self.serialize_lines_in_region(textregion, all_found_texline_polygons_h, mm, page_coord, all_box_coord_h, slopes, counter)
|
|
|
|
self.serialize_lines_in_region(textregion, all_found_texline_polygons_h, mm, page_coord, all_box_coord_h, slopes, counter)
|
|
|
|
add_textequiv(textregion)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for mm in range(len(found_polygons_marginals)):
|
|
|
|
for mm in range(len(found_polygons_marginals)):
|
|
|
|
marginal = ET.SubElement(page, 'TextRegion')
|
|
|
|
marginal = TextRegionType(id=counter.next_region_id, type='marginalia',
|
|
|
|
add_textequiv(textregion)
|
|
|
|
TextEquiv=[TextEquivType(index=0, Unicode='')],
|
|
|
|
marginal.set('id', counter.next_region_id)
|
|
|
|
Coords=CoordsType(points=self.calculate_polygon_coords(found_polygons_marginals[mm], page_coord)))
|
|
|
|
marginal.set('type', 'marginalia')
|
|
|
|
page.add_TextRegion(marginal)
|
|
|
|
coord_text = ET.SubElement(marginal, 'Coords')
|
|
|
|
|
|
|
|
coord_text.set('points', self.calculate_polygon_coords(found_polygons_marginals[mm], page_coord))
|
|
|
|
|
|
|
|
self.serialize_lines_in_marginal(marginal, all_found_texline_polygons_marginals, mm, page_coord, all_box_coord_marginals, slopes_marginals, counter)
|
|
|
|
self.serialize_lines_in_marginal(marginal, all_found_texline_polygons_marginals, mm, page_coord, all_box_coord_marginals, slopes_marginals, counter)
|
|
|
|
|
|
|
|
|
|
|
|
for mm in range(len(found_polygons_drop_capitals)):
|
|
|
|
for mm in range(len(found_polygons_drop_capitals)):
|
|
|
|
textregion=ET.SubElement(page, 'TextRegion')
|
|
|
|
page.add_TextRegion(TextRegionType(id=counter.next_region_id, type='drop-capital',
|
|
|
|
textregion.set('id', counter.next_region_id)
|
|
|
|
TextEquiv=[TextEquivType(index=0, Unicode='')],
|
|
|
|
textregion.set('type', 'drop-capital')
|
|
|
|
Coords=CoordsType(points=self.calculate_polygon_coords(found_polygons_drop_capitals[mm], page_coord))))
|
|
|
|
coord_text = ET.SubElement(textregion, 'Coords')
|
|
|
|
|
|
|
|
coord_text.set('points', self.calculate_polygon_coords(found_polygons_drop_capitals[mm], page_coord))
|
|
|
|
|
|
|
|
add_textequiv(textregion)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for mm in range(len(found_polygons_text_region_img)):
|
|
|
|
for mm in range(len(found_polygons_text_region_img)):
|
|
|
|
textregion=ET.SubElement(page, 'ImageRegion')
|
|
|
|
page.add_ImageRegion(ImageRegionType(id=counter.next_region_id, Coords=CoordsType(points=self.calculate_polygon_coords(found_polygons_text_region_img[mm], page_coord))))
|
|
|
|
textregion.set('id', counter.next_region_id)
|
|
|
|
|
|
|
|
coord_text = ET.SubElement(textregion, 'Coords')
|
|
|
|
|
|
|
|
coord_text.set('points', self.calculate_polygon_coords(found_polygons_text_region_img[mm], page_coord))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for mm in range(len(found_polygons_tables)):
|
|
|
|
for mm in range(len(found_polygons_tables)):
|
|
|
|
textregion = ET.SubElement(page, 'TableRegion')
|
|
|
|
page.add_TableRegion(TableRegionType(id=counter.next_region_id, Coords=CoordsType(points=self.calculate_polygon_coords(found_polygons_tables[mm], page_coord))))
|
|
|
|
textregion.set('id', counter.next_region_id)
|
|
|
|
|
|
|
|
coord_text = ET.SubElement(textregion, 'Coords')
|
|
|
|
|
|
|
|
coord_text.set('points', self.calculate_polygon_coords(found_polygons_tables[mm], page_coord))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pcgts
|
|
|
|
return pcgts
|
|
|
|
|
|
|
|
|
|
|
|