torchocr.io#

torchocr.io.load_image(path, mode=ImageReadMode.RGB)[source]#

Load an image as a (C, H, W) uint8 tensor, RGB by default.

Grayscale scans and RGBA screenshots are converted to the 3-channel RGB that pretrained models and OCRPipeline expect; pass mode=ImageReadMode.UNCHANGED to keep the file’s own channels.

Parameters:
Return type:

Tensor

torchocr.io.load_pdf(path, dpi=200)[source]#

Load a PDF and return one (3, H, W) uint8 RGB tensor per page.

Each page is rendered to a PyMuPDF Pixmap at the requested DPI and converted into a fresh PyTorch tensor that does not alias the pixmap’s underlying memory. The pixmap and its sample buffer are released between pages, keeping peak memory bounded by the largest single page rather than the whole document.

Parameters:
  • path (str | Path) – Filesystem path to the PDF.

  • dpi (int) – Render resolution in dots-per-inch. Default 200 – a sane OCR baseline. PyMuPDF’s native unit is the PostScript point (1/72 inch); the conversion is Matrix(dpi/72, dpi/72).

Returns:

A list of (3, H, W) uint8 tensors, one per page in document order. Channel order is RGB.

Return type:

list[Tensor]