OpenRewind/openrecall/ocr.py
2024-06-09 00:59:25 +02:00

20 lines
496 B
Python

from doctr.models import ocr_predictor
ocr = ocr_predictor(
pretrained=True,
det_arch="db_mobilenet_v3_large",
reco_arch="crnn_mobilenet_v3_large",
)
def extract_text_from_image(image):
result = ocr([image])
text = ""
for page in result.pages:
for block in page.blocks:
for line in block.lines:
for word in line.words:
text += word.value + " "
text += "\n"
text += "\n"
return text