电子相册搭建
模块
1、Service(服务分类)
2、Controller(控制器)
3、utils(公共方法)
项目结构
service模块
加载文件
VisionService
放置图像识别的算法
场景识别部分的算法
Controller
根据标签(人物表情,人物动作,场景)搜索图片,图片分类,上传图片的功能定义在这里。
功能实现
#!/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 aliyunsdkfacebody.request.v20191230.RecognizeExpressionRequest import RecognizeExpressionRequest
client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-shanghai')
request = RecognizeExpressionRequest()
request.set_accept_format('json')
request.set_ImageURL("https://current-cloud-oss.oss-cn-shanghai.aliyuncs.com/pic/20.jpg")
response = client.do_action_with_exception(request)
# python2: print(response)
print(str(response, encoding='utf-8'))
返回数据:
{
"RequestId": "91C737C4-DC71-427D-A635-21D1F565A5EF",
"Data": {
"Elements": [
{
"Expression": "happiness",
"FaceRectangle": {
"Left": 405,
"Top": 99,
"Height": 295,
"Width": 248
},
"FaceProbability": "0.99501281976699829"
},
{
"Expression": "happiness",
"FaceRectangle": {
"Left": 677,
"Top": 498,
"Height": 69,
"Width": 62
},
"FaceProbability": "0.9576987624168396"
},
{
"Expression": "happiness",
"FaceRectangle": {
"Left": 791,
"Top": 441,
"Height": 71,
"Width": 67
},
"FaceProbability": "0.92627555131912231"
},
{
"Expression": "happiness",
"FaceRectangle": {
"Left": 752,
"Top": 460,
"Height": 68,
"Width": 63
},
"FaceProbability": "0.91569304466247559"
}
]
}
}```
![image.png](https://ucc.alicdn.com/pic/developer-ecology/390d3c8adece47caaa170f77d87f8389.png)
源图片文件
**总结**