簡體   English   中英

運行Google的Cloud Vision API示例(人臉檢測)時出錯

[英]Error running Google's Cloud Vision API Example (Face Detection)

我正在嘗試在Google的Cloud Vision API中運行人臉檢測示例。 我正在嘗試運行[faces.py here] [1]。

當我運行以下命令時:

faces.py demo-picture.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,指向指向定義憑據的文件。

您需要下載服務帳號密鑰; 通常是JSON文件。 如果尚未創建憑據/未獲取密鑰,請按照以下步驟操作:

轉到您的API經理;
創建憑證;
選擇“服務帳戶密鑰”;
選擇“密鑰類型”作為JSON。

此后,您應該獲得一個JSON文件。

獲取密鑰后,轉到BASHRC(〜/ .bashrc)並添加以下內容:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/JSON

然后通過exec bash重新啟動exec bash

現在,重新運行您的faces.py。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM