public AnnotateImageResponse AnalyzeImage(Image image) { var client = new ImageAnnotatorClientBuilder(); client.CredentialsPath = ("HackGT.json"); var visClient = client.Build(); AnnotateImageRequest request = new AnnotateImageRequest { Image = image, Features = { new Feature { Type = Feature.Types.Type.LabelDetection }, new Feature { Type = Feature.Types.Type.LogoDetection }, new Feature { Type = Feature.Types.Type.ImageProperties } } }; return(visClient.Annotate(request)); }
/// <summary> /// Constructor. /// </summary> /// <param name="credentialsPath">Path to the credentials JSON file for /// access to Google VisionAI.</param> /// <param name="connString">Connection string used to connect to /// desired database.</param> public OCRTool(string credentialsPath, string connString) { _credentialsPath = credentialsPath; ImageAnnotatorClientBuilder clientBuiler = new ImageAnnotatorClientBuilder { CredentialsPath = credentialsPath }; _client = clientBuiler.Build(); _connectionString = connString; }
private ImageAnnotatorClient CreateClient(string apiKey) { if (string.IsNullOrWhiteSpace(apiKey)) { return(ImageAnnotatorClient.Create()); } var builder = new ImageAnnotatorClientBuilder(); builder.JsonCredentials = apiKey; return(builder.Build()); }
public void JwtAccessToken_GrpcClient() { Image image = LoadResourceImage("SydneyOperaHouse.jpg"); ImageAnnotatorClientBuilder builder = new ImageAnnotatorClientBuilder { // Making sure we have no scopes so that a JWT is sent. Scopes = new string[0] }; var client = builder.Build(); var result = client.DetectLandmarks(image); Assert.NotEmpty(result); }
/// <summary> /// This function is used to create a new instance of ImageAnnotatorClient /// </summary> /// <returns></returns> public ImageAnnotatorClient CreateImageAnnotatorClient() { var credPath = _googleCloudConfig.CredentialsPath; Log.Information("Instantiates a client, cred {CredPath}", credPath); var clientBuilder = new ImageAnnotatorClientBuilder { CredentialsPath = credPath }; var client = clientBuilder.Build(); return(client); }
private static ImageAnnotatorClient MakeClient() { var credPath = BotSettings.GoogleCloudCredentialsPath.SanitizeSlash(); Log.Information($"Instantiates a client, cred {credPath}"); var clientBuilder = new ImageAnnotatorClientBuilder { CredentialsPath = credPath }; var client = clientBuilder.Build(); return(client); }
private static ImageAnnotatorClient MakeClient() { var credPath = BotSettings.GoogleCloudCredentialsPath.SanitizeSlash(); Log.Information("Instantiates a client, cred {CredPath}", credPath); var clientBuilder = new ImageAnnotatorClientBuilder { CredentialsPath = credPath }; var client = clientBuilder.Build(); VideoIntelligenceService = new VideoIntelligenceServiceClientBuilder() { CredentialsPath = credPath }.Build(); return(client); }
static void GoogleVisionRequest(string path) { ImageAnnotatorClientBuilder builder = new ImageAnnotatorClientBuilder { CredentialsPath = @"C:\Users\d4gei\Workspace\ScanAndHoardData\scanandhoard-11700d373751.json" }; ImageAnnotatorClient client = builder.Build(); var image = Image.FromFile(path); TextAnnotation text = client.DetectDocumentText(image); string fileName = path + ".txt"; using (StreamWriter writer = new StreamWriter(fileName)) { writer.Write(text.Text); } Console.WriteLine($"Text: {text.Text}"); foreach (var page in text.Pages) { foreach (var block in page.Blocks) { string box = string.Join(" - ", block.BoundingBox.Vertices.Select(v => $"({v.X}, {v.Y})")); Console.WriteLine($"Block {block.BlockType} at {box}"); foreach (var paragraph in block.Paragraphs) { box = string.Join(" - ", paragraph.BoundingBox.Vertices.Select(v => $"({v.X}, {v.Y})")); Console.WriteLine($" Paragraph at {box}"); foreach (var word in paragraph.Words) { Console.WriteLine($" Word: {string.Join("", word.Symbols.Select(s => s.Text))}"); } } } } }
public static async Task <string> MakeOCRRequest(string imageFilePath) { string credentialsPath = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"); var image = Image.FromFile(imageFilePath); ImageAnnotatorClientBuilder builder = new ImageAnnotatorClientBuilder { CredentialsPath = credentialsPath }; try { ImageAnnotatorClient client = builder.Build(); var response = await client.DetectTextAsync(image); string contentString = response.ToString(); return(JToken.Parse(contentString).ToString()); } catch (Exception e) { Console.WriteLine("\n" + e.Message); return("error"); } }