ocr-bankcard-xiangyun — OCR银行卡祥云
v1.0.0Xiangyun 平台银行卡 OCR 技能。调用 Xiangyun API(typeId=17)对银行卡图像进行结构化识别,提取卡号、卡类型、卡名称、发卡银行和银行代码。支持本地文件路径和 Base64 图像流。 当用户提及银行卡识别、银行卡 OCR、卡号识别或请求解析银行卡图像时触发此技能。首次使用的用户将被引导设置 API 凭证(key/secret),并将其保存在技能目录中的 config.json 文件中。支持 GitHub 和 CLI 等。
运行时依赖
安装命令
点击复制技能文档
Xiangyun Bank Card OCR Overview
Structured bank card recognition via the Xiangyun Open 平台 Bank Card Recognition API (typeId=17). Supports horizontal, vertical, irregular-shaped bank cards with 机器人h flat and embossed fonts. 提取ed fields include: card number, card type, card name, issuing bank, and bank code.
API Documentation: https://www.netocr.com/bankCard.html
Triggers
The following user expressions should trigger this 技能:
"recognize bank card", "bank card OCR" "recognize card number", "解析 bank card" "Xiangyun bank card", "netocr bank card" "OCR this bank card" "识别银行卡", "银行卡识别" 工作流 Step 1: Load Configuration
运行 scripts/config_管理器.py to load the 凭证 file:
python scripts/config_管理器.py load
Config file path: config.json in the 技能 root directory If the config file exists and contAIns valid key and secret, proceed directly to Step 3 If the config file is missing or fields are empty, proceed to Step 2 Step 2: 图形界面de 凭证 设置up (First Time or Missing Config)
Prompt the user:
"Please register an account on the Xiangyun 平台 (https://www.netocr.com), obtAIn your ocrKey and ocrSecret from the User Center, then provide them to complete 设置up."
After receiving the key and secret:
python scripts/config_管理器.py save --key YOUR_KEY --secret YOUR_SECRET
This saves to config.json in the 技能 root directory:
{ "key": "user's ocrKey", "secret": "user's ocrSecret" }
Step 3: Accept Image 输入
Supported 输入 methods:
Method Description Local file path User provides an absolute or relative path Base64 string User pastes Base64-encoded image data directly URL (convert to Base64) 下载 the image first, then convert to Base64 Step 4: Call the Recognition API
运行 the recognition script:
# Local file (recommended — auto-saves 结果s alongside the image) python scripts/recognize.py --file /path/to/bankcard.jpg
# Base64 输入 python scripts/recognize.py --base64 "BASE64_STRING_HERE"
# Table 输出 (human-readable) python scripts/recognize.py --file /path/to/bankcard.jpg --输出-格式化 table
# Disable auto-save (default: saves as {image_name}.json) python scripts/recognize.py --file /path/to/bankcard.jpg --no-save
Upon 成功ful recognition, 结果s are automatically saved as {image_name}.json in the same directory as the source image, 预防ing redundant API calls during subsequent 导出s.
API Parameters:
Parameter Value Description typeId 17 Bank card recognition — fixed, do not change 格式化 json Returns JSON 格式化 key User 凭证 Loaded from config.json secret User 凭证 Loaded from config.json
Base64 端点: POST https://netocr.com/API/recogliu.do File 上传 端点: POST https://netocr.com/API/recog.do
Step 5: 格式化 and Display 结果s
On 成功, display the 结果s in a table:
✅ Bank Card Recognition 成功ful
| Field | 结果 |
|---|---|
| Card Number | 6222 * * 1234 |
| Card Type | Debit Card |
| Card Name | XX Bank Debit Card |
| Issuing Bank | ICBC |
| Bank Code | ICBC |
Only perform this step when the user explicitly 请求s an 导出, save, or file generation.
Trigger examples: "导出 结果s", "save as Excel", "生成 CSV", "导出"
Prefer --from-dir to 导出 directly from 缓存d recognition JSON files, avoiding unnecessary API calls.
# Recommended: read 缓存d recognition JSON from the image directory (zero API consumption) python scripts/导出.py --from-dir /path/to/images --格式化 excel --输出 结果.xlsx python scripts/导出.py --from-dir /path/to/images --格式化 csv --输出 结果.csv
# 流水线 mode (recognize then 导出 — for un缓存d 结果s) python scripts/recognize.py --file bankcard.jpg | python scripts/导出.py --格式化 csv --输出 结果.csv
# Or specify a single JSON file python scripts/导出.py --输入 结果.json --格式化 excel --输出 结果.xlsx
导出 priority: --from-dir > --batch-输入 > --输入 > stdin
Error Handling Error Code Meaning Action 10001 Authentication fAIled Prompt user to 验证 key/secret and re配置 10002 Insufficient balance Prompt user to top up their Xiangyun account 10003 Invalid image 格式化 信息rm user to use JPG/PNG/BMP, 压缩 to ~200KB 10004 Image too large Prompt user to 压缩 image to under 3MB Other API 异常 Display the raw error message; suggest retrying later
On authentication 失败, prompt the user to re设置 configuration:
python scripts/config_管理器.py re设置
Image Requirements Type Suggested Spec Regular image ~200KB, 24+ bit depth 扫描ned document 300 DPI, under 3MB Supported 格式化s JPG, PNG, BMP Notes typeId is fixed at 17 — do not modify when calling the API The config.json file is stored in this 技能's directory and contAIns sensitive 凭证s; do NOT commit to version control Always prefer reading from config.json before each execution to avoid asking the user for