face++实现人脸识别

因为项目是在多年前完毕,face++的sdk可能有调整,所以部分功能可能不再适用(2017.3)

近期做了一个使用face++实现人脸识别的功能。当初看着官方文档一点头绪都没有。看了好久才弄明确。所以在这里记录一下,希望能够帮到须要的人。

首先要注冊一个face++账号。获取apiKey和apiSecret,把face++的jar包加入到libs文件夹下,接下来是实现这个功能的代码。核心代码例如以下:

					//获取第一张图片的信息
					byte[] array1 = imageProcessing(firstPath);
					JSONObject result1 = httpRequests.detectionDetect(new PostParameters().setImg(array1));
					String face1 = result1.getJSONArray("face").getJSONObject(0).getString("face_id");
					System.out.println("face1的id=" + face1);
					//获取第二张图片的信息
					byte[] array2 = imageProcessing(secondPath);
					JSONObject result2 = httpRequests.detectionDetect(new PostParameters().setImg(array2));
					String face2 = result2.getJSONArray("face").getJSONObject(0).getString("face_id");
					System.out.println("face2的id=" + face2);
						
					System.out.println("開始比較:");
					//对照两张人脸的类似程度
					JSONObject Compare = httpRequests.recognitionCompare(new PostParameters().setFaceId1(face1).setFaceId2(face2));
					final Double smilar = Double.valueOf(Compare.getString("similarity"));
执行后的效果例如以下:

所有代码点击这里下载




原文地址:https://www.cnblogs.com/yutingliuyl/p/6755611.html