Java-SDK-圖像識別實現身份證照片獲取信息

開發準備

SDK獲取

萬象優圖的 java SDK 下載地址:image-java-sdk-v2.0java

簡介

java sdk for picture service of tencentyun.git

快速入門

在騰訊雲申請業務的受權

受權包括:APPID,SecretId,SecretKey,以及存儲桶名。可參考 域名管理github

 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:\pic\id6_zheng.jpg");
36     idcardNameList[1] = "id2_zheng.jpg";
37     idcardImageList[1] = CommonFileUtils.getFileContent("F:\pic\id2_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:\pic\id5_fan.jpg");
48     idcardNameList[1] = "id7_fan.jpg";
49     idcardImageList[1] = CommonFileUtils.getFileContent("F:\pic\id7_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中,找到本身要使用的方法,調用便可!url

相關文章
相關標籤/搜索