阿里云货架商品识别与管理Python SDK使用示例

简介: 本次分享通过结合Python SDK介绍该产品的使用流程。
作者:俏巴

概述

货架商品识别与管理(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://yq.aliyun.com/articles/693979
client = AcsClient("LTAIOZZg********", "v7CjUJCMk7j9aKduMAQLjy********", "cn-hangzhou")

# createTask API 创建商品识别任务
def createTask(Appkey:"实例ID",ImageLeftTop:"影像左上"):
    request = CommonRequest()
    request.set_method("POST")
    request.set_domain("retailir.cn-hangzhou.aliyuncs.com")
    request.set_action_name("CreateTask")
    request.set_version("2019-09-06")
    request.set_accept_format('json')
    request.add_body_params("Appkey", Appkey)
    request.add_body_params("TaskName", "test1")
    request.add_body_params("ImageLeftTop", ImageLeftTop)

    response = client.get_response(request)
    response_str = str(response[2], 'utf-8')  # bytes 转 string
    print(response_str) # 打印输出结果
    JobId = (json.loads(response_str))["Task"]["JobId"]   # 获取任务id
    return JobId

# getTask API 获取提交任务的结果
def getTask(Appkey:"实例ID", JobId:"任务Id"):
    request = CommonRequest()
    request.set_method("POST")
    request.set_domain("retailir.cn-hangzhou.aliyuncs.com")
    request.set_action_name("GetTask")
    request.set_version("2019-09-06")
    request.set_accept_format('json')
    request.add_body_params("Appkey", Appkey)
    request.add_body_params("JobId", JobId)

    response = client.get_response(request)
    response_str = str(response[2], 'utf-8')  # bytes 转 string
    print(response_str)  # 打印输出结果

if __name__ == '__main__':
    Appkey = "GGU4dslp********"
    ImageLeftTop = "https://img.alicdn.com/tfs/TB1OFfegEY1gK0jSZFCXXcwqXXa-720-1440.png"
    JobId = createTask(Appkey, ImageLeftTop)
    time.sleep(10) # 创建完的Task需要后端等待一段时间才能获取运行结果
    getTask(Appkey, JobId)
  • 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"}
{"RequestId":"99002@d500a6d0-6876-4cf8-babf-92fb7da65deb","Task":{"StatusCode":"20000000","Appkey":"GGU4dslp********","Response":"{\"data\":[{\"col_idx\":0,\"conf\":0.9962239265441895,\"img_idx\":0,\"layer_idx\":0,\"name\":\",品客酸乳酪洋葱味110g\",\"skuid\":9,\"x1\":55,\"x2\":108,\"y1\":112,\"y2\":269},{\"col_idx\":1,\"conf\":0.5302411317825317,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":102,\"x2\":153,\"y1\":115,\"y2\":269},{\"col_idx\":2,\"conf\":0.8753538727760315,\"img_idx\":0,\"layer_idx\":0,\"name\":\",品客番茄味110g\",\"skuid\":6,\"x1\":149,\"x2\":201,\"y1\":117,\"y2\":274},{\"col_idx\":3,\"conf\":0.999996542930603,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":200,\"x2\":272,\"y1\":127,\"y2\":278},{\"col_idx\":4,\"conf\":0.9997768998146057,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":270,\"x2\":332,\"y1\":103,\"y2\":278},{\"col_idx\":5,\"conf\":0.9999973773956299,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":326,\"x2\":383,\"y1\":100,\"y2\":282},{\"col_idx\":6,\"conf\":0.9999891519546509,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":379,\"x2\":441,\"y1\":102,\"y2\":283},{\"col_idx\":7,\"conf\":0.9999785423278809,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":431,\"x2\":568,\"y1\":173,\"y2\":289},{\"col_idx\":8,\"conf\":0.9982232451438904,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":560,\"x2\":630,\"y1\":108,\"y2\":288},{\"col_idx\":9,\"conf\":0.9994756579399109,\"img_idx\":0,\"layer_idx\":0,\"name\":\",others\",\"skuid\":0,\"x1\":616,\"x2\":688,\"y1\":106,\"y2\":286},{\"col_idx\":0,\"conf\":0.9999978542327881,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":72,\"x2\":184,\"y1\":333,\"y2\":485},{\"col_idx\":1,\"conf\":0.997977077960968,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":164,\"x2\":266,\"y1\":340,\"y2\":485},{\"col_idx\":2,\"conf\":0.9996862411499023,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":257,\"x2\":363,\"y1\":348,\"y2\":495},{\"col_idx\":3,\"conf\":0.9999994039535522,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":354,\"x2\":401,\"y1\":349,\"y2\":495},{\"col_idx\":4,\"conf\":1,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":401,\"x2\":448,\"y1\":349,\"y2\":497},{\"col_idx\":5,\"conf\":0.9999985694885254,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":441,\"x2\":551,\"y1\":344,\"y2\":499},{\"col_idx\":6,\"conf\":0.9971520900726318,\"img_idx\":0,\"layer_idx\":1,\"name\":\",others\",\"skuid\":0,\"x1\":555,\"x2\":673,\"y1\":350,\"y2\":509},{\"col_idx\":0,\"conf\":0.9999005794525146,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":68,\"x2\":150,\"y1\":505,\"y2\":653},{\"col_idx\":1,\"conf\":0.9999954700469971,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":146,\"x2\":198,\"y1\":531,\"y2\":654},{\"col_idx\":2,\"conf\":0.9950171113014221,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":191,\"x2\":286,\"y1\":530,\"y2\":661},{\"col_idx\":3,\"conf\":0.9942479133605957,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":264,\"x2\":352,\"y1\":547,\"y2\":668},{\"col_idx\":4,\"conf\":0.9999996423721313,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":346,\"x2\":466,\"y1\":559,\"y2\":629},{\"col_idx\":5,\"conf\":0.9999014139175415,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":379,\"x2\":453,\"y1\":622,\"y2\":676},{\"col_idx\":6,\"conf\":0.8119478225708008,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":459,\"x2\":582,\"y1\":554,\"y2\":685},{\"col_idx\":7,\"conf\":0.9999927282333374,\"img_idx\":0,\"layer_idx\":2,\"name\":\",others\",\"skuid\":0,\"x1\":554,\"x2\":619,\"y1\":582,\"y2\":692},{\"col_idx\":0,\"conf\":0.9999759197235107,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":98,\"x2\":138,\"y1\":690,\"y2\":804},{\"col_idx\":1,\"conf\":0.9999908208847046,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":134,\"x2\":194,\"y1\":699,\"y2\":809},{\"col_idx\":2,\"conf\":0.9979485869407654,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":191,\"x2\":237,\"y1\":689,\"y2\":811},{\"col_idx\":3,\"conf\":0.9999998807907104,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":234,\"x2\":275,\"y1\":698,\"y2\":813},{\"col_idx\":4,\"conf\":0.9999997615814209,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":272,\"x2\":312,\"y1\":696,\"y2\":819},{\"col_idx\":5,\"conf\":0.9999927282333374,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":309,\"x2\":357,\"y1\":695,\"y2\":824},{\"col_idx\":6,\"conf\":0.9559051990509033,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":352,\"x2\":395,\"y1\":702,\"y2\":829},{\"col_idx\":7,\"conf\":0.9999561309814453,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":394,\"x2\":441,\"y1\":708,\"y2\":834},{\"col_idx\":8,\"conf\":0.9999920129776001,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":436,\"x2\":479,\"y1\":709,\"y2\":837},{\"col_idx\":9,\"conf\":0.9999998807907104,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":472,\"x2\":518,\"y1\":712,\"y2\":842},{\"col_idx\":10,\"conf\":0.9999518394470215,\"img_idx\":0,\"layer_idx\":3,\"name\":\",others\",\"skuid\":0,\"x1\":510,\"x2\":618,\"y1\":731,\"y2\":856},{\"col_idx\":0,\"conf\":0.9999423027038574,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":109,\"x2\":161,\"y1\":843,\"y2\":959},{\"col_idx\":1,\"conf\":0.9999912977218628,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":152,\"x2\":209,\"y1\":859,\"y2\":963},{\"col_idx\":2,\"conf\":0.9999891519546509,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":207,\"x2\":264,\"y1\":864,\"y2\":965},{\"col_idx\":3,\"conf\":0.9999963045120239,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":264,\"x2\":321,\"y1\":866,\"y2\":972},{\"col_idx\":4,\"conf\":0.8745280504226685,\"img_idx\":0,\"layer_idx\":4,\"name\":\",品客番茄味110g\",\"skuid\":6,\"x1\":321,\"x2\":365,\"y1\":861,\"y2\":976},{\"col_idx\":5,\"conf\":0.9999991655349731,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":367,\"x2\":428,\"y1\":878,\"y2\":988},{\"col_idx\":6,\"conf\":0.9999672174453735,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":427,\"x2\":471,\"y1\":883,\"y2\":995},{\"col_idx\":7,\"conf\":0.9999639987945557,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":470,\"x2\":522,\"y1\":891,\"y2\":1003},{\"col_idx\":8,\"conf\":0.9998511075973511,\"img_idx\":0,\"layer_idx\":4,\"name\":\",others\",\"skuid\":0,\"x1\":516,\"x2\":579,\"y1\":896,\"y2\":1010}],\"stitched_info\":[{\"input_id\":\"0\",\"output_id\":-1,\"path\":\"https://img.alicdn.com/tfs/TB1OFfegEY1gK0jSZFCXXcwqXXa-720-1440.png\"}],\"version\":\"Weichaishi v0.2.5\"}\n","Request":"{\"images\":[{\"path\":\"https://img.alicdn.com/tfs/TB1OFfegEY1gK0jSZFCXXcwqXXa-720-1440.png\",\"position\":{\"x\":0,\"y\":1}}]}","UserId":"1848217816617278","LastUpdateTime":1577511690932,"Progress":100,"Status":"COMPLETED","JobId":"29ffee3863504d1493b4104600a6283b","CreateTime":1577511690000,"StatusMessage":"SUCCESS","Namespace":"ShelfInsight","Version":"1"},"ResultCode":0,"ResultMessage":"SUCCESS"}

5、其它开发语言的调用问题

目前提供的两个API接口都是通过pop接口对接,所以使用阿里云的core sdk均可做认证对接,然后使用CommonRequest()方法即可完成调用过程。相关语言可以参考阿里云新版人脸识别综述 新版本SDK调用示例参考部分即可。

_

更多参考


API 请求

相关文章
|
4月前
|
存储 Java API
【Azure 存储服务】Java Storage SDK 调用 uploadWithResponse 代码示例(询问ChatGTP得代码原型后人力验证)
【Azure 存储服务】Java Storage SDK 调用 uploadWithResponse 代码示例(询问ChatGTP得代码原型后人力验证)
|
2月前
|
程序员 开发工具 Android开发
Android|使用阿里云推流 SDK 实现双路推流不同画面
本文记录了一种使用没有原生支持多路推流的阿里云推流 Android SDK,实现同时推送两路不同画面的流的方法。
59 7
|
4月前
|
Java 开发工具
通过Java SDK调用阿里云模型服务
在阿里云平台上,可以通过创建应用并使用模型服务完成特定任务,如生成文章内容。本示例展示了一段简化的Java代码,演示了如何调用阿里云模型服务生成关于“春秋战国经济与文化”的简短文章。示例代码通过设置系统角色为历史学家,并提出文章生成需求,最终处理并输出生成的文章内容。在实际部署前,请确保正确配置环境变量中的密钥和ID,并根据需要调整SDK导入语句及类名。更多详情和示例,请参考相关链接。
|
4月前
|
Java 开发工具
【Azure Developer】示例: 在中国区调用MSGraph SDK通过User principal name获取到User信息,如Object ID
【Azure Developer】示例: 在中国区调用MSGraph SDK通过User principal name获取到User信息,如Object ID
|
5月前
|
安全 数据安全/隐私保护 Python
|
5月前
|
JSON 监控 开发者
Python I/O管理新篇章:优化你的程序,让数据流动更顺畅
【7月更文挑战第30天】在数据驱动时代, Python I/O操作效率至关重要。理解I/O瓶颈,使用缓冲技术(如调整`open`的`buffering`参数),并发与异步I/O(借助`asyncio`),高效序列化(json, msgpack),及监控调试(cProfile)能显著提升性能。示例展示了缓冲读取和异步文件操作的最佳实践。不断学习可助开发者优化数据流。
70 2
|
5月前
|
API Python
Python高手修炼手册:精通文件系统操作,掌控I/O管理,提升编程效率
【7月更文挑战第30天】在 Python 编程中, 文件系统操作与 I/O 管理是连接程序与数据的关键。初学者常因路径错误和权限问题受挫, 而高手能自如管理文件。传统 `os` 和 `os.path` 模块易出错, `pathlib` 提供了更直观的对象导向 API。I/O 方面, 同步操作会阻塞程序, 异步 (如使用 `aiofiles`) 则能大幅提升并发能力。真正的高手不仅掌握 API, 更能预见性能瓶颈并优化代码, 实现高效与优雅。
45 1
|
4月前
|
JSON Java API
【Azure API 管理】通过Java APIM SDK创建一个新的API,如何为Reqeust的Representation设置一个内容示例(Sample)?
【Azure API 管理】通过Java APIM SDK创建一个新的API,如何为Reqeust的Representation设置一个内容示例(Sample)?
|
4月前
|
存储 API 开发工具
【Azure Developer】使用 Python SDK连接Azure Storage Account, 计算Blob大小代码示例
【Azure Developer】使用 Python SDK连接Azure Storage Account, 计算Blob大小代码示例