[英]Error running Google's Cloud Vision API Example (Face Detection)
I am trying to run the Face Detection Example in Google's Cloud Vision API. 我正在尝试在Google的Cloud Vision API中运行人脸检测示例。 I am trying to run [faces.py here][1]. 我正在尝试运行[faces.py here] [1]。
When I run the following: 当我运行以下命令时:
faces.py demo-picture.jpg faces.py demo-picture.jpg
below is the error I get: 以下是我得到的错误:
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
I guess my question is -- how do I do this: 我想我的问题是-我该怎么做:
Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. 否则,必须定义环境变量GOOGLE_APPLICATION_CREDENTIALS,指向指向定义凭据的文件。
You need to download the service-account key; 您需要下载服务帐号密钥; typically a JSON file. 通常是JSON文件。 If you have not created the credentials/obtained the key, follow the steps: 如果尚未创建凭据/未获取密钥,请按照以下步骤操作:
Go to your API manager; 转到您的API经理;
Create credentials; 创建凭证;
Choose "Service Account Key"; 选择“服务帐户密钥”;
Select "Key Type" as JSON. 选择“密钥类型”作为JSON。
After this point, you should obtain a JSON file. 此后,您应该获得一个JSON文件。
Once you obtain the key, go to your BASHRC (~/.bashrc) and add the following: 获取密钥后,转到BASHRC(〜/ .bashrc)并添加以下内容:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/JSON
Then restart your bash by exec bash
然后通过exec bash
重新启动exec bash
Now, re-run your faces.py. 现在,重新运行您的faces.py。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.