Google Vision API의 가장 기본적인 텍스트 감지 및 OCR (광학 문자 인식) 프로그램을 Python으로 실행하려고합니다. 내 소스 코드는이 API에 대한 Google 클라우드 튜토리얼에서 가져온 것입니다 그리고 그것은 다음과 같다 :Python 프로그램에서 Google Vision API를 사용하는 방법은 무엇입니까?
나는 다음과 같은 오류가 발생하지만import io
from google.cloud import vision
from google.cloud.vision import types
def detect_text(file):
"""Detects text in the file."""
client = vision.ImageAnnotatorClient()
with io.open(file, 'rb') as image_file:
content = image_file.read()
image = types.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations
print('Texts:')
for text in texts:
print('\n"{}"'.format(text.description))
vertices = (['({},{})'.format(vertex.x, vertex.y)
for vertex in text.bounding_poly.vertices])
print('bounds: {}'.format(','.join(vertices)))
file_name = "prescription.jpg"
detect_text(file_name)
:
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or
explicitly create credential and re-run the application. For more
information, please see
https://developers.google.com/accounts/docs/application-default-credentials.
이 이상한 이유는
1) 새로운 서비스 계정을 만들었습니다.
2) .bash_profile에 export GOOGLE_APPLICATION_CREDENTIALS="/Users/User/PycharmProjects/GCP-OCR/Trial-e046e4bc6ce1.json"
을 추가했습니다. (이 p의 Pycharm 파일에 json 파일을 넣었습니다. 방금 한 가지 이상한 일은 json 파일의 개인 키가 약 20 줄인 반면 아마도 약 1 줄이 될 것이라고 예상하는 것입니다.
이 버그를 해결하고 프로그램을 실행하려면 어떻게해야합니까? 나는 단순히 내 소스 코드에
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/Users/User/PycharmProjects/GCP-OCR/Trial-e046e4bc6ce1.json"
를 추가하면 문제가 해결되는 방식으로
.
감사합니다. 예, 확실히 .bash_profile을 업데이트했지만 'echo'로 체크 아웃하지 않았습니다. 가까운 시일 내에 다시이 문제를 해결할 수 있다면이 사소한 기술적 인 문제를 해결할 수있을 것입니다. – Universalis