使用用戶端程式庫為影片加上註解
本快速入門導覽課程將介紹 Video Intelligence API。在這個快速入門導覽課程中,您將設定 Google Cloud 專案和授權,然後要求 Video Intelligence 為影片加上註解。
事前準備
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Video Intelligence API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
安裝用戶端程式庫
Go
go get cloud.google.com/go/videointelligence/apiv1
Java
如果您使用 Maven,請將下列指令新增至 pom.xml 檔案。如要進一步瞭解 BOM,請參閱「Google Cloud Platform 程式庫 BOM」。
如果您使用 Gradle,請在依附元件中加入以下指令:
如果您使用 sbt,請在依附元件中加入以下指令:
如果您使用 Visual Studio Code 或 IntelliJ,可以透過下列 IDE 外掛程式,將用戶端程式庫新增至專案:
這些外掛程式會提供其他功能,例如服務帳戶的金鑰管理功能。詳情請參閱各外掛程式的說明文件。
Node.js
安裝程式庫前,請確認您已設定適當的 Node.js 開發環境。
npm install @google-cloud/video-intelligence
Python
安裝程式庫前,請確認您已設定適當的 Python 開發環境。
pip install --upgrade google-cloud-videointelligence
其他語言
C#:請按照用戶端程式庫頁面上的 C# 設定操作說明完成相關步驟,然後參閱「.NET 適用的 Video Intelligence 參考文件」。
PHP:請按照用戶端程式庫頁面上的 PHP 設定操作說明完成相關步驟,然後參閱 PHP 適用的 Video Intelligence 參考文件。
Ruby:請按照用戶端程式庫頁面上的 Ruby 設定操作說明完成相關步驟,然後參閱「Ruby 適用的 Video Intelligence 參考文件」。
設定驗證方法
-
安裝 Google Cloud CLI,然後 使用聯合身分登入 gcloud CLI。登入後,執行下列指令來初始化 Google Cloud CLI:
gcloud init -
為使用者帳戶建立本機驗證憑證:
gcloud auth application-default login
如果系統傳回驗證錯誤,請確認您已 使用聯合身分登入 gcloud CLI。
登入畫面會隨即顯示。登入後,您的憑證會儲存在 ADC 使用的本機憑證檔案中。
標籤偵測
現在您可以使用 Video Intelligence API,要求影片或影片片段的資訊,例如標籤偵測。執行下列程式碼,發出第一項影片標籤偵測要求:
Go
Java
Node.js
執行範例前,請確認已設定適當的 Node.js 開發環境。
Python
執行範例前,請確認您已設定適當的 Python 開發環境。
其他語言
C#:請按照用戶端程式庫頁面上的 C# 設定操作說明完成相關步驟,然後參閱 .NET 適用的 Video Intelligence 參考文件。
PHP: 請按照用戶端程式庫頁面上的 PHP 設定操作說明完成相關步驟,然後參閱「PHP 適用的 Video Intelligence 參考文件」。
Ruby:請按照用戶端程式庫頁面上的 Ruby 設定操作說明完成相關步驟,然後參閱「Ruby 適用的 Video Intelligence 參考文件」。
恭喜!您已將第一個要求傳送至 Video Intelligence API。
還順利嗎?
清除所用資源
為了避免系統向您的 Google Cloud 帳戶收取本頁面所用資源的費用,請按照下列步驟操作。
- 使用 Google Cloud console 刪除不需要的專案。