Files
37duAutomation/libs/desktopauto/desktopauto/cardocr/cli.py
T
puddy 3fab00ad92 feat(sdk): hr_sdk 0.2.4 工资卡导入、desktopauto 0.5.0 证件照识别、新增插件 XQ0084
- hr_sdk.wage_import:DrissionPage 注入 cookie 打开 HR 门户,页面内 WS 订阅 + fetch 上传,解析 over: 结果;build_xlsx 第 9 列卡号强制数值(修复「卡号必须是数字」)

- 纯 HTTP 导入不可用:服务端异步任务与浏览器会话强绑定,且前端无轮询接口(已核实),结果通道只能用浏览器上下文

- desktopauto 0.5.0 新增 cardocr:身份证/银行卡 OCR、号码纠错、Luhn 与模 11-2 校验、交叉核对

- 新增插件 XQ0084 银行卡更新EHR系统:AI 表格待处理行 → 影像识别 → 一致性核对/异常名单

- .gitignore 忽略 tests/aitable_probe/_out/(含员工证件照,禁止入库)
2026-11-17 17:48:37 +08:00

111 lines
4.7 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 -*-
"""命令行:scan / image / review / verify"""
from __future__ import annotations
import argparse
import json
import logging
import sys
from pathlib import Path
from .match import check_persons, print_report
from .pipeline import analyze_folder, analyze_image, summary_table
from .review import (load_persons, load_truth_workbook, print_verify, verify_workbook,
write_review_workbook)
def _setup_stdout() -> None:
try:
sys.stdout.reconfigure(encoding="utf-8")
except Exception: # noqa: BLE001
pass
def main(argv=None) -> int:
_setup_stdout()
logging.basicConfig(level=logging.INFO, format="%(message)s", stream=sys.stdout)
ap = argparse.ArgumentParser(prog="cardocr", description="身份证 / 银行卡照片识别")
sub = ap.add_subparsers(dest="cmd", required=True)
def common(sp):
sp.add_argument("--json", default="", help="结果写入 JSON 文件")
sp.add_argument("--xlsx", default="", help="结果写成核对工作簿(含待填列)")
sp.add_argument("--mark", default="", help="标注图输出目录")
sp.add_argument("--no-extra", action="store_true", help="关闭卡号多遍增强识别(更快)")
sp.add_argument("--fast", action="store_true", help="只跑粗识别(最快,精度下降)")
sp.add_argument("--limit", type=int, default=0, help="每个目录最多取几张图(0=全部)")
sp_scan = sub.add_parser("scan", help="按「姓名/图片」目录批量识别")
sp_scan.add_argument("root", help="照片根目录")
common(sp_scan)
sp_one = sub.add_parser("image", help="识别单张图片")
sp_one.add_argument("path", help="图片路径")
sp_one.add_argument("--name", default="", help="预期姓名(用于校验身份证姓名)")
common(sp_one)
sp_rev = sub.add_parser("review", help="把 JSON 结果导出成核对工作簿")
sp_rev.add_argument("--json", required=True, help="scan 输出的 JSON")
sp_rev.add_argument("--out", required=True, help="输出的 xlsx 路径")
sp_ver = sub.add_parser("verify", help="回读填好的核对工作簿,算准确率")
sp_ver.add_argument("xlsx", help="核对工作簿路径")
sp_chk = sub.add_parser("check", help="用人工填写的正确值做「命中分析」")
sp_chk.add_argument("--json", required=True, help="scan 输出的 JSON")
sp_chk.add_argument("--truth", required=True, help="填好的核对工作簿 xlsx")
sp_chk.add_argument("--out", default="", help="命中分析结果写入 JSON")
args = ap.parse_args(argv)
if args.cmd == "scan":
persons = analyze_folder(args.root, mark_dir=args.mark or None,
extra_passes=not args.no_extra, fast=args.fast,
limit=args.limit)
print(summary_table(persons))
payload = {"root": str(Path(args.root).resolve()), "persons": persons}
if args.json:
Path(args.json).parent.mkdir(parents=True, exist_ok=True)
Path(args.json).write_text(json.dumps(payload, ensure_ascii=False, indent=1),
encoding="utf-8")
print(f"\n已写入 {args.json}")
if args.xlsx:
write_review_workbook(persons, args.xlsx, source_root=payload["root"])
print(f"\n核对工作簿已写入 {args.xlsx}")
return 0
if args.cmd == "image":
res = analyze_image(args.path, expected_name=args.name, mark_dir=args.mark or None,
extra_passes=not args.no_extra, fast=args.fast)
print(json.dumps(res, ensure_ascii=False, indent=1))
if args.json:
Path(args.json).parent.mkdir(parents=True, exist_ok=True)
Path(args.json).write_text(json.dumps({"images": [res]}, ensure_ascii=False,
indent=1), encoding="utf-8")
return 0
if args.cmd == "review":
persons = load_persons(args.json)
write_review_workbook(persons, args.out)
print(f"核对工作簿已写入 {args.out}({len(persons)} 行)")
return 0
if args.cmd == "check":
persons = load_persons(args.json)
truth = load_truth_workbook(args.truth)
rows = check_persons(persons, truth)
print(print_report(rows))
if args.out:
Path(args.out).write_text(json.dumps(rows, ensure_ascii=False, indent=1),
encoding="utf-8")
print(f"\n命中分析已写入 {args.out}")
return 0
result = verify_workbook(args.xlsx)
print_verify(result)
return 0
if __name__ == "__main__":
raise SystemExit(main())