Files
pricing_review/AdminCost/参考资料/规范与COS4/scripts/ocr_all.py

34 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""批量 OCR:PDF 52-146(第6章),逐页增量落盘,可断点续跑"""
import os, json, sys, time
sys.path.insert(0, r"C:\Users\MZ\AppData\Local\Temp\cos4std")
from ocr_page import ocr_page, BASE
OUT = os.path.join(BASE, "ocr_ch6.json")
START, END = 52, 146
data = {}
if os.path.exists(OUT):
try:
data = json.load(open(OUT, encoding="utf-8"))
print("resume, have", len(data))
except Exception:
data = {}
t0 = time.time()
for n in range(START, END + 1):
key = "p%03d" % n
if key in data and data[key]:
continue
try:
data[key] = ocr_page(n)
print("%s ok items=%d %.0fs" % (key, len(data[key]), time.time() - t0), flush=True)
except Exception as e:
print("%s FAIL %s" % (key, e), flush=True)
data[key] = []
if n % 5 == 0:
json.dump(data, open(OUT, "w", encoding="utf-8"), ensure_ascii=False)
json.dump(data, open(OUT, "w", encoding="utf-8"), ensure_ascii=False)
print("done", len(data), "%.0fs" % (time.time() - t0))