乾貨 | AI人臉識別之人臉搜尋

本文件將利用京東雲AI SDK來實踐人臉識別中的人臉搜尋功能,主要涉及到分組建立/刪除、分組列表獲取、人臉建立/刪除、人臉搜尋,本次實操的最終效果是: 建立一個人臉庫,拿一張圖片在人臉庫中搜尋出相似度最高的一張,實現1:N的人臉識別,操作示意圖如下:

一、準備工作
1. 建立AK/SK

2. 購買人臉搜尋服務
人臉搜尋透過 API 呼叫次數計費,目前人臉搜尋功能有 0元免費試用,呼叫量限制為 13

3.下載SDK


4.下載Eclipse並安裝
二、實操開始
1.新建JAVA專案

右擊JAVA專案中的 src目錄,依次點選 new- Package


接下來我們分別建立分組建立( faceGroupCreate)/刪除( faceGroupDelete)、分組列表獲取( getFaceGroupList)、人臉建立( faceCreate)/刪除( faceDelete)、人臉搜尋( faceSearch)相關的 (類)Class,新建 Class的方法如下:


全部Class建立完成後如下圖:

2.裝載京東雲AI SDK

重新整理Eclipse中的 Package Explorer便可看到我們複製進來的京東雲AI SDK檔案,選中全部jar包檔案,右擊,依次點選 Build Path- Add to Build Path來重新構建路徑(Build Path)

重新構建路徑完成後,我們在Eclipse的 Package Explorer中可看到 Referenced Libraries,裡面包含我們重構路徑的所有jar包

3.除錯介面
建立分組(faceGroupCreate)
1package facesearch;
2
3import com.jdcloud.apigateway.signature.JdcloudSDKClient;
4import com.jdcloud.sdk.utils.BinaryUtils;
5import com.google.api.client.http.HttpResponse;
6import java.io.IOException;
7import java.util.HashMap;
8import java.util.Map;
9
10import static com.jdcloud.sdk.http.Protocol.HTTP;
11
12//建立分組
13public class faceGroupCreate {
14 public static void main(String[] args) {
15 String accessKey = "請輸入您的AK";
16 String secretKey = "請輸入您的SK";
17 String endPoint = "aiapi.jdcloud.com";
18 String path = "/jdai/faceGroupCreate";
19 String method = "POST";
20 Map<String, String> headers = new HashMap<>();
21 Map<String, Object> queryMap = new HashMap<>();
22 //queryMap.put("groupId", "10");
23 queryMap.put("groupName", "請輸入分組名稱");
24 queryMap.put("groupInfo", "請輸入分組描述");
25 String body = "\"\"";
26 try {
27 HttpResponse response = JdcloudSDKClient.execute(accessKey, secretKey, HTTP,
28 endPoint, path, method, headers, queryMap, body);
29 System.out.println(new String(BinaryUtils.toByteArray(response.getContent())));
30 } catch (IOException e) {
31 System.out.println(e.getMessage());
32 }
33 }
34}

右擊程式碼依次點選 Run as- 1 Java Application執行程式碼

執行後發現報錯資訊如下( 這裡雖然有報錯,但我們定義的名稱為 請輸入分組名稱 的組已成功建立):

由此我們可以看出,報出錯誤的地方主要是slf4j的jar包,而故障碼中 Failed to load class "org.slf4j.impl.StaticLoggerBinder"的意思則是 載入類檔案org.slf4j.impl.StaticLoggerBinder時失敗

接下來依次建立其他類檔案
注意:如下程式碼中涉及到 String body = "imageBase64=";的部分 需要先將圖片轉換為Base64,轉換地址為:; 然後將轉換後的程式碼複製到 imageBase64=之後(轉換後的程式碼需去除掉“ data:image/jpeg;base64,”後再複製)。
刪除分組(`faceGroupDelete`)
1package facesearch;
2
3import com.jdcloud.apigateway.signature.JdcloudSDKClient;
4import com.jdcloud.sdk.utils.BinaryUtils;
5import com.google.api.client.http.HttpResponse;
6import java.io.IOException;
7import java.util.HashMap;
8import java.util.Map;
9
10import static com.jdcloud.sdk.http.Protocol.HTTP;
11
12//刪除分組
13public class faceGroupDelete {
14 public static void main(String[] args) {
15 String accessKey = "請輸入您的AK";
16 String secretKey = "請輸入您的SK";
17 String endPoint = "aiapi.jdcloud.com";
18 String path = "/jdai/faceGroupDelete";
19 String method = "POST";
20 Map<String, String> headers = new HashMap<>();
21 Map<String, Object> queryMap = new HashMap<>();
22 //queryMap.put("groupId", "10");
23 queryMap.put("groupName", "請輸入分組名稱");
24 String body = "{}";
25 try {
26 HttpResponse response = JdcloudSDKClient.execute(accessKey, secretKey, HTTP,
27 endPoint, path, method, headers, queryMap, body);
28 System.out.println(new String(BinaryUtils.toByteArray(response.getContent())));
29 } catch (IOException e) {
30 System.out.println(e.getMessage());
31 }
32 }
33}
分組列表獲取(`getFaceGroupList`)
1package facesearch;
2
3import com.jdcloud.apigateway.signature.JdcloudSDKClient;
4import com.jdcloud.sdk.utils.BinaryUtils;
5import com.google.api.client.http.HttpResponse;
6import java.io.IOException;
7import java.util.HashMap;
8import java.util.Map;
9
10import static com.jdcloud.sdk.http.Protocol.HTTP;
11
12//獲取分組列表
13public class getFaceGroupList {
14 public static void main(String[] args) {
15 String accessKey = "請輸入您的AK";
16 String secretKey = "請輸入您的SK";
17 String endPoint = "aiapi.jdcloud.com";
18 String path = "/jdai/getFaceGroupList";
19 String method = "POST";
20 Map<String, String> headers = new HashMap<>();
21 Map<String, Object> queryMap = new HashMap<>();
22 queryMap.put("start", "0");
23 queryMap.put("length", "5");
24 String body = "aaa";
25 try {
26 HttpResponse response = JdcloudSDKClient.execute(accessKey, secretKey, HTTP,
27 endPoint, path, method, headers, queryMap, body);
28 System.out.println(new String(BinaryUtils.toByteArray(response.getContent())));
29 } catch (IOException e) {
30 System.out.println(e.getMessage());
31 }
32 }
33}
人臉建立(`faceCreate`)
1package facesearch;
2
3import com.jdcloud.apigateway.signature.JdcloudSDKClient;
4import com.jdcloud.sdk.utils.BinaryUtils;
5import com.google.api.client.http.HttpResponse;
6import java.io.IOException;
7import java.util.HashMap;
8import java.util.Map;
9
10import static com.jdcloud.sdk.http.Protocol.HTTP;
11
12//建立人臉
13public class faceCreate {
14 public static void main(String[] args) {
15 String accessKey = "請輸入您的AK";
16 String secretKey = "請輸入您的SK";
17 String endPoint = "aiapi.jdcloud.com";
18 String path = "/jdai/faceCreate";
19 String method = "POST";
20 //建立
21 Map<String, String> dataMap = new HashMap<>();
22 //線上圖片轉base64:
23 dataMap.put("marin1", "imageBase64=圖片轉換為Base64後的程式碼(去掉前面的data:image/jpeg;base64,)");
24 dataMap.put("marin2", "imageBase64=圖片轉換為Base64後的程式碼(去掉前面的data:image/jpeg;base64,)");
25 dataMap.put("corona", "imageBase64=圖片轉換為Base64後的程式碼(去掉前面的data:image/jpeg;base64,)");
26 dataMap.put("dog", "imageBase64=圖片轉換為Base64後的程式碼(去掉前面的data:image/jpeg;base64,)");
27 Map<String, String> headers = new HashMap<>();
28 Map<String, Object> queryMap = new HashMap<>();
29 queryMap.put("groupName", "請輸入分組名稱");
30 String body;
31 for (Map.Entry<String, String> entry: dataMap.entrySet()){
32 queryMap.put("outerId", entry.getKey());
33 body = entry.getValue();
34 try {
35 HttpResponse response = JdcloudSDKClient.execute(accessKey, secretKey, HTTP,
36 endPoint, path, method, headers, queryMap, body);
37 System.out.println(new String(BinaryUtils.toByteArray(response.getContent())));
38 } catch (IOException e) {
39 System.out.println(e.getMessage());
40 }
41 queryMap.remove("outerId");
42 }
43 }
44}
人臉刪除(`faceDelete`)
1package facesearch;
2
3import com.jdcloud.apigateway.signature.JdcloudSDKClient;
4import com.jdcloud.sdk.utils.BinaryUtils;
5import com.google.api.client.http.HttpResponse;
6import java.io.IOException;
7import java.util.HashMap;
8import java.util.Map;
9
10import static com.jdcloud.sdk.http.Protocol.HTTP;
11
12//刪除人臉
13public class faceDelete {
14 public static void main(String[] args) {
15 String accessKey = "請輸入您的AK";
16 String secretKey = "請輸入您的SK";
17 String endPoint = "aiapi.jdcloud.com";
18 String path = "/jdai/faceDelete";
19 String method = "POST";
20 Map<String, String> headers = new HashMap<>();
21 Map<String, Object> queryMap = new HashMap<>();
22 queryMap.put("groupName", "請輸入分組名稱");
23 queryMap.put("outerId", "marin1");
24 queryMap.put("outerId", "marin2");
25 queryMap.put("outerId", "corona");
26 queryMap.put("outerId", "dog");
27 String body = "{}";
28 try {
29 HttpResponse response = JdcloudSDKClient.execute(accessKey, secretKey, HTTP,
30 endPoint, path, method, headers, queryMap, body);
31 System.out.println(new String(BinaryUtils.toByteArray(response.getContent())));
32 } catch (IOException e) {
33 System.out.println(e.getMessage());
34 }
35 }
36}
人臉搜尋(`faceSearch`)
1package facesearch;
2
3import com.jdcloud.apigateway.signature.JdcloudSDKClient;
4import com.jdcloud.sdk.utils.BinaryUtils;
5import com.google.api.client.http.HttpResponse;
6import java.io.IOException;
7import java.util.HashMap;
8import java.util.Map;
9
10import static com.jdcloud.sdk.http.Protocol.HTTP;
11
12//人臉搜尋
13public class faceSearch {
14 public static void main(String[] args) {
15 String accessKey = "請輸入您的AK";
16 String secretKey = "請輸入您的SK";
17 String endPoint = "aiapi.jdcloud.com";
18 String path = "/jdai/faceSearch";
19 String method = "POST";
20 Map<String, String> headers = new HashMap<>();
21 Map<String, Object> queryMap = new HashMap<>();
22 queryMap.put("groupName", "請輸入分組名稱");
23 //如下填寫同一人的第三張人臉Base64程式碼進行人臉搜尋,這裡用人臉marin.jpg
24 String body = "imageBase64=圖片轉換為Base64後的程式碼(去掉前面的data:image/jpeg;base64,)";
25 try {
26 HttpResponse response = JdcloudSDKClient.execute(accessKey, secretKey, HTTP,
27 endPoint, path, method, headers, queryMap, body);
28 System.out.println(new String(BinaryUtils.toByteArray(response.getContent())));
29 } catch (IOException e) {
30 System.out.println(e.getMessage());
31 }
32 }
33}
4.進行演示
如下演示都透過右擊對應的程式碼執行 Run as- 1 Java Application來執行程式碼檢視結果
建立分組

獲取分組列表

建立人臉庫

人臉搜尋

刪除人臉

刪除分組

如上,我們透過 marin1.jpg、 marin2.jpg、 corona.jpg、 dog.jpg建立了人臉庫,最後透過 marin.jpg將相似度最高的 marin1.jpg搜尋了出來,至此,操作演示完畢~~
點選“
京東雲
”瞭解京東雲人臉對比
歡迎點選“ 京東雲 ”瞭解更多精彩內容

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69912185/viewspace-2660500/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 人臉識別之人臉檢測的重要性
- 人工智慧之人臉識別技術人工智慧
- 實現 AI 換臉的第一步:人臉搜尋AI
- opencv 人臉識別OpenCV
- 人臉識別之特徵臉方法(Eigenface)特徵
- 人臉檢測識別,人臉檢測,人臉識別,離線檢測,C#原始碼C#原始碼
- 前端人臉識別--兩張臉相似度前端
- AI+慈善 ▏人臉識別+人臉模擬助力失散親人找到回家的路AI
- 小程式--人臉識別功能(百度ai)AI
- python ubuntu dlib人臉識別3-人臉對齊PythonUbuntu
- 人臉活體檢測人臉識別:眨眼+張口
- C#人臉識別入門篇-STEP BY STEP人臉識別--入門篇C#
- 智慧人臉識別門禁系統開發,人臉識別開鎖流程
- 「乾貨」影象演算法之3D人臉識別技術原理概述演算法3D
- 人臉識別之Python DLib庫進行人臉關鍵點識別Python
- python—呼叫API人臉識別PythonAPI
- 「專利解密」商湯科技:AI加持人臉識別解密AI
- 機器視覺之人臉識別的流程及主要技術視覺
- 保障人臉安全!頂象釋出《人臉識別安全白皮書》
- 人臉識別智慧考勤系統開發_人臉識別考勤管理系統開發
- 刷臉支付人臉識別特徵點越多是別越精確特徵
- 前端如何玩轉人臉識別前端
- 人臉識別技術應用
- Python人臉識別微笑檢測Python
- 從零玩轉人臉識別
- 刪除十億人臉資料,Facebook關閉人臉識別系統
- 從零玩轉人臉識別之RGB人臉活體檢測
- OpenCV-Python 人臉眼睛嘴識別OpenCVPython
- 人臉識別系列(三):DeepID2
- 人臉識別系列(二):DeepID1
- TensorFlow2.0 + CNN + keras + 人臉識別CNNKeras
- 人工智慧資料標註案例之人臉識別 | 景聯文科技人工智慧
- OPPO Find X 3D人臉識別功能 支援刷臉支付3D
- 人臉美化和人臉識別在美顏SDK中的具體應用
- 人臉識別技術看這一篇就夠了(附國內人臉識別20強公司)
- 識別特定影象的AI玻璃來了,未來或可用於人臉識別AI
- 支小蜜食堂人臉識別就餐系統,“刷臉”消費更透明
- 人臉識別不到位,兄弟秒變父與子!AI 研習社「人臉年齡識別挑戰賽」火熱進行中AI