huaweicloud-sdk-python-v3/huaweicloud-sdk-image/huaweicloudsdkimage/v1/image_client.py

193 lines
6.9 KiB
Python
Raw Normal View History

2020-05-18 07:34:40 +00:00
# coding: utf-8
from __future__ import absolute_import
import datetime
import re
import importlib
# python 2 and python 3 compatibility library
import six
from huaweicloudsdkcore.client import Client
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcore.utils import http_utils
class ImageClient(Client):
"""
:param configuration: .Configuration object for this client
:param pool_threads: The number of threads to use for async requests
to the API. More threads means more concurrent API requests.
"""
PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types
NATIVE_TYPES_MAPPING = {
'int': int,
'long': int if six.PY3 else long,
'float': float,
'str': str,
'bool': bool,
'date': datetime.date,
'datetime': datetime.datetime,
'object': object,
}
def __init__(self):
super(ImageClient, self).__init__()
self.model_package = importlib.import_module("huaweicloudsdkimage.v1.model")
self.preset_headers = {'User-Agent': 'HuaweiCloud-SDK-Python'}
def run_celebrity_recognition(self, request):
"""名人识别
分析并识别图片中包含的政治人物明星及网红人物返回人物信息及人脸坐标
:param RunCelebrityRecognitionRequest request
:return: RunCelebrityRecognitionResponse
"""
return self.run_celebrity_recognition_with_http_info(request)
def run_celebrity_recognition_with_http_info(self, request):
"""名人识别
分析并识别图片中包含的政治人物明星及网红人物返回人物信息及人脸坐标
:param RunCelebrityRecognitionRequest request
:return: tuple(RunCelebrityRecognitionResponse, status_code(int), headers(HTTPHeaderDict))
"""
all_params = ['body']
all_params.append('async_req')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')
local_var_params = {}
for attr in request.attribute_map:
if hasattr(request, attr):
local_var_params[attr] = getattr(request, attr)
collection_formats = {}
path_params = {}
query_params = []
header_params = {}
form_params = []
body_params = None
if 'body' in local_var_params:
body_params = local_var_params['body']
header_params['Accept'] = http_utils.select_header_accept(
['*/*', 'application/json'])
header_params['Content-Type'] = http_utils.select_header_content_type(
['application/json;charset=UTF-8'])
auth_settings = []
return self.call_api(
'/v1.0/image/celebrity-recognition', 'POST',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
response_type='RunCelebrityRecognitionResponse',
auth_settings=auth_settings,
collection_formats=collection_formats)
def run_image_tagging(self, request):
"""图像标签
自然图像的语义内容非常丰富一个图像包含多个标签内容图像标签服务准确识别自然图片中数百种场景上千种通用物体及其属性让智能相册管理照片检索和分类基于场景内容或者物体的广告推荐等功能更加直观使用时用户发送待处理图片返回图片标签内容及相应置信度
:param RunImageTaggingRequest request
:return: RunImageTaggingResponse
"""
return self.run_image_tagging_with_http_info(request)
def run_image_tagging_with_http_info(self, request):
"""图像标签
自然图像的语义内容非常丰富一个图像包含多个标签内容图像标签服务准确识别自然图片中数百种场景上千种通用物体及其属性让智能相册管理照片检索和分类基于场景内容或者物体的广告推荐等功能更加直观使用时用户发送待处理图片返回图片标签内容及相应置信度
:param RunImageTaggingRequest request
:return: tuple(RunImageTaggingResponse, status_code(int), headers(HTTPHeaderDict))
"""
all_params = ['body']
all_params.append('async_req')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')
local_var_params = {}
for attr in request.attribute_map:
if hasattr(request, attr):
local_var_params[attr] = getattr(request, attr)
collection_formats = {}
path_params = {}
query_params = []
header_params = {}
form_params = []
body_params = None
if 'body' in local_var_params:
body_params = local_var_params['body']
header_params['Accept'] = http_utils.select_header_accept(
['*/*', 'application/json'])
header_params['Content-Type'] = http_utils.select_header_content_type(
['application/json;charset=UTF-8'])
auth_settings = []
return self.call_api(
'/v1.0/image/tagging', 'POST',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
response_type='RunImageTaggingResponse',
auth_settings=auth_settings,
collection_formats=collection_formats)
def call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None,
response_type=None, auth_settings=None, collection_formats=None):
"""Makes the HTTP request and returns deserialized data.
:param resource_path: Path to method endpoint.
:param method: Method to call.
:param path_params: Path parameters in the url.
:param query_params: Query parameters in the url.
:param header_params: Header parameters to be
placed in the request header.
:param body: Request body.
:param post_params dict: Request post form parameters,
for `application/x-www-form-urlencoded`, `multipart/form-data`.
:param auth_settings list: Auth Settings names for the request.
:param response_type: Response data type.
:param collection_formats: dict of collection formats for path, query,
header, and post parameters.
:return:
Return the response directly.
"""
return self.do_http_request(method, resource_path, path_params,
query_params, header_params, body, post_params,
response_type, collection_formats)