MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / __call__

Method __call__

docling/models/ocr_mac_model.py:38–118  ·  view source on GitHub ↗
(
        self, conv_res: ConversionResult, page_batch: Iterable[Page]
    )

Source from the content-addressed store, hash-verified

36 self.reader_RIL = ocrmac.OCR
37
38 def __call__(
39 self, conv_res: ConversionResult, page_batch: Iterable[Page]
40 ) -> Iterable[Page]:
41
42 if not self.enabled:
43 yield from page_batch
44 return
45
46 for page in page_batch:
47 assert page._backend is not None
48 if not page._backend.is_valid():
49 yield page
50 else:
51 with TimeRecorder(conv_res, "ocr"):
52
53 ocr_rects = self.get_ocr_rects(page)
54
55 all_ocr_cells = []
56 for ocr_rect in ocr_rects:
57 # Skip zero area boxes
58 if ocr_rect.area() == 0:
59 continue
60 high_res_image = page._backend.get_page_image(
61 scale=self.scale, cropbox=ocr_rect
62 )
63
64 with tempfile.NamedTemporaryFile(
65 suffix=".png", mode="w"
66 ) as image_file:
67 fname = image_file.name
68 high_res_image.save(fname)
69
70 boxes = self.reader_RIL(
71 fname,
72 recognition_level=self.options.recognition,
73 framework=self.options.framework,
74 language_preference=self.options.lang,
75 ).recognize()
76
77 im_width, im_height = high_res_image.size
78 cells = []
79 for ix, (text, confidence, box) in enumerate(boxes):
80 x = float(box[0])
81 y = float(box[1])
82 w = float(box[2])
83 h = float(box[3])
84
85 x1 = x * im_width
86 y2 = (1 - y) * im_height
87
88 x2 = x1 + w * im_width
89 y1 = y2 - h * im_height
90
91 left = x1 / self.scale
92 top = y1 / self.scale
93 right = x2 / self.scale
94 bottom = y2 / self.scale
95

Callers

nothing calls this directly

Calls 9

TimeRecorderClass · 0.90
OcrCellClass · 0.90
is_validMethod · 0.45
get_ocr_rectsMethod · 0.45
areaMethod · 0.45
get_page_imageMethod · 0.45
saveMethod · 0.45
post_process_cellsMethod · 0.45

Tested by

no test coverage detected