目标
在本示例中,您将使用 Google Vision API 检测图片中的人脸。为了证明自己已正确检测到人脸,您将借助相应数据在每个人脸周围画一个方框。
费用
在本文档中,您将使用 Google Cloud的以下收费组件:
- Cloud Vision
如需根据您的预计使用量来估算费用,请使用价格计算器。
准备工作
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
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 Google Cloud Vision 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. -
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 Google Cloud Vision 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. - 设置您的环境以便使用应用默认凭据。
-
设置语言特定的任务和工具:
C#
- 安装 Google 客户端库。
- 安装 Visual Studio 2012/2015。
Java
- 安装 Java。
- API 参考文档。
下载并安装 Apache Maven 构建系统。构建项目时,Maven 会确保安装 Google API 客户端库和 Vision API 客户端库,因为我们已将它们包含在
pom.xml中。...
Node.js
- 安装 Google 客户端库。
- 安装 node.js。
- API 参考文档。
安装 npm 和 node-canvas。示例代码包含
package.json,用于使用npm install命令安装所有依赖项。请注意,您可能还需要安装 node-canvas 的其他依赖项;如需了解详情,请参阅 node-canvas 安装文档。
PHP
- 安装 Google 客户端库。
- 安装 PHP 和 Composer。
- API 参考文档。
- 安装并启用 PHP 版 GD。
Python
- 安装 Google 客户端库。
- 安装 Python。
- API 参考文档。
- 安装 pillow。
Ruby
- 安装 Google 客户端库。
- 安装 Ruby 和