*[구글 클라우드] Vision API 사용하기

(1) GCP에서 프로젝트 생성

(2) GCP에서 compute engine 생성 (VM인스턴스)

(3) GCP에서 Vision API 검색 후 추가

(4) compute engine 에서 서비스 계정키 생성 (json 파일로)

(5) 서버에 접속할 클라이언트 환경에서 서비스 계정키 등록

export GOOGLE_APPLICATION_CREDENTIALS=서비스계정path

(6) 클라이언트 환경에서 아래 파이썬 코드를 실행 (끝)

import io

def detect_text(path):
    from google.cloud import vision
    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

    return texts

image_path = "/Users/mezzaninegwak/html/x_1_resized.jpg"

result = detect_text(image_path)

print(result)
반응형

+ Recent posts