ImageAnnotatorClient(*, credentials: typing.Optional[google.auth.credentials.Credentials] = None, transport: typing.Optional[typing.Union[str, google.cloud.vision_v1.services.image_annotator.transports.base.ImageAnnotatorTransport]] = None, client_options: typing.Optional[typing.Union[google.api_core.client_options.ClientOptions, dict]] = None, client_info: google.api_core.gapic_v1.client_info.ClientInfo = <google.api_core.gapic_v1.client_info.ClientInfo object>)用于对客户端图片执行 Google Cloud Vision API 检测任务的服务,可执行人脸、地标、徽标、标签和文本等内容的检测。ImageAnnotator 服务返回从图片中检测到的实体。
属性
transport
返回客户端实例使用的传输方式。
| 返回结果 | |
|---|---|
| 类型 | 说明 |
ImageAnnotatorTransport | 客户端实例使用的传输。 |
方法
ImageAnnotatorClient
ImageAnnotatorClient(*, credentials: typing.Optional[google.auth.credentials.Credentials] = None, transport: typing.Optional[typing.Union[str, google.cloud.vision_v1.services.image_annotator.transports.base.ImageAnnotatorTransport]] = None, client_options: typing.Optional[typing.Union[google.api_core.client_options.ClientOptions, dict]] = None, client_info: google.api_core.gapic_v1.client_info.ClientInfo = <google.api_core.gapic_v1.client_info.ClientInfo object>)实例化图片注释器客户端。
| 参数 | |
|---|---|
| 名称 | 说明 |
credentials |
Optional[google.auth.credentials.Credentials]
要附加到请求的授权凭据。这些凭据用于向服务标识应用;如果未指定任何凭据,客户端将尝试从环境中确定凭据。 |
transport |
Union[str, ImageAnnotatorTransport]
要使用的传输。如果设置为 None,系统会自动选择传输方式。 |
client_options |
Optional[Union[google.api_core.client_options.ClientOptions, dict]]
客户端的自定义选项。如果提供了 |
client_info |
google.api_core.gapic_v1.client_info.ClientInfo
用于随 API 请求一起发送用户代理字符串的客户端信息。如果值为 |
| 例外情况 | |
|---|---|
| 类型 | 说明 |
google.auth.exceptions.MutualTLSChannelError | 如果因任何原因导致相互 TLS 传输创建失败。 |
__exit__
__exit__(type, value, traceback)释放底层传输的资源。
async_batch_annotate_files
async_batch_annotate_files(
request: typing.Optional[
typing.Union[
google.cloud.vision_v1.types.image_annotator.AsyncBatchAnnotateFilesRequest,
dict,
]
] = None,
*,
requests: typing.Optional[
typing.MutableSequence[
google.cloud.vision_v1.types.image_annotator.AsyncAnnotateFileRequest
]
] = None,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> google.api_core.operation.Operation对常规文件(例如可能包含多页、每页可能包含多张图片的 PDF 文件)列表运行异步图片检测和注解。您可以通过 google.longrunning.Operations 接口检索进度和结果。Operation.metadata 包含 OperationMetadata(元数据)。Operation.response 包含 AsyncBatchAnnotateFilesResponse(结果)。
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import vision_v1
def sample_async_batch_annotate_files():
# Create a client
client = vision_v1.ImageAnnotatorClient()
# Initialize request argument(s)
request = vision_v1.AsyncBatchAnnotateFilesRequest(
)
# Make the request
operation = client.async_batch_annotate_files(request=request)
print("Waiting for operation to complete...")
response = operation.result()
# Handle the response
print(response)
| 参数 | |
|---|---|
| 名称 | 说明 |
request |
Union[google.cloud.vision_v1.types.AsyncBatchAnnotateFilesRequest, dict]
请求对象。多个异步文件注释请求会分批次,通过单个服务调用进行处理。 |
requests |
MutableSequence[google.cloud.vision_v1.types.AsyncAnnotateFileRequest]
必需。此批次的各个异步文件注解请求。这对应于 |
retry |
google.api_core.retry.Retry
指定应重试哪些错误(如果有)。 |
timeout |
float
相应请求的超时时间。 |
metadata |
Sequence[Tuple[str, str]]
应随请求一起作为元数据发送的字符串。 |
| 返回结果 | |
|---|---|
| 类型 | 说明 |
google.api_core.operation.Operation | 表示长时间运行的操作的对象。相应操作的结果类型将为 AsyncBatchAnnotateFilesResponse,即对异步批量文件注解请求的响应。 |
batch_annotate_files
batch_annotate_files(
request: typing.Optional[
typing.Union[
google.cloud.vision_v1.types.image_annotator.BatchAnnotateFilesRequest, dict
]
] = None,
*,
requests: typing.Optional[
typing.MutableSequence[
google.cloud.vision_v1.types.image_annotator.AnnotateFileRequest
]
] = None,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> google.cloud.vision_v1.types.image_annotator.BatchAnnotateFilesResponse对一批文件执行图片检测和注解的服务。目前仅支持“application/pdf”“image/tiff”和“image/gif”。 此服务最多从每个提供的文件中提取最多 5 个(在 AnnotateFileRequest.pages 中分别指定 5 个)框架 (gif) 或网页(pdf 或 tiff),并对提取的每个图片执行检测和注解。
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import vision_v1
def sample_batch_annotate_files():
# Create a client
client = vision_v1.ImageAnnotatorClient()
# Initialize request argument(s)
request = vision_v1.BatchAnnotateFilesRequest(
)
# Make the request
response = client.batch_annotate_files(request=request)
# Handle the response
print(response)
| 参数 | |
|---|---|
| 名称 | 说明 |
request |
Union[google.cloud.vision_v1.types.BatchAnnotateFilesRequest, dict]
请求对象。使用 BatchAnnotateFiles API 注释文件的请求列表。 |
requests |
MutableSequence[google.cloud.vision_v1.types.AnnotateFileRequest]
必需。文件注释请求列表。目前,BatchAnnotateFilesRequest 中仅支持使用一个 AnnotateFileRequest。这对应于 |
retry |
google.api_core.retry.Retry
指定应重试哪些错误(如果有)。 |
timeout |
float
相应请求的超时时间。 |
metadata |
Sequence[Tuple[str, str]]
应随请求一起作为元数据发送的字符串。 |
| 返回结果 | |
|---|---|
| 类型 | 说明 |
google.cloud.vision_v1.types.BatchAnnotateFilesResponse | 文件注释响应的列表。 |
batch_annotate_images
batch_annotate_images(
request: typing.Optional[
typing.Union[
google.cloud.vision_v1.types.image_annotator.BatchAnnotateImagesRequest,
dict,
]
] = None,
*,
requests: typing.Optional[
typing.MutableSequence[
google.cloud.vision_v1.types.image_annotator.AnnotateImageRequest
]
] = None,
retry: typing.Union[
google.api_core.retry.Retry, google.api_core.gapic_v1.method._MethodDefault
] = _MethodDefault._DEFAULT_VALUE,
timeout: typing.Union[float, object] = _MethodDefault._DEFAULT_VALUE,
metadata: typing.Sequence[typing.Tuple[str, str]] = ()
) -> google.cloud.vision_v1.types.image_annotator.BatchAnnotateImagesResponse对一批图片运行图片检测和注解。
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import vision_v1
def sample_batch_annotate_images():
# Create a client
client = vision_v1.ImageAnnotatorClient()
# Initialize request argument(s)
request = vision_v1.BatchAnnotateImagesRequest(
)
# Make the request
response = client.batch_annotate_images(request=request)
# Handle the response
print(response)
| 参数 | |
|---|---|
| 名称 | 说明 |
request |
Union[google.cloud.vision_v1.types.BatchAnnotateImagesRequest, dict]
请求对象。多个图片注释请求会分批次,通过单个服务调用进行处理。 |
requests |
MutableSequence[google.cloud.vision_v1.types.AnnotateImageRequest]
必需。此批次的各个图片注解请求。这对应于 |
retry |
google.api_core.retry.Retry
指定应重试哪些错误(如果有)。 |
timeout |
float
相应请求的超时时间。 |
metadata |
Sequence[Tuple[str, str]]
应随请求一起作为元数据发送的字符串。 |
| 返回结果 | |
|---|---|
| 类型 | 说明 |
google.cloud.vision_v1.types.BatchAnnotateImagesResponse | 对一个批量图片注释请求的响应。 |
common_billing_account_path
common_billing_account_path(billing_account: str) -> str返回完全限定的 billing_account 字符串。
common_folder_path
common_folder_path(folder: str) -> str返回完全限定的文件夹字符串。
common_location_path
common_location_path(project: str, location: str) -> str返回一个完全限定的位置字符串。
common_organization_path
common_organization_path(organization: str) -> str返回完全限定的组织字符串。
common_project_path
common_project_path(project: str) -> str返回完全限定的项目字符串。
from_service_account_file
from_service_account_file(filename: str, *args, **kwargs)使用提供的凭据文件创建此客户端的实例。
| 参数 | |
|---|---|
| 名称 | 说明 |
filename |
str
服务账号私钥 JSON 文件的路径。 |
| 返回结果 | |
|---|---|
| 类型 | 说明 |
ImageAnnotatorClient | 构建的客户端。 |
from_service_account_info
from_service_account_info(info: dict, *args, **kwargs)使用提供的凭据信息创建此客户端的实例。
| 参数 | |
|---|---|
| 名称 | 说明 |
info |
dict
服务账号私钥信息。 |
| 返回结果 | |
|---|---|
| 类型 | 说明 |
ImageAnnotatorClient | 构建的客户端。 |
from_service_account_json
from_service_account_json(filename: str, *args, **kwargs)使用提供的凭据文件创建此客户端的实例。
| 参数 | |
|---|---|
| 名称 | 说明 |
filename |
str
服务账号私钥 JSON 文件的路径。 |
| 返回结果 | |
|---|---|
| 类型 | 说明 |
ImageAnnotatorClient | 构建的客户端。 |
get_mtls_endpoint_and_cert_source
get_mtls_endpoint_and_cert_source(
client_options: typing.Optional[
google.api_core.client_options.ClientOptions
] = None,
)返回双向 TLS 的 API 端点和客户端证书源。
客户端证书来源按以下顺序确定:(1) 如果 GOOGLE_API_USE_CLIENT_CERTIFICATE 环境变量不是“true”,则客户端证书来源为 None。
(2) 如果提供了 client_options.client_cert_source,则使用提供的 client_options.client_cert_source;如果存在默认客户端证书来源,则使用默认客户端证书来源;否则,客户端证书来源为 None。
API 端点按以下顺序确定:(1) 如果提供了 client_options.api_endpoint,则使用提供的端点。
(2) 如果 GOOGLE_API_USE_CLIENT_CERTIFICATE 环境变量为“always”,则使用默认 mTLS 端点;如果该环境变量为“never”,则使用默认 API 端点;否则,如果存在客户端证书源,则使用默认 mTLS 端点,否则使用默认 API 端点。
如需了解详情,请访问 https://google.aip.dev/auth/4114。
| 参数 | |
|---|---|
| 名称 | 说明 |
client_options |
google.api_core.client_options.ClientOptions
客户端的自定义选项。此方法中只能使用 |
| 例外情况 | |
|---|---|
| 类型 | 说明 |
google.auth.exceptions.MutualTLSChannelError | 如果发生任何错误。 |
| 返回结果 | |
|---|---|
| 类型 | 说明 |
Tuple[str, Callable[[], Tuple[bytes, bytes]]] | 返回要使用的 API 端点和客户端证书来源。 |
parse_common_billing_account_path
parse_common_billing_account_path(path: str) -> typing.Dict[str, str]将 billing_account 路径解析为组成部分。
parse_common_folder_path
parse_common_folder_path(path: str) -> typing.Dict[str, str]将文件夹路径解析为组成部分。
parse_common_location_path
parse_common_location_path(path: str) -> typing.Dict[str, str]将位置路径解析为组成部分。
parse_common_organization_path
parse_common_organization_path(path: str) -> typing.Dict[str, str]将组织路径解析为组成部分。
parse_common_project_path
parse_common_project_path(path: str) -> typing.Dict[str, str]将项目路径解析为组成部分。
parse_product_path
parse_product_path(path: str) -> typing.Dict[str, str]将商品路径解析为组成部分。
parse_product_set_path
parse_product_set_path(path: str) -> typing.Dict[str, str]将 product_set 路径解析为组成部分。
product_path
product_path(project: str, location: str, product: str) -> str返回完全限定的产品字符串。
product_set_path
product_set_path(project: str, location: str, product_set: str) -> str返回完全限定的 product_set 字符串。