java实现人脸识别V3版本开发
? ? ? 有段時間沒有寫更新公眾號了,也許好多人都忘記了自己還關注了這么個公眾號。
????? ?
????因為這段時間確實是有其他的事比較忙,還有一個原因就是自己在技術方面沒有學習新的東西,所以沒有可更新的(包括博客)
????今天,我決定更新一下,內容主要為:java實現人臉識別使用百度API接口V3版本,主要功能實現了人臉注冊,人臉搜索(人臉登陸),人臉檢測
????????以前做出來的是V2版本的,那是207年的事了,時隔2018年一年,為什么現在才更新呢,這里我解釋一下,說實話,我存在點私心,因為V2版本的代碼只能v2的key來完成,而百度方面升級了之后用戶創建的均為V3的key。我以前寫的代碼(博客里面的代碼)都是v2的代碼,其他人要想測試效果只能從我這要key,我會讓他們關注我的公眾號獲取(因為當時做人臉識別的時候費了好多精力,不想一下子就分享給別人),所以通過這種簡單的交易來成全雙方的。
? ? 現在我想重新開發v3的版本,在分享給別人,取長補短,使得自己的技術更能得到提升,故此公開v3的源碼:
人臉檢測:
public static void face_jiance(AipFace client) {?
? ? // 傳入可選參數調用接口
? ? HashMap<String, String> options = new HashMap<String, String>();
? ? options.put("face_field", "age");
? ? options.put("max_face_num", "2");
? ? options.put("face_type", "LIVE");
? ? File directory = new File("");// 參數為空
? ? ? ? String courseFile="";
try {
courseFile = directory.getCanonicalPath();
//獲取當前項目的根路徑
? ? ? ? //System.out.println(courseFile);
? ? String image = courseFile+"/WebRoot/picture/111.jpg";
? ? String imageType = "BASE64";
? ? //轉換格式
? ? String strImageToBase64 =ImageToBase64(image);
? ? //輸出base64圖像數據
? ? ? ? //System.out.println("本地圖片轉換Base64:"+strImageToBase64);
? ? // 人臉檢測
? ? JSONObject res = client.detect(strImageToBase64,imageType, options);
? ? System.out.println(res.toString(2));
} catch (IOException e) {
// TODO 異常執行塊!
e.printStackTrace();
}
}
人臉注冊:
public static void face_reg(AipFace client) {
? ? // 傳入可選參數調用接口
? ? HashMap<String, String> options = new HashMap<String, String>();
? ? options.put("user_info", "user's info");
? ? String groupId = "group1";
? ? String userId = "user1";
? ? File directory = new File("");// 參數為空
? ? ? ? String courseFile="";
try {
courseFile = directory.getCanonicalPath();
//獲取當前項目的根路徑
? ? ? ? //System.out.println(courseFile);
String image = courseFile+"/WebRoot/picture/111.jpg";
String imageType = "BASE64";
? ? //轉換格式
? ? String strImageToBase64 =ImageToBase64(image);
? ? //輸出base64圖像數據
? ? ? ? //System.out.println("本地圖片轉換Base64:"+strImageToBase64);
? ? // 人臉注冊
? ? JSONObject res = client.addUser(strImageToBase64, imageType, groupId, userId, options);
? ? System.out.println(res.toString(2));
? ??
} catch (IOException e) {
// TODO 異常執行塊!
e.printStackTrace();
}
}
人臉登陸:
public static void face_login(AipFace client) {
? ? // 傳入可選參數調用接口
? ? HashMap<String, String> options = new HashMap<String, String>();
? ? options.put("user_id", "user1");
? ? File directory = new File("");// 參數為空
? ? ? ? String courseFile="";
? ? ? ? String groupIdList = "group1";
try {
courseFile = directory.getCanonicalPath();
//獲取當前項目的根路徑
? ? ? ? //System.out.println(courseFile);
String image = courseFile+"/WebRoot/picture/222.jpg";
String imageType = "BASE64";
? ? //轉換格式
? ? String strImageToBase64 =ImageToBase64(image);
? ? //輸出base64圖像數據
? ? ? ? //System.out.println("本地圖片轉換Base64:"+strImageToBase64);
? ? // 人臉搜索
? ? JSONObject res = client.search(strImageToBase64, imageType, groupIdList, options);
? ? System.out.println(res.toString(2));
? ??
} catch (IOException e) {
// TODO 異常執行塊!
e.printStackTrace();
}
}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的java实现人脸识别V3版本开发的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么登QQ时有手机验证
- 下一篇: 苹果手机左上方屏幕有模糊的一块