diff --git a/sbb_newspapers_org_image/eynollah.py b/sbb_newspapers_org_image/eynollah.py index 5798c63..0dc4574 100644 --- a/sbb_newspapers_org_image/eynollah.py +++ b/sbb_newspapers_org_image/eynollah.py @@ -1122,52 +1122,6 @@ class eynollah: poly.put(poly_sub) box_sub.put(boxes_sub_new) - def serialize_lines_in_region(self, textregion, all_found_texline_polygons, region_idx, page_coord, all_box_coord, slopes, id_indexer_l): - self.logger.debug('enter serialize_lines_in_region') - for j in range(len(all_found_texline_polygons[region_idx])): - textline = ET.SubElement(textregion, 'TextLine') - textline.set('id', 'l%s' % id_indexer_l) - id_indexer_l += 1 - coord = ET.SubElement(textline, 'Coords') - add_textequiv(textline) - - points_co = '' - for l in range(len(all_found_texline_polygons[region_idx][j])): - if not self.curved_line: - if len(all_found_texline_polygons[region_idx][j][l])==2: - textline_x_coord = max(0, int((all_found_texline_polygons[region_idx][j][l][0] + all_box_coord[region_idx][2] + page_coord[2]) / self.scale_x)) - textline_y_coord = max(0, int((all_found_texline_polygons[region_idx][j][l][1] + all_box_coord[region_idx][0] + page_coord[0]) / self.scale_y)) - else: - textline_x_coord = max(0, int((all_found_texline_polygons[region_idx][j][l][0][0] + all_box_coord[region_idx][2] + page_coord[2]) / self.scale_x)) - textline_y_coord = max(0, int((all_found_texline_polygons[region_idx][j][l][0][1] + all_box_coord[region_idx][0] + page_coord[0]) / self.scale_y)) - points_co += str(textline_x_coord) - points_co += ',' - points_co += str(textline_y_coord) - - if self.curved_line and np.abs(slopes[region_idx]) <= 45: - if len(all_found_texline_polygons[region_idx][j][l]) == 2: - points_co += str(int((all_found_texline_polygons[region_idx][j][l][0] + page_coord[2]) / self.scale_x)) - points_co += ',' - points_co += str(int((all_found_texline_polygons[region_idx][j][l][1] + page_coord[0]) / self.scale_y)) - else: - points_co += str(int((all_found_texline_polygons[region_idx][j][l][0][0] + page_coord[2]) / self.scale_x)) - points_co += ',' - points_co += str(int((all_found_texline_polygons[region_idx][j][l][0][1] + page_coord[0])/self.scale_y)) - elif self.curved_line and np.abs(slopes[region_idx]) > 45: - if len(all_found_texline_polygons[region_idx][j][l])==2: - points_co += str(int((all_found_texline_polygons[region_idx][j][l][0] + all_box_coord[region_idx][2]+page_coord[2])/self.scale_x)) - points_co += ',' - points_co += str(int((all_found_texline_polygons[region_idx][j][l][1] + all_box_coord[region_idx][0]+page_coord[0])/self.scale_y)) - else: - points_co += str(int((all_found_texline_polygons[region_idx][j][l][0][0] + all_box_coord[region_idx][2]+page_coord[2])/self.scale_x)) - points_co += ',' - points_co += str(int((all_found_texline_polygons[region_idx][j][l][0][1] + all_box_coord[region_idx][0]+page_coord[0])/self.scale_y)) - - if l < len(all_found_texline_polygons[region_idx][j]) - 1: - points_co += ' ' - coord.set('points',points_co) - return id_indexer_l - def calculate_polygon_coords(self, contour_list, i, page_coord): self.logger.debug('enter calculate_polygon_coords') coords = '' @@ -1182,7 +1136,7 @@ class eynollah: coords += str(int((contour_list[i][j][0][1] + page_coord[0]) / self.scale_y)) if j < len(contour_list[i]) - 1: - coords=coords+' ' + coords=coords + ' ' #print(coords) return coords @@ -1225,6 +1179,52 @@ class eynollah: name.set('regionRef', 'r%s' % indexer_region) indexer_region += 1 + def serialize_lines_in_region(self, textregion, all_found_texline_polygons, region_idx, page_coord, all_box_coord, slopes, id_indexer_l): + self.logger.debug('enter serialize_lines_in_region') + for j in range(len(all_found_texline_polygons[region_idx])): + textline = ET.SubElement(textregion, 'TextLine') + textline.set('id', 'l%s' % id_indexer_l) + id_indexer_l += 1 + coord = ET.SubElement(textline, 'Coords') + add_textequiv(textline) + + points_co = '' + for l in range(len(all_found_texline_polygons[region_idx][j])): + if not self.curved_line: + if len(all_found_texline_polygons[region_idx][j][l])==2: + textline_x_coord = max(0, int((all_found_texline_polygons[region_idx][j][l][0] + all_box_coord[region_idx][2] + page_coord[2]) / self.scale_x)) + textline_y_coord = max(0, int((all_found_texline_polygons[region_idx][j][l][1] + all_box_coord[region_idx][0] + page_coord[0]) / self.scale_y)) + else: + textline_x_coord = max(0, int((all_found_texline_polygons[region_idx][j][l][0][0] + all_box_coord[region_idx][2] + page_coord[2]) / self.scale_x)) + textline_y_coord = max(0, int((all_found_texline_polygons[region_idx][j][l][0][1] + all_box_coord[region_idx][0] + page_coord[0]) / self.scale_y)) + points_co += str(textline_x_coord) + points_co += ',' + points_co += str(textline_y_coord) + + if self.curved_line and np.abs(slopes[region_idx]) <= 45: + if len(all_found_texline_polygons[region_idx][j][l]) == 2: + points_co += str(int((all_found_texline_polygons[region_idx][j][l][0] + page_coord[2]) / self.scale_x)) + points_co += ',' + points_co += str(int((all_found_texline_polygons[region_idx][j][l][1] + page_coord[0]) / self.scale_y)) + else: + points_co += str(int((all_found_texline_polygons[region_idx][j][l][0][0] + page_coord[2]) / self.scale_x)) + points_co += ',' + points_co += str(int((all_found_texline_polygons[region_idx][j][l][0][1] + page_coord[0])/self.scale_y)) + elif self.curved_line and np.abs(slopes[region_idx]) > 45: + if len(all_found_texline_polygons[region_idx][j][l])==2: + points_co += str(int((all_found_texline_polygons[region_idx][j][l][0] + all_box_coord[region_idx][2]+page_coord[2])/self.scale_x)) + points_co += ',' + points_co += str(int((all_found_texline_polygons[region_idx][j][l][1] + all_box_coord[region_idx][0]+page_coord[0])/self.scale_y)) + else: + points_co += str(int((all_found_texline_polygons[region_idx][j][l][0][0] + all_box_coord[region_idx][2]+page_coord[2])/self.scale_x)) + points_co += ',' + points_co += str(int((all_found_texline_polygons[region_idx][j][l][0][1] + all_box_coord[region_idx][0]+page_coord[0])/self.scale_y)) + + if l < len(all_found_texline_polygons[region_idx][j]) - 1: + points_co += ' ' + coord.set('points',points_co) + return id_indexer_l + def write_into_page_xml(self, found_polygons_text_region, page_coord, dir_of_image, 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, curved_line, slopes, slopes_marginals): self.logger.debug('enter write_into_page_xml')