torchocr.io#
- torchocr.io.load_image(path, mode=ImageReadMode.RGB)[source]#
Load an image as a
(C, H, W)uint8tensor, RGB by default.Grayscale scans and RGBA screenshots are converted to the 3-channel RGB that pretrained models and
OCRPipelineexpect; passmode=ImageReadMode.UNCHANGEDto keep the file’s own channels.- Parameters:
mode (ImageReadMode)
- Return type:
- torchocr.io.load_pdf(path, dpi=200)[source]#
Load a PDF and return one
(3, H, W) uint8RGB tensor per page.Each page is rendered to a PyMuPDF
Pixmapat 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:
- Returns:
A list of
(3, H, W) uint8tensors, one per page in document order. Channel order is RGB.- Return type: