功能描述
表情识别能力可以检测和识别图片中人脸的表情。表情种类为:neutral(中性)、happiness(高兴)、surprise(惊讶)、sadness(伤心)、anger(生气)、disgust(厌恶)、fear(害怕)。
特色优势
支持识别多种表情:中性、高兴、惊讶、伤心、生气、厌恶、害怕等。
前提条件
输入限制
- 图像格式:JPEG、JPG、BMP、PNG、TIF、PBM。
- 图像大小:不超过3 MB。
- 图片分辨率:大于5×5像素,小于2048×2048像素,人脸占比不低于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 RecognizeExpression {
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);
RecognizeExpressionRequest request = new RecognizeExpressionRequest();
request.setImageURL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/facebody/RecognizeExpression/RecognizeExpression10.jpg");
try {
RecognizeExpressionResponse 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());
}
}
}