Skip to content

Instantly share code, notes, and snippets.

@kiyoaki
Last active February 23, 2016 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiyoaki/7e5760287b4664904828 to your computer and use it in GitHub Desktop.
Save kiyoaki/7e5760287b4664904828 to your computer and use it in GitHub Desktop.
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using Google.Apis.Services;
using Google.Apis.Vision.v1;
using Google.Apis.Vision.v1.Data;
namespace ComputerVisionAPI.Controllers
{
public class GoogleVisionApiController : ApiController
{
public async Task<BatchAnnotateImagesResponse> Get(string gsObjectName)
{
var service = new VisionService(new BaseClientService.Initializer
{
ApiKey = "xxxxx",
ApplicationName = "xxxxx"
});
var request = service.Images.Annotate(new BatchAnnotateImagesRequest
{
Requests = new[]
{
new AnnotateImageRequest
{
Image = new Image
{
Source = new ImageSource()
{
GcsImageUri = "gs://xxxxx/" + gsObjectName
}
},
Features = new[]
{
"LABEL_DETECTION",
"TEXT_DETECTION",
"FACE_DETECTION",
"LANDMARK_DETECTION",
"LOGO_DETECTION",
"SAFE_SEARCH_DETECTION",
"IMAGE_PROPERTIES"
}.Select(x=> new Feature { Type = x }).ToArray()
}
}
});
var response = await request.ExecuteAsync();
return response;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment