使用用戶端程式庫為影片加上註解
本快速入門導覽課程將介紹 Video Intelligence API。在本快速入門導覽課程中,您將設定 Google Cloud 專案和授權,然後要求 Video Intelligence 註解影片。
事前準備
- 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
-
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.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
安裝 Google Cloud CLI。
-
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
-
執行下列指令,初始化 gcloud CLI:
gcloud init -
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.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
安裝 Google Cloud CLI。
-
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
-
執行下列指令,初始化 gcloud CLI:
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。 完成後,執行下列指令來初始化 Google Cloud CLI:
gcloud init若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
-
如果您使用本機殼層,請為使用者帳戶建立本機驗證憑證:
gcloud auth application-default login
如果您使用 Cloud Shell,則不需要執行這項操作。
如果系統傳回驗證錯誤,且您使用外部識別資訊提供者 (IdP),請確認您已 使用聯合身分登入 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 刪除不需要的專案。