public List <string> getMatches(string filePath) { string path = MapPath("~/My Project 25680-6d24c8bb9131.json"); //var credential = GoogleCredential.FromFile(path); //Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", ""); var output = new List <string>(); //var client = ImageAnnotatorClient.Create(credential); GoogleCredential googleCredential; using (Stream m = new FileStream(path, FileMode.Open)) googleCredential = GoogleCredential.FromStream(m); var channel = new Grpc.Core.Channel(ImageAnnotatorClient.DefaultEndpoint.Host, googleCredential.ToChannelCredentials()); var client = ImageAnnotatorClient.Create(channel); var image = Image.FromFile(filePath); var response = client.DetectLogos(image); foreach (var annotation in response) { if (annotation.Description != null) { output.Add(annotation.Description); } } return(output); }
public override async Task RunCommand(object sender) { var engine = (IAutomationEngineInstance)sender; var vAPICredentials = (string)await v_APICredentials.EvaluateCode(engine); string vFilePath = null; if (v_ImageType == "Filepath") { vFilePath = (string)await v_FilePath.EvaluateCode(engine); } else { Bitmap vBitmap = (Bitmap)await v_Bitmap.EvaluateCode(engine); vFilePath = engine.EngineContext.ProjectPath + "\\tempOCRBitmap.bmp"; FileStream imageStream = new FileStream(vFilePath, FileMode.OpenOrCreate); vBitmap.Save(imageStream, ImageFormat.Bmp); imageStream.Close(); } Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", vAPICredentials); string foundText = ""; GoogleImage image = GoogleImage.FromFile(vFilePath); ImageAnnotatorClient client = ImageAnnotatorClient.Create(); IReadOnlyList <EntityAnnotation> textAnnotations = client.DetectText(image); foundText = textAnnotations[0].Description; foundText.SetVariableValue(engine, v_OutputUserVariableName); }
/// <summary> /// Constructor for a feature extractor using Google Cloud Platform SDK, using a given annotator client, /// optimized to be used with a batch of images. /// </summary> /// <param name="imagePath"></param> /// <param name="client"></param> internal GcpFeatureExtractor(string imagePath, ImageAnnotatorClient client) { SetRotation(SKCodec.Create(imagePath).EncodedOrigin); var size = System.Drawing.Image.FromFile(imagePath).Size; Width = size.Width; Height = size.Height; _image = Image.FromFile(imagePath); _client = client; }
/// <summary> /// Constructor for a feature extractor using Google Cloud Platform SDK, optimized for analysing a single image. /// </summary> /// <param name="imagePath"></param> /// <param name="credentialsPath"></param> public GcpFeatureExtractor(string imagePath, string credentialsPath) { SetRotation(SKCodec.Create(imagePath).EncodedOrigin); var size = System.Drawing.Image.FromFile(imagePath).Size; Width = size.Width; Height = size.Height; var visionImage = Image.FromFile(imagePath); _client = new ImageAnnotatorClientBuilder() { CredentialsPath = credentialsPath }.Build(); _image = Image.FromFile(imagePath); }
public string doc_text_dection(string GVA_File_Path, string Credential_Path) { //var credential = GoogleCredential.FromFile(Credential_Path); Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "Your_Json_File_Name.json"); //Load the image file into memory var image = Image.FromFile(GVA_File_Path); // Instantiates a client ImageAnnotatorClient client = ImageAnnotatorClient.Create(); TextAnnotation text = client.DetectDocumentText(image); //Console.WriteLine($"Text: {text.Text}"); return($"Text: {text.Text}"); //return "test image..."; }
protected void Page_Load(object sender, EventArgs e) { // Instantiates a client var client = ImageAnnotatorClient.Create(); // Load the image file into memory var image = Image.FromFile(@"C:\Users\NecC\Downloads\69597698_2263657030613474_151965357500792832_n.jpg"); // Performs label detection on the image file var response = client.DetectLabels(image); foreach (var annotation in response) { if (annotation.Description != null) { Console.WriteLine(annotation.Description); } } }