如何开发python sdk_Python SDK

本文介绍图像搜索服务Python SDK的使用方法及示例。

接口列表

接口名称

接口说明

Add

增加图片。

SearchImageByPic

使用图片进行搜索。

SearchImageByName

指定名称,使用已入库的图片进行搜索。

Delete

删除图片。

准备工作

使用如下方式安装依赖包。pip install alibabacloud_imagesearch20200212

Add接口

代码示例from alibabacloud_imagesearch20200212.client import Client

from alibabacloud_imagesearch20200212.models import AddImageAdvanceRequest

from alibabacloud_tea_rpc.models import Config

from alibabacloud_oss_util.models import RuntimeOptions

def addImage():

request = AddImageAdvanceRequest()

request.instance_name = ''

request.product_id = ''

request.pic_name = ''

f = open('', 'rb')

request.pic_content_object = f

config = Config()

config.access_key_id = ''

config.access_key_secret = ''

config.endpoint = 'imagesearch.[regionId].aliyuncs.com'

config.region_id = ''

config.type = 'access_key'

client = Client(config)

runtime_option = RuntimeOptions()

response = client.add_image_advance(request, runtime_option)

print(response.to_map())

f.close()

if __name__ == '__main__':

addImage()

结果示例{

'RequestId': '7F769FFC-4F45-476E-BE6C-E4EF82E012A7',

'Success': True,

'Message': 'success',

'Code': 0,

'PicInfo': {

'CategoryId': 20,

'Region': '474,747,497,784'

}

}

SearchImageByPic接口

代码示例from alibabacloud_imagesearch20200212.client import Client

from alibabacloud_imagesearch20200212.models import SearchImageByPicAdvanceRequest

from alibabacloud_tea_rpc.models import Config

from alibabacloud_oss_util.models import RuntimeOptions

def searchImageByPic() :

request = SearchImageByPicAdvanceRequest()

request.instance_name = ''

f = open('', 'rb')

request.pic_content_object = f

config = Config()

config.access_key_id = ''

config.access_key_secret = ''

config.endpoint = 'imagesearch.[regionId].aliyuncs.com'

config.region_id = ''

config.type = 'access_key'

client = Client(config)

runtime_option = RuntimeOptions()

response = client.search_image_by_pic_advance(request, runtime_option)

print(response.to_map())

f.close()

if __name__ == '__main__':

searchImageByPic()

结果示例{

'RequestId': '53C481F3-E064-428D-AB25-B6C57A704E68',

'Success': True,

'Code': 0,

'Msg': 'success',

'Auctions': [{

'CategoryId': 20,

'ProductId': 'test-version-001',

'PicName': 'test-version-001.jpg',

'CustomContent': None,

'SortExprValues': '5.37633353624177e+24;0',

'IntAttr': None,

'StrAttr': None

}, {

'CategoryId': 20,

'ProductId': 'test_0426_1',

'PicName': 'test_0426_1.png',

'CustomContent': None,

'SortExprValues': '2.71303606033325;263',

'IntAttr': None,

'StrAttr': None

}],

'Head': {

'DocsReturn': 5,

'DocsFound': 5,

'SearchTime': 295

},

'PicInfo': {

'CategoryId': 20,

'Region': '474,747,497,784',

'AllCategories': [{

'Id': 0,

'Name': 'Tops'

}, {

'Id': 1,

'Name': 'Dress'

}, {

'Id': 2,

'Name': 'Bottoms'

}, {

'Id': 3,

'Name': 'Bag'

}, {

'Id': 4,

'Name': 'Shoes'

}, {

'Id': 5,

'Name': 'Accessories'

}, {

'Id': 6,

'Name': 'Snack'

}, {

'Id': 7,

'Name': 'Makeup'

}, {

'Id': 8,

'Name': 'Bottle'

}, {

'Id': 9,

'Name': 'Furniture'

}, {

'Id': 20,

'Name': 'Toy'

}, {

'Id': 21,

'Name': 'Underwear'

}, {

'Id': 22,

'Name': 'Digital device'

}, {

'Id': 88888888,

'Name': 'Other'

}]

}

}

SearchImageByName接口

代码示例from alibabacloud_imagesearch20200212.client import Client

from alibabacloud_imagesearch20200212.models import SearchImageByNameRequest

from alibabacloud_tea_rpc.models import Config

from alibabacloud_oss_util.models import RuntimeOptions

def searchImageByName() :

request = SearchImageByNameRequest()

request.instance_name = ''

request.product_id = ''

request.pic_name = ''

config = Config()

config.access_key_id = ''

config.access_key_secret = ''

config.endpoint = 'imagesearch.[regionId].aliyuncs.com'

config.region_id = ''

config.type = 'access_key'

client = Client(config)

runtime_option = RuntimeOptions()

response = client.search_image_by_name(request, runtime_option)

print(response.to_map())

if __name__ == '__main__':

searchImageByName()

结果示例{

'RequestId': '7BC00158-3B9B-49C4-9E25-FFEC28AF3CE8',

'Success': True,

'Code': 0,

'Msg': 'success',

'Auctions': [{

'CategoryId': 20,

'ProductId': 'test-version-001',

'PicName': 'test-version-001.jpg',

'CustomContent': None,

'SortExprValues': '5.37633353624177e+24;0',

'IntAttr': None,

'StrAttr': None

}, {

'CategoryId': 20,

'ProductId': 'test_0426_1',

'PicName': 'test_0426_1.png',

'CustomContent': None,

'SortExprValues': '2.71303606033325;263',

'IntAttr': None,

'StrAttr': None

}],

'Head': {

'DocsReturn': 5,

'DocsFound': 5,

'SearchTime': 15

},

'PicInfo': {

'CategoryId': 20,

'Region': None,

'AllCategories': [{

'Id': 0,

'Name': 'Tops'

}, {

'Id': 1,

'Name': 'Dress'

}, {

'Id': 2,

'Name': 'Bottoms'

}, {

'Id': 3,

'Name': 'Bag'

}, {

'Id': 4,

'Name': 'Shoes'

}, {

'Id': 5,

'Name': 'Accessories'

}, {

'Id': 6,

'Name': 'Snack'

}, {

'Id': 7,

'Name': 'Makeup'

}, {

'Id': 8,

'Name': 'Bottle'

}, {

'Id': 9,

'Name': 'Furniture'

}, {

'Id': 20,

'Name': 'Toy'

}, {

'Id': 21,

'Name': 'Underwear'

}, {

'Id': 22,

'Name': 'Digital device'

}, {

'Id': 88888888,

'Name': 'Other'

}]

}

}

Delete接口

代码示例def deleteImage() :

request = DeleteImageRequest()

request.instance_name = ''

request.product_id = ''

request.pic_name = ''

config = Config()

config.access_key_id = ''

config.access_key_secret = ''

config.endpoint = 'imagesearch.[regionId].aliyuncs.com'

config.region_id = ''

config.type = 'access_key'

client = Client(config)

runtime_option = RuntimeOptions()

response = client.delete_image(request, runtime_option)

print(response.to_map())

if __name__ == '__main__':

deleteImage()

结果示例{

'RequestId': '9ADA959B-B639-4B3B-841D-2399F1C34DA8',

'Success': True,

'Message': 'success',

'Code': 0

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值