百度雲API刷臉

  • 刷臉登錄是基於人工智能、生物識別、3D傳感、大數據風控技術,最新實現的登錄形式。用戶在無需輸入用戶名
    密碼的前提下,憑藉“刷臉”完成登錄過程。實現刷臉登錄的核心是人臉處理,在人臉處理中有兩個概念:
    • 人臉檢測:檢測圖中的人臉,併爲人臉標記出邊框。檢測出人臉後,可對人臉進行分析,獲得眼、口、鼻輪
      廓等72個關鍵點定位準確識別多種人臉屬性,如性別,年齡,表情等信息
    • 人臉識別(對比):通過提取人臉的特徵,計算兩張人臉的相似度,從而判斷是否同一個人,並給出相似度
      評分
  • 註冊:
    • 註冊百度雲帳號
      打開百度雲平臺:https://login.bce.baidu.com/reg.html?tpl=bceplat&from=portal進行賬號註冊
    • 記住:    AppID,API Key,Secret Key
  • 環境搭建
    • <dependency>
          <groupId>com.baidu.aip</groupId>
          <artifactId>java-sdk</artifactId>
          <version>4.8.0</version>
      </dependency>
    • 人臉註冊:
      •  //人臉註冊
            @Test
            public void testFaceRegister() throws Exception {
                //傳入可選參數調用接口
                HashMap<String, String> options = new HashMap<String, String>();
                options.put("quality_control", "NORMAL"); //圖片質量控制
                options.put("liveness_control", "LOW"); //活體檢測控制
                String imageType = "BASE64";
                String groupId = "groupId ";
                String userId = "userId ";
                 //構造base64圖片字符串
                String path = "C:\\Users\\001.png";
                byte[] bytes = Files.readAllBytes(Paths.get(path));
                String image = Base64Util.encode(bytes);
                // 人臉註冊
                JSONObject result = client.addUser(image, imageType, groupId, userId, options);
           }
      • 人臉註冊 請求參數詳情

        • image:圖片信息(總數據大小應小於10M),圖片上傳方式根據image_type來判斷

        • image_type:圖片類型 BASE64:圖片的base64值,base64編碼後的圖片數據,需urlencode,編碼後的圖片大小不超過2M;URL:圖片的 URL地址( 可能由於網絡等原因導致下載圖片時間過長);FACE_TOKEN: 人臉圖片的唯一標識,調用人臉檢測接口時,會爲每個人臉圖片賦予一個唯一的FACE_TOKEN,同一張圖片多次檢測得到的FACE_TOKEN是同一個

        • group_id:用戶組id(由數字、字母、下劃線組成),長度限制128B

        • user_id:用戶id(由數字、字母、下劃線組成),長度限制128B

        • user_info:用戶資料,長度限制256B

        • quality_control:圖片質量控制 NONE: 不進行控制 LOW:較低的質量要求NORMAL: 一般的質量要求 HIGH: 較高的質量要求 默認NONE

        • liveness_control:活體檢測控制 NONE: 不進行控制 LOW:較低的活體要求(高通過率 低攻擊拒絕率) NORMAL: 一般的活體要求(平衡的攻擊拒絕率, 通過率) HIGH: 較高的活體要求(高攻擊拒絕率 低通過率) 默認NONE

      • 人臉註冊返回參數:

    • 人臉更新
      •  //人臉更新
            @Test
            public void testFaceUpdate() throws Exception {
                //傳入可選參數調用接口
                HashMap<String, String> options = new HashMap<String, String>();
                options.put("quality_control", "NORMAL");
                options.put("liveness_control", "LOW");
                String imageType = "BASE64";
                String groupId = "groupId";
                String userId = "userId";
                //構造base64圖片字符串
                String path = "C:\\Users\\000.png";
                byte[] bytes = Files.readAllBytes(Paths.get(path));
                String image = Base64Util.encode(bytes);
                //人臉註冊
                JSONObject res = client.updateUser(image, imageType, groupId, userId, options);
                System.out.println(res.toString(2));
           }
    • 人臉檢測

      •  

        //人臉檢測
            @Test
            public void testFaceDetect() throws IOException {
                String path = "C:\\Users\\002.png";
                byte[] bytes = Files.readAllBytes(Paths.get(path));
                String image = Base64Util.encode(bytes);
                String imageType = "BASE64";
                HashMap<String, String> subOptions = new HashMap<String, String>();
                subOptions.put("max_face_num", "10");
                //人臉檢測
                JSONObject res = client.detect(image, imageType, subOptions);
                System.out.println(res.toString(2));
           }
      • 請求參數:

      • 返回參數:

    • 人臉查找

      •  //人臉搜索
            @Test
            public void testFaceSearch() throws IOException {
                String path = "D:\\223.png";
                byte[] bytes = Files.readAllBytes(Paths.get(path));
                String image = Base64Util.encode(bytes);
                String imageType = "BASE64";
                HashMap<String, String> options = new HashMap<String, String>();
                options.put("user_top_num", "1");
                //人臉搜索
                JSONObject res = client.search(image, imageType, "itcast", options);
                System.out.println(res.toString(2));
           }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章