Python

准备工作

在安装和使用阿里云SDK前,确保您已经注册阿里云账号并生成访问密钥(AccessKey)。详情参考创建AccessKey

安装Python SDK核心库。

  • 使用依赖包工具安装(推荐)。

    • 执行以下命令,安装阿里云SDK核心库:pip install aliyun-python-sdk-core

  • 自行下载安装: 您可以使用git clone或其它手段下载aliyun-python-sdk-core并自行添加解决方案。aliyun-python-sdk-core GitHub地址:aliyun-python-sdk-core

安装IVPD Python SDK。

  • 使用依赖包工具安装(推荐)。

    • 执行以下命令,安装图像搜索Python SDK:pip install aliyun-python-sdk-ivpd, 查看版本

  • 自行下载安装:您可以使用git clone或其它手段下载aliyun-python-sdk-ivpd并自行添加解决方案。aliyun-python-sdk-ivpd GitHub地址:aliyun-python-sdk-ivpd

完整代码示例

# -*- coding: utf8 -*-

from aliyunsdkcore.client import AcsClient
from aliyunsdkivpd.request.v20190625 import *

# 创建 AcsClient 实例
client = AcsClient("<your-access-key-id>", "<your-access-key-secret>", "<region>")


# 抠图
request = SegmentImageRequest()
request.set_Url("http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/aliyun-doc/pop/images/segment-image-src.jpg")
response = client.do_action_with_exception(request)
print(response)


# 清晰化/超分辨率
request = DetectImageElementsRequest()
request.set_Url("http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/pop-sample/images/MakeSuperResolution/sup-dog.png")
response = client.do_action_with_exception(request)
print(response)


# 尺寸变换
request = ChangeImageSizeRequest()
request.set_Url("http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/IMG_20190515_202100.jpg")
request.set_Width(500)
request.set_Height(600)
response = client.do_action_with_exception(request)
print(response)


# 图像元素检测
request = DetectImageElementsRequest()
request.set_Url("http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/ivpd-demo/images/IMG_20190515_202100.jpg")
response = client.do_action_with_exception(request)
print(response)


# 风格迁移
request = ExtendImageStyleRequest()
request.set_StyleUrl("https://ivpd-demo.oss-cn-shanghai.aliyuncs.com/pop-sample/images/ExtendImageStyle/styleUrl.jpeg")
request.set_MajorUrl("https://ivpd-demo.oss-cn-shanghai.aliyuncs.com/pop-sample/images/ExtendImageStyle/majorUrl.jpeg")
response = client.do_action_with_exception(request)
print(response)


# 色板识别
request = RecognizeImageColorRequest()
request.set_Url("https://ivpd-demo.oss-cn-shanghai.aliyuncs.com/pop-sample/images/RecognizeImageColor/RecognizeImageColor.png")
request.set_ColorCount(3)
response = client.do_action_with_exception(request)
print(response)


# 风格识别
request = RecognizeImageStyleRequest()
request.set_Url("http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/pop-sample/images/RecognizeImageStyle/technology.png")
response = client.do_action_with_exception(request)
print(response)


# 色彩迁移
request = RecolorImageRequest()
#自动拓色
request.set_Mode("AUTO")
request.set_Url("http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/pop-sample/images/RecolorImage/recolor-1-src.png")
request.set_ColorCount(3)
response = client.do_action_with_exception(request)
print(response)
#参考图拓色
request.set_Mode("REF_PIC")
request.set_Url("http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/pop-sample/images/RecolorImage/recolor-refurl-src.png")
response = client.do_action_with_exception(request)
print(response)
#色板拓色
request.setMode("TEMPLATE")
request.set_Url("http://ivpd-demo.oss-cn-shanghai.aliyuncs.com/pop-sample/images/RecolorImage/recolor-2-src.png")
colorTemplateList = ()
colorTemplateList.add({"Color": "FF0000"})  # 16711680
colorTemplateList.add({"Color": "00FF00"})  # 65280
colorTemplateList.add({"Color": "0000FF"})  # 255
request.set_ColorTemplates(colorTemplateList)
response = client.do_action_with_exception(request)
print(response)
阿里云首页 智能视觉生产(文档停止维护) 相关技术圈