0

我正在尝试在 Google 的 Cloud Vision API 中运行人脸检测示例。我正在尝试运行 [faces.py here][1]。

当我运行以下命令时:

faces.py 演示图片.jpg

以下是我得到的错误:

ubuntu@ubuntu-VirtualBox:~/Documents/code/python-    stuff/googleapis/cloudvisionapi/cloud-vision/python/face_detection$ python     faces.py demo-image.jpg 
Traceback (most recent call last):
  File "faces.py", line 121, in <module>
    main(args.input_image, args.output, args.max_results)
  File "faces.py", line 98, in main
    faces = detect_face(image, max_results)
  File "faces.py", line 62, in detect_face
    service = get_vision_service()
  File "faces.py", line 35, in get_vision_service
    credentials = GoogleCredentials.get_application_default()
  File "/home/ubuntu/.local/lib/python2.7/site-     packages/oauth2client/client.py", line 1398, in get_application_default
    return GoogleCredentials._get_implicit_credentials()
  File "/home/ubuntu/.local/lib/python2.7/site-    packages/oauth2client/client.py", line 1388, in _get_implicit_credentials
    raise ApplicationDefaultCredentialsError(ADC_HELP_MSG)
oauth2client.client.ApplicationDefaultCredentialsError: The Application     Default Credentials are not available. They are available if running in Google     Compute Engine. Otherwise, the environment variable     GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the     credentials. See https://developers.google.com/accounts/docs/application-    default-credentials for more information.
ubuntu@ubuntu-VirtualBox:~/Documents/code/python-    stuff/googleapis/cloudvisionapi/cloud-vision/python/face_detection$ 
  [1]: https://github.com/GoogleCloudPlatform/cloud-    vision/tree/master/python/face_detection

我想我的问题是——我该怎么做:

否则,必须定义环境变量 GOOGLE_APPLICATION_CREDENTIALS 指向定义凭据的文件。

4

1 回答 1

0

您需要下载服务帐户密钥;通常是 JSON 文件。如果您尚未创建凭证/获取密钥,请按照以下步骤操作:

转到您的 API 管理器;
创建凭据;
选择“服务帐户密钥”;
选择“密钥类型”作为 JSON。

在此之后,您应该获得一个 JSON 文件。

获得密钥后,转到您的 BASHRC (~/.bashrc) 并添加以下内容:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/JSON

然后重新启动你的bash exec bash

现在,重新运行你的 faces.py。

于 2016-06-16T02:59:56.750 回答