700
阿里云
身份证识别__API介绍_文字识别_人工智能图像类-阿里云
本页面主要介绍服务对应的接口和返回结果中的关键字段的含义,请在阅读本页面之前,了解请求数据格式介绍,了解输入输出的通用数据格式。 此外,在本页最后,附上了身份证服务调用的程序示例,以供参考。
请求接口
云市场接口
- 请求方法: POST
- 请求url: 在云市场搜索
印刷文字识别-身份证识别,在API接口中找到调用地址
数加接口
- 请求方法: POST
- 请求url: 打开管理控制台,接口名称选择
ocr_idcard,查看请求地址
请求参数
| 参数名称 | 参数类型 | 描述 | 默认值 |
|---|---|---|---|
| image | string | dataType为50, dataValue是base64编码后的图像数据 | 空字符串 |
| configure | string | dataType为50, dataValue是json字符串,其中的具体参数字段参考后面 | 空字符串 |
configure 参数的具体字段如下:
| 参数名称 | 参数类型 | 描述 | 默认值 |
|---|---|---|---|
| side | string | 表示上传图片是身份证正面/反面图像, “face” 表示正面,”back”表示反面 | 无 |
请求参数的POST请求body如下:
{"inputs": [{"image": {"dataType": 50, #50表示image的数据类型为字符串"dataValue": "base64_image_string" #图片以base64编码的string},"configure": {"dataType": 50,"dataValue": "{"side": "face" #身份证正反面类型: face/back}"}}]}
返回结果格式
返回结果分为正面和反面两种格式,正面返回结果格式如下:
{"outputs": [{"outputLabel": "ocr_id","outputMulti": {},"outputValue": {"dataType": 50,"dataValue": "{"address" : "浙江省杭州市余杭区文一西路969号", #地址信息"config_str" : "{\"side\":\"face\"}", #配置信息,同输入configure"name" : "张三", #姓名"num" : "1234567890", #身份证号"sex" : "男", #性别"birth" : "20000101", #出生日期"nationality" : "汉", #民族"success" : true #识别结果,true表示成功,false表示失败}"}}]}
每一个请求返回的结果都是一个json字符串,由dataValue关键词可以索引到,主要有7个字段:
- address: 识别的地址信息, 类型为字符串
- config_str: 表示发送请求时候的配置字符串,为json字符串格式,表示输入时候的配置参数, 类型为字符串
- name: 识别的身份证姓名, 类型为字符串
- num: 识别的身份证号码, 类型为字符串
- sex: 识别的性别, 类型为字符串
- birth: 识别的出生日期, 类型为字符串
- nationality : 识别的民族, 类型为字符串
- success: 识别流程是否出现异常, false表示识别失败,true表示识别成功, 类型为布尔型
反面输出结果格式如下:
{"outputs": [{"outputLabel": "ocr_id","outputMulti": {},"outputValue": {"dataType": 50,"dataValue": "{"config_str" :"{\"side\":\"back\"}",#配置信息,同输入configure"start_date" : "19700101", #有效期起始时间"end_date" : "19800101", #有效期结束时间"issue" : "杭州市公安局", #签发机关"success" : true #识别结果,true表示成功,false表示失败}"}}]}
每个返回结果同样存储在以dataValue为关键词所对应的键值对中,其中有5个字段:
- config_str: 和正面字段含义一样, 类型为字符串
- issue: 身份证签发机关,类型为字符串
- start_date: 身份证有效期起始时间,类型为字符串
- end_date: 身份证有效期结束时间,类型为字符串
- success: 识别流程是否成功,类型为布尔型
程序示例
云市场
在云市场搜索印刷文字识别-身份证识别,在API接口中找到请求示例
数加平台
import java.io.File;import java.io.FileInputStream;import java.io.IOException;import org.apache.commons.codec.binary.Base64;import org.json.JSONObject;import org.json.JSONArray;import org.json.JSONException;public class IDcard {/** 获取参数的json对象*/public static JSONObject getParam(int type, JSONObject dataValue) {JSONObject obj = new JSONObject();try {obj.put("dataType", type);obj.put("dataValue", dataValue);} catch (JSONException e) {e.printStackTrace();}return obj;}/** 获取参数的json对象*/public static JSONObject getParam(int type, String dataValue) {JSONObject obj = new JSONObject();try {obj.put("dataType", type);obj.put("dataValue", dataValue);} catch (JSONException e) {e.printStackTrace();}return obj;}public static void main(String[] args) {String imgFile = "idcard.jpg";String serviceURL = "your-service-url";String akID = "your access key id";String akSecret = "your access key secret";// 对图像进行base64编码String imgBase64 = "";try {File file = new File(imgFile);byte[] content = new byte[(int) file.length()];FileInputStream finputstream = new FileInputStream(file);finputstream.read(content);finputstream.close();imgBase64 = new String(Base64.encodeBase64(content));} catch (IOException e) {e.printStackTrace();return;}// 拼装请求body的json字符串JSONObject requestObj = new JSONObject();try {JSONObject configObj = new JSONObject();JSONObject obj = new JSONObject();JSONArray inputArray = new JSONArray();configObj.put("side", configStr);obj.put("image", getParam(50, imgBase64));obj.put("configure", getParam(50, configObj.toString()));inputArray.put(obj);requestObj.put("inputs", inputArray);} catch (JSONException e) {e.printStackTrace();}String body = requestObj.toString();//Sender代码参考 https://help.aliyun.com/document_detail/shujia/OCR/ocr-api/sender.htmlString result = Sender.sendPost(serviceURL, body, akID, akSecret);System.out.println(result);// 解析请求结果try {JSONObject resultObj = new JSONObject(result);JSONArray outputArray = resultObj.getJSONArray("outputs");String output = outputArray.getJSONObject(0).getJSONObject("outputValue").getString("dataValue"); // 取出结果json字符串JSONObject out = new JSONObject(output);if (out.getBoolean("success")) {String addr = out.getString("address"); // 获取地址String name = out.getString("name"); // 获取名字String num = out.getString("num"); // 获取身份证号System.out.printf(" name : %s n num : %sn address : %sn", name, num, addr);} else {System.out.println("predict error");}} catch (JSONException e) {e.printStackTrace();}}}
最后更新:2016-11-24 11:23:48
上一篇:
数据格式__API介绍_文字识别_人工智能图像类-阿里云
下一篇:
驾驶证识别__API介绍_文字识别_人工智能图像类-阿里云
已经授权子用户管理某个负载均衡器的权限,但是在均衡器实例中添加/移除ECS服务器以及设置权重时提示没有权限___负载均衡(SLB)授权问题_授权常见问题_访问控制-阿里云
设置解析记录时提示冲突的原因__网站解析_产品使用问题_云解析-阿里云
RAM支持的ActionTrail操作和资源__控制用户的访问权限_用户指南_操作审计-阿里云
如何获取真实来源IP__常见问题_负载均衡-阿里云
查询RDS地域和可用区信息__实例管理_API 参考_云数据库 RDS 版-阿里云
搜索集群__集群管理_用户指南_容器服务-阿里云
遍历全表操作__开发手册_分布式关系型数据库 DRDS-阿里云
阿里云发布新物种神龙云服务器 媲美物理机性能的弹性云服务器
阿里云发布Link物联网平台
跨阿里云账号RDS实时同步__实时同步_用户指南_数据传输-阿里云
相关内容
常见错误说明__附录_大数据计算服务-阿里云
发送短信接口__API使用手册_短信服务-阿里云
接口文档__Android_安全组件教程_移动安全-阿里云
运营商错误码(联通)__常见问题_短信服务-阿里云
设置短信模板__使用手册_短信服务-阿里云
OSS 权限问题及排查__常见错误及排除_最佳实践_对象存储 OSS-阿里云
消息通知__操作指南_批量计算-阿里云
设备端快速接入(MQTT)__快速开始_阿里云物联网套件-阿里云
查询API调用流量数据__API管理相关接口_API_API 网关-阿里云
使用STS访问__JavaScript-SDK_SDK 参考_对象存储 OSS-阿里云