功能描述
表情识别能力可以检测和识别图片中人脸的表情。表情种类为:neutral(中性)、happiness(高兴)、surprise(惊讶)、sadness(伤心)、anger(生气)、disgust(厌恶)、fear(害怕)。
特色优势
支持识别多种表情:中性、高兴、惊讶、伤心、生气、厌恶、害怕等。
前提条件
输入限制
- 图像格式:JPEG、JPG、BMP、PNG、TIF、PBM。
- 图像大小:不超过3 MB。
- 图片分辨率:大于5×5像素,小于2048×2048像素,人脸占比不低于64×64像素。
- URL地址中不能包含中文字符。
下载安装
导入Maven依赖文件
pip install aliyun-python-sdk-core
pip install aliyun-python-sdk-facebody
代码示例
实现代码示例
#!/usr/bin/env python
#coding=utf-8
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkcore.auth.credentials import StsTokenCredential
from aliyunsdkfacebody.request.v20191230.RecognizeExpressionRequest import RecognizeExpressionRequest
credentials = AccessKeyCredential('<your-access-key-id>', '<your-access-key-secret>')
# use STS Token
# credentials = StsTokenCredential('<your-access-key-id>', '<your-access-key-secret>', '<your-sts-token>')
client = AcsClient(region_id='cn-shanghai', credential=credentials)
request = RecognizeExpressionRequest()
request.set_accept_format('json')
request.set_ImageURL("url")
response = client.do_action_with_exception(request)
# python2: print(response)
print(str(response, encoding='utf-8'))