提交 f028badd authored 作者: yangqi's avatar yangqi

1

上级 b4b8addc
......@@ -61,4 +61,11 @@ public class FaceController {
String faceId = faceService.addFaceImage(dbName, entityId, url);
return new ApiResponse<>(faceId);
}
@NoAuth
@GetMapping("/searchFace")
public ApiResponse<Object> searchFace(String dbName, String url) throws Exception {
faceService.searchFace(dbName, url);
return new ApiResponse<>();
}
}
......@@ -149,6 +149,27 @@ public class Face {
return res.getBody().data.faceId;
}
/**
* 人脸搜索
* @link {https://help.aliyun.com/document_detail/159209.html}
*/
public SearchFaceResponseBody.SearchFaceResponseBodyDataMatchList searchFace(String dbName, String url) throws Exception {
com.aliyun.facebody20191230.Client client = createClient();
com.aliyun.facebody20191230.models.SearchFaceRequest request = new com.aliyun.facebody20191230.models.SearchFaceRequest();
request.setDbName(dbName);
request.setImageUrl(url);
request.setLimit(1);
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
SearchFaceResponse res = client.searchFaceWithOptions(request, runtime);
SearchFaceResponseBody.SearchFaceResponseBodyData data = res.getBody().data;
if(data == null){
return null;
}
List<SearchFaceResponseBody.SearchFaceResponseBodyDataMatchList> list = data.matchList;
return list.get(0);
}
public String uploadImageUrl(String file) throws com.aliyuncs.exceptions.ClientException, IOException {
FileUtils fileUtils = FileUtils.getInstance(this.accessKeyId, this.accessKeySecret);
return fileUtils.upload(file);
......
......@@ -2,6 +2,7 @@ package cn.lefull.service.ali;
import cn.lefull.common.sdk.ali.base.Face;
import cn.lefull.common.utils.Utils;
import com.aliyun.facebody20191230.models.SearchFaceResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -50,4 +51,14 @@ public class FaceService {
url = face.uploadImageUrl(url);
return face.addFaceImage(dbName, entityId, url);
}
public void searchFace(String dbName, String url) throws Exception {
Utils.checkParamsNotEmpty(dbName, "dbName");
Utils.checkParamsNotEmpty(url, "url");
url = face.uploadImageUrl(url);
SearchFaceResponseBody.SearchFaceResponseBodyDataMatchList list = face.searchFace(dbName, url);
if(list == null){
//return null;
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论