使用阿里云身份证扫描识别接口案例——CSDN博客
2023-09-14 08:57:40 时间
/** * * @Title: idcard * @Description: 该方法的主要作用:扫描身份证 * @param @return 设定文件 * @return 返回类型:String * @throws */ public void idcard(){ String host = "https://dm-51.data.aliyun.com"; String path = "/rest/160601/ocr/ocr_idcard.json"; String method = "POST"; Map<String, String> headers = new HashMap<String, String>(); headers.put("Authorization", "APPCODE " + appcode); headers.put("Content-Type", "application/json; charset=UTF-8"); Map<String, String> querys = new HashMap<String, String>(); String bodys = "{\"inputs\": [{\"image\": {\"dataType\": 50,\"dataValue\":\""+img+"\"},\"configure\": {\"dataType\": 50,\"dataValue\":\"{\\\"side\\\":\\\"face\\\"}\"}}]}"; try { HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys); //System.out.println(EntityUtils.toString(response.getEntity())); String result = EntityUtils.toString(response.getEntity()); System.out.println(result); JSONObject jObject = JSONObject.fromObject(result); JSONArray jarray = jObject.optJSONArray("outputs"); for (int i = 0; i < jarray.size(); i++) { JSONObject subject = jarray.getJSONObject(i); String outputValue = subject.get("outputValue").toString(); /*outputValue={ "dataType": 50, "dataValue": { "address": "山西省xxxx041", "birth": "19980908", "config_str": "{\"side\":\"face\"}", "face_rect": { "angle": -90, "center": { "x": 446, "y": 210 }, "size": { "height": 92, "width": 84 } }, "name": "xxx", "nationality": "汉", "num": "1411251998xxxxxxX", "request_id": "20170806200141_c5338b2c4fd601ea7f00c4dcc5c8ee0e", "sex": "男", "success": true } }*/ JSONObject j_outputValue = JSONObject.fromObject(outputValue); String dataValue = j_outputValue.getString("dataValue"); JSONObject j_dataValue = JSONObject.fromObject(dataValue); customerInfo = new CustomerInfo(); customerInfo.setName(j_dataValue.getString("name").toString()); //姓名 String date = j_dataValue.getString("birth").toString(); customerInfo.setBorn(date); SimpleDateFormat format = new SimpleDateFormat(date); Date birth = format.parse(date); customerInfo.setBirth(birth);//生日 customerInfo.setAddress(j_dataValue.getString("address").toString()); customerInfo.setNationality(j_dataValue.getString("nationality").toString()); customerInfo.setNum(j_dataValue.getString("num").toString()); customerInfo.setSex(j_dataValue.getString("sex").toString()); } System.out.println(customerInfo.getName()); String jsonc = JSON.toJSONString(customerInfo); HttpServletResponse response1 = ServletActionContext.getResponse(); response1.setContentType("text/html;charset=utf-8"); PrintWriter out = response1.getWriter(); out.print(jsonc); } catch (Exception e) { e.printStackTrace(); } }
相关文章
- 【立即报名】人脸情绪识别案例分享
- 学习索引结构的一些案例——Jeff Dean在SystemML会议上发布的论文(中)
- 案例分析|如何消除代码坏味道
- C#中的序列化和反序列化案例
- 使用阿里云身份证扫描识别接口案例——CSDN博客
- 记录一次JVM配置优化的案例
- SPSS统计分析案例:无空白列重复正交试验设计方差分析
- 7.1.3 TimePicker结合案例详解
- Freemarker 页面静态化技术使用入门案例
- CV之FR:基于paddlehub 框架利用mobile_mask人工智能算法实现人脸口罩图像识别(二分类识别,可结合无人机可,实现实时检测实时警告提醒)案例应用
- DL之DNN:基于Tensorflow框架对神经网络算法进行参数初始化的常用九大函数及其使用案例
- Python语言学习:利用python获取当前/上级/上上级目录路径(获取路径下的最后叶目录的文件名、合并两个不同路径下图片文件名等目录/路径案例、正确加载图片路径)之详细攻略
- Python之sklearn:LabelEncoder函数简介(编码与编码还原)、使用方法、具体案例(在数据缺失和test数据内存在新值(train数据未出现过)环境下的数据LE化)之详细攻略
- TF之DNN:利用DNN【784→500→10】对MNIST手写数字图片识别数据集(TF自带函数下载)预测(98%)+案例理解DNN过程
- 豆瓣点评9.3分,10w好评的《python实战案例80个实例问答》,28天基础入门,学不会我退出IT界
- Android 代码重构案例
- y49.第三章 Kubernetes从入门到精通 -- k8s实战案例(二二)
- 通过Oracle识别字符串中的中文or字母or数字来介绍全角半角转换函数(to_multi_byte/to_single_byte)在varchar/clob中的使用案例
- 测试用例设计——案例详解
- Microsoft SDK 中Sample案例之Amcap項目 的运行方法(转)
- 数据分析案例-航空公司客户价值分析(聚类)
- Keras之TCN:基于keras框架利用时间卷积网络TCN算法对上海最高气温实现回归预测(把时间序列数据集转化为有监督学习数据集)案例
- QT案例实战1 - 从零开始编写一个OCR工具软件 (8) Pdf读取展示/截图/文字识别
- QT案例实战1 - 从零开始编写一个OCR工具软件 (7) 屏幕截图/图像展示/文字识别
- python使用技巧(三十二):将整个list都是数值的字符串转为正常的数值list--->案例:str = “[1,2,3,5,7,10]“
- 史上最全的2022年最新版软件测试面试题集锦(含答案+案例分析)【二】,再战金九银十