English | 中文
doc page extractor can identify text and format in images and return structured data.
pip install doc-page-extractor
pip install >
Please refer to the introduction of PyTorch and select the appropriate command to install according to your operating system.
In addition, replace the command to install onnxruntime
in the previous article with the following:
pip install onnxruntime-gpu==1.21.0
from PIL import Image
from doc_page_extractor import DocExtractor
extractor = DocExtractor(
model_dir_path=model_path, # Folder address where AI model is downloaded and installed
device="cpu", # If you want to use CUDA, please change to device="cuda".
)
with Image.open("/path/to/your/image.png") as image:
result = extractor.extract(
image=image,
lang="ch", # Language of image text
)
for layout in result.layouts:
for fragment in layout.fragments:
print(fragment.rect, fragment.text)
The code of doc_page_extractor/onnxocr
in this repo comes from OnnxOCR.