(page: Any)
| 258 | |
| 259 | |
| 260 | def _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 | |
| 287 | def _ocr_page_with_pytesseract(page: Any) -> str: |
no test coverage detected