功能描述
人脸属性识别能力可以识别检测人脸的性别、年龄、表情、眼镜、帽子五种属性,返回人脸的1024维深度学习特征。基于这个特征并按照特征比较规则,可以实现高性能的人脸识别。
特色优势
覆盖多个年龄段。
前提条件
输入限制
- 图像格式:JPEG、JPG、PNG、BMP。
- 图像大小:不超过3 MB。
- 图片分辨率:大于5×5像素,小于4096×4096像素,人脸占比不低于64×64像素。
- URL地址中不能包含中文字符。
下载安装
导入Maven依赖文件
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-facebody</artifactId>
<version>1.2.27</version>
</dependency>
代码示例
实现代码示例
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.facebody.model.v20191230.*;
public class RecognizeFace {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", "<your-access-key-id>", "<your-access-key-secret>");
/** use STS Token
DefaultProfile profile = DefaultProfile.getProfile(
"<your-region-id>", // The region ID
"<your-access-key-id>", // The AccessKey ID of the RAM account
"<your-access-key-secret>", // The AccessKey Secret of the RAM account
"<your-sts-token>"); // STS Token
**/
IAcsClient client = new DefaultAcsClient(profile);
RecognizeFaceRequest request = new RecognizeFaceRequest();
request.setImageURL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeFace/RecognizeFace1.png");
request.setAge(true);
request.setGender(true);
request.setHat(true);
request.setGlass(true);
try {
RecognizeFaceResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}