File size: 1,496 Bytes
10469c8 | 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 27 28 29 30 31 32 33 34 35 | """sumoocr IMAGE... [--format text|json] [--backend onnxruntime|openvino] [--threads N] [--max-side PX]"""
from __future__ import annotations
import argparse
import json
import sys
def main(argv=None) -> int:
ap = argparse.ArgumentParser(prog="sumoocr", description="SumoOCR tiny: text lines of page images, on CPU.")
ap.add_argument("images", nargs="+", help="page images (PNG, JPEG, TIFF, BMP, WebP)")
ap.add_argument("--format", choices=("text", "json"), default="text",
help="text: one line per text line; json: one object per image with lines, boxes, confidences")
ap.add_argument("--backend", choices=("onnxruntime", "openvino"), default="onnxruntime")
ap.add_argument("--threads", type=int, default=None, help="CPU threads per model (default: the runtime's)")
ap.add_argument("--max-side", type=int, default=1280,
help="detector's long-side cap in px (dense small print auto-scales to 2400)")
a = ap.parse_args(argv)
from . import SumoOCR
ocr = SumoOCR(backend=a.backend, threads=a.threads, max_side=a.max_side)
for path in a.images:
lines = ocr(path)
if a.format == "json":
print(json.dumps({"image": path, "lines": [ln.to_dict() for ln in lines]}, ensure_ascii=False))
else:
if len(a.images) > 1:
print(f"==> {path} <==")
print("\n".join(ln.text for ln in lines))
return 0
if __name__ == "__main__":
sys.exit(main())
|