Google Cloud Vision gRPC API를 호출하여 이미지를 분석(레이블, 텍스트, 얼굴 등)하는 형식화된 인터페이스입니다.
Google Cloud Vision은 이미지를 분석하여 레이블, 텍스트, 얼굴 및 랜드마크와 같은 인사이트를 반환합니다. gRPC API는 google.cloud.vision.v1.ImageAnnotator 서비스를 통해 제공되며, TLS를 통해 vision.googleapis.com:443에서 접근하고, 주요 메서드는 단일 호출로 이미지 배치에 주석을 추가하는 BatchAnnotateImages입니다.
요청은 TsgcGRPCVisionBatchAnnotateImagesRequest로 작성됩니다. AddRequest를 호출하여 이미지(gs:// 이미지의 경우 Image.Source.GcsImageUri)를 추가하고, AddFeature를 호출하여 기능을 요청하며, FeatureType(예: LABEL_DETECTION)과 MaxResults를 설정합니다.
아래 예제는 서비스 계정 JWT로 인증하고, Vision 호스트에 대해 TsgcHTTP2Client 위에 TsgcGRPCClient를 연결하고, authorization Bearer 메타데이터를 설정한 후, gs:// 이미지에서 레이블 감지를 실행하기 위해 BatchAnnotateImages를 호출합니다.
TsgcHTTP2Client *oHTTP2 = new TsgcHTTP2Client();
oHTTP2->Host = "vision.googleapis.com";
oHTTP2->Port = 443;
oHTTP2->TLS = true;
TsgcGRPCClient *oGRPC = new TsgcGRPCClient();
oGRPC->Client = oHTTP2;
// service-account JWT authentication
oGRPC->GoogleCloudOptions->JWT->KeyFile = "service-account.json";
oGRPC->GoogleCloudOptions->JWT->API_Endpoint = "https://vision.googleapis.com/";
oGRPC->DefaultMetadata->AddValue("authorization", "Bearer " + oGRPC->GoogleCloudOptions->JWT->Token);
// build the typed request and call the method
TsgcGRPCVisionBatchAnnotateImagesRequest *oRequest = new TsgcGRPCVisionBatchAnnotateImagesRequest();
TsgcGRPCVisionAnnotateImageRequest *oImage = oRequest->AddRequest();
oImage->Image->Source->GcsImageUri = "gs://my-bucket/photo.jpg";
oImage->AddFeature("LABEL_DETECTION", 10);
TsgcGRPCResponse *oResponse = oGRPC->Call("google.cloud.vision.v1.ImageAnnotator", "BatchAnnotateImages", oRequest->ToBytes());
ShowMessage(oResponse->DataString);
delete oRequest;
| Name | 설명 |
|---|---|
| BatchAnnotateImages | 이미지 배치에 대해 이미지 감지 및 주석을 실행하여 요청된 기능(레이블, 텍스트, 얼굴 등)을 반환합니다. |
작동하는 샘플은 데모 폴더 Demos/21.GRPC/13.Vision에서 제공되며, BatchAnnotateImages 메서드로 인증하고 이미지에서 레이블 감지를 실행하는 방법을 보여줍니다.