電子相冊搭建
子產品
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"
}
]
}
}```

源圖檔檔案
**總結**