Head vs breakz

[code] - 이미지에서 글씨 찾기 구글 API / windows에서 본문

Head/Code

[code] - 이미지에서 글씨 찾기 구글 API / windows에서

headbreakz 2020. 4. 20. 20:09
from google.cloud import vision
import os,io


os.environ["GOOGLE_APPLICATION_CREDENTIALS"] ='구글에서받은.json'

# def detect_text(path):

client = vision.ImageAnnotatorClient()

with io.open(path, 'rb') as image_file:
    content = image_file.read()

image = vision.types.Image(content=content)

response = client.text_detection(image=image)
texts = response.text_annotations

print(texts)
     for text in texts:
         print("{}".format(text.description))   

        
file_name ='C:/Users/82107/Desktop/project/Images/final_image/circle_gray/3752.jpg'
detect_text(file_name)

    

이미지에서 글씨 추출을 위한 google API를 검색해서 진행하다보면, GOOGLE_APPLICATION_CREDENTIALS 문제를 만나게 되서 다양한 방법을 해보았다. 결국은 os.environ을 통해 code내에서 해결하는 방법이 현재 상황에서 가장 깔끔하게 해결 되었다. 

Comments