Esempio n. 1
0
 def iter_semantic_graphic_for_layout_document(
         self, layout_document: LayoutDocument,
         extract_graphic_assets: bool) -> Iterable[SemanticGraphic]:
     page_by_page_number_map = self.get_page_by_page_number_map(
         layout_document)
     LOGGER.debug('cv model: page_by_page_number_map=%r',
                  page_by_page_number_map)
     has_cv_semantic_graphic: bool = False
     for page_image in self.page_image_iterable:
         LOGGER.debug('page_image: %r', page_image)
         page_number = page_image.page_number
         with PIL.Image.open(page_image.page_image_path) as image:
             for semantic_graphic in self.iter_semantic_graphic_for_image(
                     image,
                     extract_graphic_assets=extract_graphic_assets,
                     page_number=page_number,
                     page=page_by_page_number_map.get(page_number)):
                 has_cv_semantic_graphic = True
                 yield semantic_graphic
     if not has_cv_semantic_graphic:
         LOGGER.info(
             'no graphics detected using cv model, falling back to regular graphics'
         )
         yield from get_semantic_graphic_list_for_layout_graphic_list(
             layout_document.iter_all_graphics(),
             extract_graphic_assets=extract_graphic_assets)
Esempio n. 2
0
 def iter_semantic_graphic_for_layout_document(
         self, layout_document: LayoutDocument,
         extract_graphic_assets: bool) -> Iterable[SemanticGraphic]:
     return get_semantic_graphic_list_for_layout_graphic_list(
         layout_document.iter_all_graphics(),
         extract_graphic_assets=extract_graphic_assets)