作者:俏巴
概述
货架商品识别与管理(Retail Image Recognition)是基于深度学习、图像检测、图像识别等技术,为新零售品牌商/经销商提供AI商品识别能力的阿里云产品;适用于货架商品识别、陈列识别、形象化识别等多个业务应用场景中,提供对渠道的数据全面精准洞察,助力渠道业务管理实现数字化、智能化的转型升级。目前该产品还在公测预览版免费试用阶段,下面通过结合Python SDK介绍该产品的使用流程。
操作步骤
1、服务开通
申请一般需要一到三个工作日审批通过,如果想加快审批流程,可以提工单,注意提工单的时候带上申请的账户Uid。
2、创建项目
3、控制台快速测试
4、Python SDK测试
- 4.1 Python SDK的安装可以参考链接
- 4.2 Code Sample
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
import json
import time
DefaultProfile.getProfile的参数分别是access_key_id, access_key_secret,region(目前固定为杭州) https: class="hljs-comment">//yq.aliyun.com/articles/693979
client = AcsClient("LTAIOZZg", "v7CjUJCMk7j9aKduMAQLjy", "cn-hangzhou")
createTask API 创建商品识别任务
def createTask(Appkey:"实例ID",ImageLeftTop:"影像左上"):
request = CommonRequest()
request.set_method(<span class="hljs-string">"POST"</span>)
request.set_domain(<span class="hljs-string">"retailir.cn-hangzhou.aliyuncs.com"</span>)
request.set_action_name(<span class="hljs-string">"CreateTask"</span>)
request.set_version(<span class="hljs-string">"2019-09-06"</span>)
request.set_accept_format(<span class="hljs-string">'json'</span>)
request.add_body_params(<span class="hljs-string">"Appkey"</span>, Appkey)
request.add_body_params(<span class="hljs-string">"TaskName"</span>, <span class="hljs-string">"test1"</span>)
request.add_body_params(<span class="hljs-string">"ImageLeftTop"</span>, ImageLeftTop)
response = client.get_response(request)
response_str = str(response[<span class="hljs-number">2</span>], <span class="hljs-string">'utf-8'</span>) # bytes 转 string
print(response_str) # 打印输出结果
JobId = (json.loads(response_str))[<span class="hljs-string">"Task"</span>][<span class="hljs-string">"JobId"</span>] # 获取任务id
<span class="hljs-keyword">return</span> JobId
getTask API 获取提交任务的结果
def getTask(Appkey:"实例ID", JobId:"任务Id"):
request = CommonRequest()
request.set_method(<span class="hljs-string">"POST"</span>)
request.set_domain(<span class="hljs-string">"retailir.cn-hangzhou.aliyuncs.com"</span>)
request.set_action_name(<span class="hljs-string">"GetTask"</span>)
request.set_version(<span class="hljs-string">"2019-09-06"</span>)
request.set_accept_format(<span class="hljs-string">'json'</span>)
request.add_body_params(<span class="hljs-string">"Appkey"</span>, Appkey)
request.add_body_params(<span class="hljs-string">"JobId"</span>, JobId)
response = client.get_response(request)
response_str = str(response[<span class="hljs-number">2</span>], <span class="hljs-string">'utf-8'</span>) # bytes 转 string
print(response_str) # 打印输出结果
if name == '__main__':
Appkey = <span class="hljs-string">"GGU4dslp********"</span>
ImageLeftTop = <span class="hljs-string">"https://img.alicdn.com/tfs/TB1OFfegEY1gK0jSZFCXXcwqXXa-720-1440.png"</span>
JobId = createTask(Appkey, ImageLeftTop)
time.sleep(<span class="hljs-number">10</span>) # 创建完的Task需要后端等待一段时间才能获取运行结果
getTask(Appkey, JobId)</code></pre>
4.3 代码测试结果
{"RequestId":"99020@73d2c29d-4bd2-4d44-bc72-3ab674072d8f","Task":{"Status":"INIT","Appkey":"GGU4dslp","JobId":"29ffee3863504d1493b4104600a6283b","Namespace":"ShelfInsight","Request":"{"images":[{"path":"https://img.alicdn.com/tfs/TB1OFfegEY1gK0jSZFCXXcwqXXa-720-1440.png","position":{"x":0,"y":1}}]}","UserId":"1848217816617278","Version":"0","Progress":0},"ResultCode":0,"ResultMessage":"SUCCESS"}
5、其它开发语言的调用问题
目前提供的两个API接口都是通过pop接口对接,所以使用阿里云的core sdk均可做认证对接,然后使用CommonRequest()方法即可完成调用过程。相关语言可以参考阿里云新版人脸识别综述 新版本SDK调用示例参考部分即可。
更多参考
更多参考