【问题标题】:Error running Google's Cloud Vision API Example (Face Detection)运行 Google 的 Cloud Vision API 示例(人脸检测)时出错
【发布时间】:2016-06-02 18:08:28
【问题描述】:

我正在尝试在 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 指向定义凭据的文件。

【问题讨论】:

    标签: python python-2.7 ubuntu google-cloud-vision


    【解决方案1】:

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

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

    此时,您应该获得一个 JSON 文件。

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

    然后重启你的 bash exec bash

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

    【讨论】:

    • export ... 行应该放在~/.bashrc 文件的末尾吗?
    • 通常,您添加到 ~/.bashrc 的任何额外/自定义行都到最后。但这取决于你。
    猜你喜欢
    • 1970-01-01
    • 2017-07-30
    • 2019-04-08
    • 2021-11-10
    • 2020-03-06
    • 2019-09-02
    • 2017-06-07
    • 2023-03-22
    • 2021-11-18
    相关资源
    最近更新 更多