回覆列表
  • 1 # 程式設計師米兜
    二、用途

    對於企業來說,拿到你的身份證,無非就是身份證OCR(文字識別)一下,就是識別出你的身份證正反面的資訊,然後校驗以下幾種情況:

    註冊身份的真實性;身份證是否過期;年齡是否滿足註冊條件;性別校驗;...

    以上資訊是否都校驗是基於這款產品的目的用途。一般APP基本都是拿到姓名、身份證號校驗註冊身份的真實性即可。

    除上以外,會儲存你的身份證照片,這個雖然儲存在企業伺服器上了,但是一般都是授權訪問的,如有疑問,問題排查所用。企業員工都是基於法律簽訂合同的,如果真有企業或者員工做非法的事情,那就是違犯,等待相關機關處理。

    三、技術實現

    一般身份證OCR實現,都是藉助第三方介面實現,目前大部分都是採用百度實現。實現方式如下:

    1.獲取百度身份證文字識別金鑰,登入https://console.bce.baidu.com/ai/?fromai=1#/ai/ocr/overview/index,拿到APP_ID、API_KEY、SECRET_KEY即可。

    2.maven配置

    3.controller實現

    package com.midou.idcardocr.controller;import com.baidu.aip.ocr.AipOcr;import com.midou.idcardocr.util.ImageUtil;import org.json.JSONObject;import java.util.HashMap;/** * @author 米兜 * @description * @date 2020/6/28 8:17 * @modified by */public class HelloWorld {//申請的[https://console.bce.baidu.com/ai/?fromai=1#/ai/ocr/overview/index] public static final String APP_ID = "20621426";public static final String API_KEY = "01IBzVivzwkwdQMS9B4ScdDt";public static final String SECRET_KEY = "RvIYakSHRgZrNnOIDXObitl2FOEQdtUo";public static void main(String[] args) {AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);// 傳入可選引數呼叫介面 HashMap<String, String> options = new HashMap<String, String>();options.put("detect_direction", "true");options.put("detect_risk", "false");//身份證背面照 //String idCardSide = "back"; //身份證正面照 String idCardSide = "front";// 引數為本地圖片路徑 //String image = "D:\\back.jpg"; String image = "D:\\front.jpg";JSONObject res = client.idcard(image, idCardSide, options);System.out.println(res.toString(2));// 引數為本地圖片轉二進位制 byte[] file = ImageUtil.readImageFile(image);res = client.idcard(file, idCardSide, options);System.out.println(res.toString(2));}}

    4.上面涉及一個本地圖片轉二進位制package com.midou.idcardocr.util;import javax.imageio.stream.FileImageInputStream;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;/** * @author 米兜 * @description * @date 2020/6/28 8:24 * @modified by */public class ImageUtil {/** * 將影象轉為二進位制陣列 * * @param path * @return */ public static byte[] readImageFile(String path) {byte[] data = null;FileImageInputStream input = null;try {input = new FileImageInputStream(new File(path));ByteArrayOutputStream output = new ByteArrayOutputStream();byte[] buf = new byte[1024];int numBytesRead = 0;while ((numBytesRead = input.read(buf)) != -1) {output.write(buf, 0, numBytesRead);}data = output.toByteArray();output.close();input.close();} catch (FileNotFoundException ex1) {ex1.printStackTrace();} catch (IOException ex1) {ex1.printStackTrace();}return data;}}

    四、執行結果

    0 [main] INFO com.baidu.aip.client.BaseClient - get access_token success. current state: STATE_AIP_AUTH_OK

    2 [main] DEBUG com.baidu.aip.client.BaseClient - current state after check priviledge: STATE_TRUE_AIP_USER

    {

    "log_id": 3010258785723740188,

    "words_result": {

    "姓名": {

    "words": "欒韶東",

    "location": {

    "top": 40,

    "left": 89,

    "width": 51,

    "height": 19

    }

    },

    "民族": {

    "words": "回",

    "location": {

    "top": 76,

    "left": 168,

    "width": 12,

    "height": 14

    }

    },

    "住址": {

    "words": "廣東省深圳市福田區筍崗西路3002號",

    "location": {

    "top": 140,

    "left": 85,

    "width": 166,

    "height": 37

    }

    },

    "公民身份號碼": {

    "words": "",

    "location": {

    "top": 0,

    "left": 0,

    "width": 0,

    "height": 0

    }

    },

    "出生": {

    "words": "19680909",

    "location": {

    "top": 107,

    "left": 86,

    "width": 131,

    "height": 14

    }

    },

    "性別": {

    "words": "男",

    "location": {

    "top": 76,

    "left": 89,

    "width": 10,

    "height": 15

    }

    }

    },

    "words_result_num": 6,

    "idcard_number_type": 0,

    "image_status": "unknown",

    "direction": 0

    }

    {

    "log_id": 2919714179777122876,

    "words_result": {

    "姓名": {

    "words": "欒韶東",

    "location": {

    "top": 40,

    "left": 89,

    "width": 51,

    "height": 19

    }

    },

    "民族": {

    "words": "回",

    "location": {

    "top": 76,

    "left": 168,

    "width": 12,

    "height": 14

    }

    },

    "住址": {

    "words": "廣東省深圳市福田區筍崗西路3002號",

    "location": {

    "top": 140,

    "left": 85,

    "width": 166,

    "height": 37

    }

    },

    "公民身份號碼": {

    "words": "",

    "location": {

    "top": 0,

    "left": 0,

    "width": 0,

    "height": 0

    }

    },

    "出生": {

    "words": "19680909",

    "location": {

    "top": 107,

    "left": 86,

    "width": 131,

    "height": 14

    }

    },

    "性別": {

    "words": "男",

    "location": {

    "top": 76,

    "left": 89,

    "width": 10,

    "height": 15

    }

    }

    },

    "words_result_num": 6,

    "idcard_number_type": 0,

    "image_status": "unknown",

    "direction": 0

    }

    Process finished with exit code 0

    五、總結

    上面是基於程式設計師角度分析身份證資訊問題,如有不對,請多多包涵。

  • 中秋節和大豐收的關聯?
  • 為什麼現在年輕人閒著也不打工?還總想著創業掙大錢?