MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / _ocr_page_with_rapidocr

Function _ocr_page_with_rapidocr

skills/pdf-parser/scripts/parse_pdf.py:260–284  ·  view source on GitHub ↗
(page: Any)

Source from the content-addressed store, hash-verified

258
259
260def _ocr_page_with_rapidocr(page: Any) -> str:
261 engine = _get_rapidocr_engine()
262 if engine is None:
263 return ""
264
265 image = _render_page_to_numpy(page)
266 if image is None:
267 return ""
268
269 try:
270 result, _elapsed = engine(image)
271 except Exception:
272 return ""
273
274 texts: List[str] = []
275 for item in result or []:
276 if not isinstance(item, (list, tuple)) or len(item) < 2:
277 continue
278 candidate = item[1]
279 if isinstance(candidate, (list, tuple)) and candidate:
280 candidate = candidate[0]
281 text = str(candidate or "").strip()
282 if text:
283 texts.append(text)
284 return "\n".join(texts).strip()
285
286
287def _ocr_page_with_pytesseract(page: Any) -> str:

Callers 1

Calls 2

_get_rapidocr_engineFunction · 0.85
_render_page_to_numpyFunction · 0.85

Tested by

no test coverage detected