File size: 694 Bytes
c330961
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Read a whole page/screenshot: RapidOCR's detector + this recogniser.

    pip install rapidocr_onnxruntime==1.4.4 opencv-python-headless huggingface_hub
    python rapidocr_page.py screenshot.png
"""
import sys

from huggingface_hub import hf_hub_download
from rapidocr_onnxruntime import RapidOCR

REPO = "ScienceSoft/scnsoft-ocr-rec-multilingual"


def main() -> None:
    engine = RapidOCR(
        rec_model_path=hf_hub_download(REPO, "rec-multi.onnx"),
        rec_keys_path=hf_hub_download(REPO, "dict-multi.txt"),
    )
    result, _ = engine(sys.argv[1])
    for _box, text, score in result or []:
        print(f"{float(score):.2f}  {text}")


if __name__ == "__main__":
    main()