提交 0e377a8f authored 作者: yangqi's avatar yangqi

1

上级 13b7f72f
......@@ -153,7 +153,7 @@ public class Face {
* 人脸搜索
* @link {https://help.aliyun.com/document_detail/159209.html}
*/
public SearchFaceResponseBody.SearchFaceResponseBodyDataMatchList searchFace(String dbName, String url) throws Exception {
public Map<String, String> 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);
......@@ -166,8 +166,20 @@ public class Face {
if(data == null){
return null;
}
List<SearchFaceResponseBody.SearchFaceResponseBodyDataMatchList> list = data.matchList;
return list.get(0);
List<SearchFaceResponseBody.SearchFaceResponseBodyDataMatchList> matchList = data.matchList;
if(matchList == null){
return null;
}
SearchFaceResponseBody.SearchFaceResponseBodyDataMatchList match = matchList.get(0);
List<SearchFaceResponseBody.SearchFaceResponseBodyDataMatchListFaceItems> itemList = match.getFaceItems();
if(itemList == null){
return null;
}
SearchFaceResponseBody.SearchFaceResponseBodyDataMatchListFaceItems item = itemList.get(0);
Map<String, String> map = new HashMap<>();
map.put("entityId" , item.getEntityId());
map.put("faceId", item.getFaceId());
return map;
}
public String uploadImageUrl(String file) throws com.aliyuncs.exceptions.ClientException, IOException {
......
......@@ -44,5 +44,5 @@ public interface FaceService {
/**
* 搜索人脸
*/
public void searchFace(String dbName, String url) throws Exception;
public boolean searchFace(String dbName, String url) throws Exception;
}
......@@ -120,13 +120,18 @@ public class FaceServiceImpl implements FaceService{
}
@Override
public void searchFace(String dbName, String url) throws Exception {
public boolean searchFace(String dbName, String url) throws Exception {
Utils.checkParamsNotEmpty(dbName, "dbName");
Utils.checkParamsNotEmpty(url, "url");
url = sdk.uploadImageUrl(url);
SearchFaceResponseBody.SearchFaceResponseBodyDataMatchList list = sdk.searchFace(dbName, url);
if(list == null){
//return null;
Map<String, String> map = sdk.searchFace(dbName, url);
if(map == null){
return false;
}
String entityId = map.get("entityId");
String faceId = map.get("faceId");
System.out.println(entityId);
System.out.println(faceId);
return true;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论