自动分类证件
发送证件图像时无需声明 template。OCR 会识别证件的类型和正反面,核对其是否在 allowed_templates 列表中,然后执行与指定模板发送相同的校验和数据提取。
当用户可能提交多种证件(例如 CNH 或 RG),而您不希望在拍摄前让用户先选择证件类型时,请使用此方式。
Endpoint
ENDPOINT
/image方法
POST状态
200此 endpoint 与指定模板发送时使用的 endpoint 相同,行为由请求体决定:发送 allowed_templates 代替 template。两个字段互斥——同时发送或都不发送,均返回 400。
身份验证
在 Authorization 请求头中发送 API key。参见简介中的“身份验证”一节。
请求体
| 字段 | 类型 | 必填 | 说明 | 大小 |
|---|---|---|---|---|
document_b64 | string | 是 | base64 编码的证件文件。JPEG,或仅一页的 PDF。 | 3 MB(JPEG),30 MB(PDF) |
allowed_templates | string[] | 是 | 您接受的证件类型。取值见允许的模板表。 | — |
{
"document_b64": "YOUR_BASE64_DOCUMENT",
"allowed_templates": ["cnh", "rg"]
}
import requests
response = requests.post(
"https://api.caas.qitech.app/ocr/image",
headers={"Authorization": "YOUR_API_KEY"},
json={
"document_b64": "YOUR_BASE64_DOCUMENT",
"allowed_templates": ["cnh", "rg"],
},
)
print(response.status_code, response.json())