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(*, 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 個影格 (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傳回完整帳單帳戶字串。
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,
)傳回 mTLS 的 API 端點和用戶端憑證來源。
用戶端憑證來源的判斷順序如下:
(1) 如果 GOOGLE_API_USE_CLIENT_CERTIFICATE 環境變數不是「true」,則用戶端憑證來源為 None。
(2) 如果提供 client_options.client_cert_source,則使用提供的來源;如果存在預設用戶端憑證來源,則使用預設來源;否則用戶端憑證來源為 None。
API 端點的決定順序如下:
(1) 如果提供 client_options.api_endpoint,則使用提供的端點。
(2) 如果 GOOGLE_API_USE_CLIENT_CERTIFICATE 環境變數為「always」,請使用預設的 mTLS 端點;如果環境變數為「never」,請使用預設的 API 端點;否則,如果存在用戶端憑證來源,請使用預設的 mTLS 端點,否則請使用預設的 API 端點。
| 參數 | |
|---|---|
| 名稱 | 說明 |
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傳回完整產品組合字串。