Java-SDK-图像识别实现身份证照片获取信息

开发准备

SDK获取

万象优图的 java SDK 下载地址:image-java-sdk-v2.0

简介

java sdk for picture service of tencentyun.

快速入门

在腾讯云申请业务的授权

授权包括:APPID,SecretId,SecretKey,以及存储桶名。可参考 域名管理

 1 创建对应操作类的对象
 2 
 3 如果要使用图片,需要创建图片操作类对象
 4 
 5 ImageClient imageClient = new ImageClient(APP_ID, SECRET_ID, SECRET_KEY);
 6 String bucketName = BUCKET;
 7 调用对应的方法
 8 
 9 在创建完对象后,根据实际需求,调用对应的操作方法就可以了。sdk 提供的方法包括:图片识别、人脸识别及人脸核身等。
10 
11 图片识别
12 
13 图片识别包括:图片鉴黄、图片标签、OCR - 身份证识别及 OCR - 名片识别。
14 
15 OCR - 身份证识别
16 
17 // 1. url方式,识别身份证正面
18 String[] idcardUrlList = new String[2];
19 idcardUrlList[0] = "http://imgs.focus.cn/upload/sz/5876/a_58758051.jpg";
20 idcardUrlList[1] = "http://img5.iqilu.com/c/u/2013/0530/1369896921237.jpg";
21 IdcardDetectRequest idReq = new IdcardDetectRequest(bucketName, idcardUrlList, 0); 
22 ret = imageClient.idcardDetect(idReq);
23 System.out.println("idcard detect ret:" + ret);
24 //识别身份证反面
25 idcardUrlList[0] = "http://www.csx.gov.cn/cwfw/bszn/201403/W020121030349825312574.jpg";
26 idcardUrlList[1] = "http://www.4009951551.com/upload/image/20151026/1445831136187479.png";
27 idReq = new IdcardDetectRequest(bucketName, idcardUrlList, 1);   
28 ret = imageClient.idcardDetect(idReq);
29 System.out.println("idcard detect ret:" + ret);
30 //2. 图片内容方式,识别身份证正面
31 String[] idcardNameList = new String[2];
32 String[] idcardImageList = new String[2];
33 try {
34     idcardNameList[0] = "id6_zheng.jpg";
35     idcardImageList[0] = CommonFileUtils.getFileContent("F:picid6_zheng.jpg");
36     idcardNameList[1] = "id2_zheng.jpg";
37     idcardImageList[1] = CommonFileUtils.getFileContent("F:picid2_zheng.jpg");
38     } catch (Exception ex) {
39    Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
40     }
41 idReq = new IdcardDetectRequest(bucketName, idcardNameList, idcardImageList, 0);
42 ret = imageClient.idcardDetect(idReq);
43 System.out.println("idcard detect ret:" + ret);
44 //识别身份证反面
45 try {
46     idcardNameList[0] = "id5_fan.png";
47     idcardImageList[0] = CommonFileUtils.getFileContent("F:picid5_fan.jpg");
48     idcardNameList[1] = "id7_fan.jpg";
49     idcardImageList[1] = CommonFileUtils.getFileContent("F:picid7_fan.png");
50     } catch (Exception ex) {
51    Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
52     }
53 idReq = new IdcardDetectRequest(bucketName, idcardNameList, idcardImageList, 1);
54 ret = imageClient.idcardDetect(idReq);
55 System.out.println("idcard detect ret:" + ret);
56 Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
57     }
58 idReq = new IdcardDetectRequest(bucketName, idcardNameList, idcardImageList, 1);
59 ret = imageClient.idcardDetect(idReq);
60 System.out.println("idcard detect ret:" + ret);

经验:下载完sdk后,在demo中,找到自己要使用的方法,调用即可!

原文地址:https://www.cnblogs.com/baorantHome/p/8124929.html