ocr_detect_all_bboxes.py 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. def ocr_prepare_bboxes_for_layout_split(img_blocks, table_blocks, discarded_blocks, text_blocks,
  2. title_blocks, interline_equation_blocks, page_w, page_h):
  3. all_bboxes = []
  4. for image in img_blocks:
  5. x0, y0, x1, y1 = image['bbox']
  6. all_bboxes.append([x0, y0, x1, y1, None, None, None, 'image_block', None, None, None, None])
  7. for table in table_blocks:
  8. x0, y0, x1, y1 = table['bbox']
  9. all_bboxes.append([x0, y0, x1, y1, None, None, None, 'table_block', None, None, None, None])
  10. for text in text_blocks:
  11. x0, y0, x1, y1 = text['bbox']
  12. all_bboxes.append([x0, y0, x1, y1, None, None, None, 'text_block', None, None, None, None])
  13. for title in title_blocks:
  14. x0, y0, x1, y1 = title['bbox']
  15. all_bboxes.append([x0, y0, x1, y1, None, None, None, 'title_block', None, None, None, None])
  16. for interline_equation in interline_equation_blocks:
  17. x0, y0, x1, y1 = interline_equation['bbox']
  18. all_bboxes.append([x0, y0, x1, y1, None, None, None, 'interline_equation_block', None, None, None, None])
  19. '''discarded_blocks中只保留宽度超过1/3页面宽度的,高度超过10的,处于页面下半50%区域的(限定footnote)'''
  20. for discarded in discarded_blocks:
  21. x0, y0, x1, y1 = discarded['bbox']
  22. if (x1 - x0) > (page_w / 3) and (y1 - y0) > 10 and y0 > (page_h / 2):
  23. all_bboxes.append([x0, y0, x1, y1, None, None, None, 'footnote', None, None, None, None])
  24. return all_bboxes