(page, dpi: int)
| 246 | |
| 247 | |
| 248 | def ocr_page(page, dpi: int) -> str: |
| 249 | if fitz is None or pytesseract is None or Image is None: |
| 250 | return "" |
| 251 | scale = dpi / 72.0 |
| 252 | matrix = fitz.Matrix(scale, scale) |
| 253 | pix = page.get_pixmap(matrix=matrix, alpha=False) |
| 254 | image = Image.open(io.BytesIO(pix.tobytes("png"))) |
| 255 | return normalize_whitespace(pytesseract.image_to_string(image)) |
| 256 | |
| 257 | |
| 258 | def extract_page_images(doc, page, page_number: int, images_dir: Path) -> list[dict]: |
no test coverage detected