本文介紹了Python SDK V2.0的安裝方式和使用智能標簽SDK的示例代碼。
版本說明
媒體處理的Python SDK版本需要在3.6版本及以上。阿里云Python SDK V2.0推薦的pip安裝方式:
pip install alibabacloud_mts20140618==5.0.0
前提條件
使用前請先初始化客戶端,詳細說明請參見初始化。
提交智能標簽作業
調用SubmitSmarttagJob提交智能標簽作業,接口字段和參數詳細信息請參見提交智能標簽作業,調用示例如下:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
submit_smarttag_job_request = mts_20140618_models.SubmitSmarttagJobRequest(
# 管道ID
pipeline_id='2',
# 視頻標題
title='example-title-****',
# 視頻內容描述
content='example content ****',
# 額外的請求參數
params='false',
# Callback路徑
notify_url='https://example.com/endpoint/aliyun/ai?id=76401125000***',
# 通過回調透傳回來的信息
user_data='{"key":"value"}',
# 需要分析的視頻或圖片文件的地址
input='oss://mybucket-****/example-****.mp4',
# 模板ID用于指定分析算法
template_id='39f8e0bc005e4f309379701645f4****',
# 任務在其對應管道內的優先級
priority='5'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
client.submit_smarttag_job_with_options(submit_smarttag_job_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
submit_smarttag_job_request = mts_20140618_models.SubmitSmarttagJobRequest(
# 管道ID
pipeline_id='2',
# 視頻標題
title='example-title-****',
# 視頻內容描述
content='example content ****',
# 額外的請求參數
params='false',
# Callback路徑
notify_url='https://example.com/endpoint/aliyun/ai?id=76401125000***',
# 通過回調透傳回來的信息
user_data='{"key":"value"}',
# 需要分析的視頻或圖片文件的地址
input='oss://mybucket-****/example-****.mp4',
# 模板ID用于指定分析算法
template_id='39f8e0bc005e4f309379701645f4****',
# 任務在其對應管道內的優先級
priority='5'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
await client.submit_smarttag_job_with_options_async(submit_smarttag_job_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
查詢智能標簽作業
調用QuerySmarttagJob查詢智能標簽作業,接口字段和參數詳細信息請參見查詢智能標簽作業,調用示例如下:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
query_smarttag_job_request = mts_20140618_models.QuerySmarttagJobRequest(
#需要查詢的智能標簽作業ID
job_id='39f8e0bc005e4f309379701645f4****',
#額外的請求參數
params='{"labelResultType":"auto"}'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
client.query_smarttag_job_with_options(query_smarttag_job_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
query_smarttag_job_request = mts_20140618_models.QuerySmarttagJobRequest(
# 需要查詢的智能標簽作業ID
job_id='39f8e0bc005e4f309379701645f4****',
# 額外的請求參數
params='{"labelResultType":"auto"}'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
await client.query_smarttag_job_with_options_async(query_smarttag_job_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
添加模板
調用AddSmarttagTemplate 添加一個模板,接口字段和參數詳細信息請參見添加模板,調用示例如下:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
add_smarttag_template_request = mts_20140618_models.AddSmarttagTemplateRequest(
# 自定義模板名稱
template_name='template-example-****',
# 待分析文件所處行業
industry='common',
# 待分析文件使用場景
scene='search',
# 分析類型
analyse_types='ocr',
# 參與識別的?臉庫ID列表
face_category_ids='celebrity',
# 人臉算法的參數
face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
# 參與識別的物體庫ID列表
object_group_ids='general,item,weapon,animal',
# 參與識別的地域庫ID列表
landmark_group_ids='common',
# 是否設置為默認模板(設置為默認模板后
is_default=True,
# 標注類型
label_type='hmi',
# 指定智能標簽版本
label_version='1.0',
# 智能標簽2.0和2.0-custom模式下
knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
# 關鍵詞標簽配置
keyword_config='"type": "name,location,organization,other" }'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
client.add_smarttag_template_with_options(add_smarttag_template_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
add_smarttag_template_request = mts_20140618_models.AddSmarttagTemplateRequest(
# 自定義模板名稱
template_name='template-example-****',
# 待分析文件所處行業
industry='common',
# 待分析文件使用場景
scene='search',
# 分析類型
analyse_types='ocr',
# 參與識別的?臉庫ID列表
face_category_ids='celebrity',
# 人臉算法的參數
face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
# 參與識別的物體庫ID列表
object_group_ids='general,item,weapon,animal',
# 參與識別的地域庫ID列表
landmark_group_ids='common',
# 是否設置為默認模板(設置為默認模板后
is_default=True,
# 標注類型
label_type='hmi',
# 指定智能標簽版本
label_version='1.0',
# 智能標簽2.0和2.0-custom模式下
knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
# 關鍵詞標簽配置
keyword_config='"type": "name,location,organization,other" }'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
await client.add_smarttag_template_with_options_async(add_smarttag_template_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
查詢模板
調用QuerySmarttagTemplateList查詢模板信息,接口字段和參數詳細信息請參見查詢模板,調用示例如下:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
query_smarttag_template_list_request = mts_20140618_models.QuerySmarttagTemplateListRequest(
# 模板ID
template_id='05de22f255284c7a8d2aab535dde****'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
client.query_smarttag_template_list_with_options(query_smarttag_template_list_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
query_smarttag_template_list_request = mts_20140618_models.QuerySmarttagTemplateListRequest(
# 模板ID
template_id='05de22f255284c7a8d2aab535dde****'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
await client.query_smarttag_template_list_with_options_async(query_smarttag_template_list_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
更新模板
調用UpdateSmarttagTemplate更新模板信息,接口字段和參數詳細信息請參見更新模板,調用示例如下:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
update_smarttag_template_request = mts_20140618_models.UpdateSmarttagTemplateRequest(
# 模板ID
template_id='05de22f255284c7a8d2aab535dde****',
# 自定義模板名稱
template_name='template-example-****',
# 待分析文件所處行業
industry='common',
# 使用場景
scene='search',
# 分析類型
analyse_types='ocr,asr',
# 參與識別的?臉庫ID列表
face_category_ids='celebrity',
# 人臉算法的參數
face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
# 參與識別的物體庫ID列表
object_group_ids='general,item,weapon,animal',
# 參與識別的地域庫ID列表
landmark_group_ids='common',
# 是否默認模板
is_default=True,
# 標注類型
label_type='hmi',
# 指定智能標簽版本
label_version='1.0',
# 智能標簽2.0和2.0-custom模式下
knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
# 關鍵詞標簽配置
keyword_config='{ "type": "name,location,organization,other" }'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
client.update_smarttag_template_with_options(update_smarttag_template_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
update_smarttag_template_request = mts_20140618_models.UpdateSmarttagTemplateRequest(
# 模板ID
template_id='05de22f255284c7a8d2aab535dde****',
# 自定義模板名稱
template_name='template-example-****',
# 待分析文件所處行業
industry='common',
# 使用場景
scene='search',
# 分析類型
analyse_types='ocr,asr',
# 參與識別的?臉庫ID列表
face_category_ids='celebrity',
# 人臉算法的參數
face_custom_params_config='{ "faceDetThreshold":0.999, "faceRegThreshold":0.9 }',
# 參與識別的物體庫ID列表
object_group_ids='general,item,weapon,animal',
# 參與識別的地域庫ID列表
landmark_group_ids='common',
# 是否默認模板
is_default=True,
# 標注類型
label_type='hmi',
# 指定智能標簽版本
label_version='1.0',
# 智能標簽2.0和2.0-custom模式下
knowledge_config='{ "movie":"name,alias,chnl,genre", "music":"songName,artistName", "person":"name,gender" }',
# 關鍵詞標簽配置
keyword_config='{ "type": "name,location,organization,other" }'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
await client.update_smarttag_template_with_options_async(update_smarttag_template_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
刪除模板
調用DeleteSmarttagTemplate刪除模板,接口字段和參數詳細信息請參見刪除模板,調用示例如下:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
delete_smarttag_template_request = mts_20140618_models.DeleteSmarttagTemplateRequest(
# 需要刪除的模板ID
template_id='05de22f255284c7a8d2aab535dde****'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
client.delete_smarttag_template_with_options(delete_smarttag_template_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
delete_smarttag_template_request = mts_20140618_models.DeleteSmarttagTemplateRequest(
# 需要刪除的模板ID
template_id='05de22f255284c7a8d2aab535dde****'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
await client.delete_smarttag_template_with_options_async(delete_smarttag_template_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
注冊自定義人臉
調用RegisterCustomFace注冊自定義人臉,接口字段和詳細參數信息請參見注冊?定義?臉,調用示例如下:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
register_custom_face_request = mts_20140618_models.RegisterCustomFaceRequest(
# ?物庫ID
category_id='CategoryId001-****',
# ?物ID
person_id='PersonId001-****',
# 需要注冊的?臉圖?公網地址
image_url='http://example-****.jpeg'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
client.register_custom_face_with_options(register_custom_face_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
register_custom_face_request = mts_20140618_models.RegisterCustomFaceRequest(
# ?物庫ID
category_id='CategoryId001-****',
# ?物ID
person_id='PersonId001-****',
# 需要注冊的?臉圖?公網地址
image_url='http://example-****.jpeg'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
await client.register_custom_face_with_options_async(register_custom_face_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
注銷自定義人臉
調用UnregisterCustomFace注銷自定義人臉,接口字段和參數詳細說明請參見注銷?定義?臉,調用示例如下:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
unregister_custom_face_request = mts_20140618_models.UnregisterCustomFaceRequest(
# ?物庫ID
category_id='CategoryId001-****',
# ?物ID
person_id='PersonId001-****',
# 人臉ID
face_id='15****'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
client.unregister_custom_face_with_options(unregister_custom_face_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
unregister_custom_face_request = mts_20140618_models.UnregisterCustomFaceRequest(
# ?物庫ID
category_id='CategoryId001-****',
# ?物ID
person_id='PersonId001-****',
# 人臉ID
face_id='15****'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
await client.unregister_custom_face_with_options_async(unregister_custom_face_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
添加自定義人物庫或人物標簽
調用TagCustomPerson添加自定義人物庫或人物標簽,接口字段和參數詳細信息請參見添加自定義人物庫或人物標簽,調用示例如下:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
tag_custom_person_request = mts_20140618_models.TagCustomPersonRequest(
# ?物庫ID
category_id='CategoryId001-****',
# ?物庫名稱
category_name='CategoryNametest-****',
# ?物庫描述
category_description='CategoryDescription001-****',
# ?物ID
person_id='PersonId001-****',
# ?物名稱
person_name='PersonNametest-****',
# ?物描述
person_description='PersonDescriptiontest-****'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
client.tag_custom_person_with_options(tag_custom_person_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
tag_custom_person_request = mts_20140618_models.TagCustomPersonRequest(
# ?物庫ID
category_id='CategoryId001-****',
# ?物庫名稱
category_name='CategoryNametest-****',
# ?物庫描述
category_description='CategoryDescription001-****',
# ?物ID
person_id='PersonId001-****',
# ?物名稱
person_name='PersonNametest-****',
# ?物描述
person_description='PersonDescriptiontest-****'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
await client.tag_custom_person_with_options_async(tag_custom_person_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
列出人物庫所有人物和人臉信息
調用ListCustomPersons列出人物庫所有人物和人臉信息,接口字段和參數詳細說明請參見列出?物庫所有?物和?臉信息,調用示例如下:
import os
import sys
from typing import List
from alibabacloud_mts20140618.client import Client as Mts20140618Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_mts20140618 import models as mts_20140618_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client() -> Mts20140618Client:
"""
使用AK&SK初始化賬號Client
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
# 必填,請確保代碼運行環境設置了環境變量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
config.endpoint = f'mts.cn-hangzhou.aliyuncs.com'
return Mts20140618Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
client = Sample.create_client()
list_custom_persons_request = mts_20140618_models.ListCustomPersonsRequest(
# ?物庫ID
category_id='CategoryId-****',
# ?物ID
person_id='PersonId-****'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
client.list_custom_persons_with_options(list_custom_persons_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
client = Sample.create_client()
list_custom_persons_request = mts_20140618_models.ListCustomPersonsRequest(
# ?物庫ID
category_id='CategoryId-****',
# ?物ID
person_id='PersonId-****'
)
runtime = util_models.RuntimeOptions()
try:
# 復制代碼運行請自行打印 API 的返回值
await client.list_custom_persons_with_options_async(list_custom_persons_request, runtime)
except Exception as error:
# 此處僅做打印展示,請謹慎對待異常處理,在工程項目中切勿直接忽略異常。
# 錯誤 message
print(error.message)
# 診斷地址
print(error.data.get("Recommend"))
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
文檔內容是否對您有幫助?