Example #1
0
 /// <summary>Snippet for BatchAnnotateImages</summary>
 public void BatchAnnotateImages_RequestObject()
 {
     // Snippet: BatchAnnotateImages(BatchAnnotateImagesRequest,CallSettings)
     // Create client
     ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.Create();
     // Initialize request argument(s)
     BatchAnnotateImagesRequest request = new BatchAnnotateImagesRequest
     {
         Requests = { },
     };
     // Make the request
     BatchAnnotateImagesResponse response = imageAnnotatorClient.BatchAnnotateImages(request);
     // End snippet
 }
        public void AnnotateImage_BadImage()
        {
            var client  = ImageAnnotatorClient.Create();
            var request = new AnnotateImageRequest
            {
                Image    = s_badImage,
                Features = { new Feature {
                                 Type = Feature.Types.Type.FaceDetection
                             } }
            };
            var exception = Assert.Throws <AnnotateImageException>(() => client.Annotate(request));

            Assert.Equal((int)Code.InvalidArgument, exception.Response.Error.Code);
        }
Example #3
0
        public static List <string> VerificarImagem(byte[] imagem)
        {
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", HttpContext.Current.Server.MapPath(@"~/App_Data/CloudVisionConfig.json"));
            // Instantiates a client
            var client = ImageAnnotatorClient.Create();
            // Load the image file into memory
            var image        = Google.Cloud.Vision.V1.Image.FromBytes(imagem);
            var responseLbl  = client.DetectLabels(image);
            var responseProp = client.DetectImageProperties(image);

            List <EntityAnnotation> animals = responseLbl.Take(8).ToList();

            for (int i = 0; i < animals.Count; i++)
            {
                if (string.Compare(animals[i].Description, "dog", true) == 0 ||
                    string.Compare(animals[i].Description, "black", true) == 0 ||
                    string.Compare(animals[i].Description, "brown", true) == 0 ||
                    string.Compare(animals[i].Description, "carnivore", true) == 0 ||
                    string.Compare(animals[i].Description, "canidae", true) == 0 ||
                    string.Compare(animals[i].Description, "mammal", true) == 0 ||
                    string.Compare(animals[i].Description, "vertebrate", true) == 0 ||
                    string.Compare(animals[i].Description, "dog breed", true) == 0 ||
                    string.Compare(animals[i].Description, "dog breed", true) == 0 ||
                    string.Compare(animals[i].Description, "bear", true) == 0 ||
                    string.Compare(animals[i].Description, "wolf", true) == 0 ||
                    string.Compare(animals[i].Description, "guard dog", true) == 0 ||
                    string.Compare(animals[i].Description, "companion dog", true) == 0 ||
                    string.Compare(animals[i].Description, "hunting dog", true) == 0 ||
                    string.Compare(animals[i].Description, "fawn", true) == 0 ||
                    string.Compare(animals[i].Description, "snout", true) == 0 ||
                    string.Compare(animals[i].Description, "sporting group", true) == 0 ||
                    string.Compare(animals[i].Description, "wolf", true) == 0 ||
                    string.Compare(animals[i].Description, "giant dog breed", true) == 0 ||
                    string.Compare(animals[i].Description, "molosser ", true) == 0 ||
                    string.Compare(animals[i].Description, "working dog ", true) == 0 ||
                    string.Compare(animals[i].Description, "muscle", true) == 0 ||
                    string.Compare(animals[i].Description, "sporting group", true) == 0 ||
                    string.Compare(animals[i].Description, "toy dog", true) == 0 ||
                    string.Compare(animals[i].Description, "rare breed (dog)", true) == 0 ||
                    string.Compare(animals[i].Description, "russkiy dog", true) == 0
                    )
                {
                    animals.RemoveAt(i);
                    i--;
                }
            }
            List <string> descricoes = animals.ConvertAll <string>(c => c.Description);

            return(descricoes);
        }
Example #4
0
        //**Método que convierte a texto la imagen a cargada**//
        private void btnConvertirImagen_Click(object sender, EventArgs e)
        {
            var client   = ImageAnnotatorClient.Create();
            var image    = Google.Cloud.Vision.V1.Image.FromFile(fileDlg.FileName);
            var response = client.DetectText(image);

            txtResultado.Text = response.ElementAt(0).Description;
            string[] renglones = txtResultado.Text.Split('\n');
            txtResultado.Text = "";
            foreach (var renglon in renglones)
            {
                txtResultado.Text = string.Concat(txtResultado.Text, renglon);
                txtResultado.Text = string.Concat(txtResultado.Text, Environment.NewLine);
            }
        }
Example #5
0
        // [END vision_logo_detection_gcs]

        // [START vision_logo_detection]
        private static object DetectLogos(string filePath)
        {
            var client   = ImageAnnotatorClient.Create();
            var image    = Image.FromFile(filePath);
            var response = client.DetectLogos(image);

            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                {
                    Console.WriteLine(annotation.Description);
                }
            }
            return(0);
        }
Example #6
0
        public static void VisionUseGoogle(System.Drawing.Image img)
        {
            string p = $"{Environment.CurrentDirectory}{ConfigurationManager.AppSettings.Get(VisionConstants.GoogleAppCredentials)}";

            Environment.SetEnvironmentVariable(VisionConstants.GoogleAppKey, p);
            using (MemoryStream memStream = new MemoryStream())
            {
                img.Save(memStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                memStream.Seek(0, SeekOrigin.Begin);

                ImageAnnotatorClient client = ImageAnnotatorClient.Create();
                Image image    = Image.FromStream(memStream);
                var   response = client.DetectLabels(image);
            }
        }
        public void DetectLogos()
        {
            Image image = LoadResourceImage("Chrome.png");
            // Snippet: DetectLogos
            ImageAnnotatorClient             client = ImageAnnotatorClient.Create();
            IReadOnlyList <EntityAnnotation> logos  = client.DetectLogos(image);

            foreach (EntityAnnotation logo in logos)
            {
                Console.WriteLine($"Description: {logo.Description}");
            }
            // End snippet
            Assert.Equal(1, logos.Count);
            Assert.Equal("Google Chrome", logos[0].Description);
        }
        /// <summary>
        /// Handle the intent.
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public override async Task <string> HandleAsync(ConvRequest req)
        {
            // Create the client and ask for labels from Vision API ML service.
            var visionClient = ImageAnnotatorClient.Create();
            var labels       = await visionClient.DetectLabelsAsync(Image.FromUri(_conversation.State.FocusedImage.Url), maxResults : 10);

            // Order labels by score, and prepare the label descriptions for DialogFlow
            var toSay = labels
                        .OrderByDescending(x => x.Score)
                        .TakeWhile((x, i) => i <= 2 || x.Score > 0.75)
                        .Select(x => x.Description)
                        .ToList();

            return(DialogflowApp.Tell(CombineList(toSay, "This picture is labelled", "Nothing at all, apparently. Which is odd.")));
        }
Example #9
0
        //Method to extract text from image using Google Cloud vision API
        public void CallGoogleVisionAPI()
        {
            //var certificate = new X509Certificate2("//Users//apurva//Downloads//snapio-228915-3e71201609c7.p12", "notasecret", X509KeyStorageFlags.Exportable);
            var client   = ImageAnnotatorClient.Create();
            var image    = Image.FromFile("//Users//apurva//Desktop//photo");
            var response = client.DetectText(image);

            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                {
                    text = (annotation.Description);
                }
            }
        }
        private static object DetectSafeSearch(Image image)
        {
            // [START vision_safe_search_detection]
            // [START vision_safe_search_detection_gcs]
            var client   = ImageAnnotatorClient.Create();
            var response = client.DetectSafeSearch(image);

            Console.WriteLine("Adult: {0}", response.Adult.ToString());
            Console.WriteLine("Spoof: {0}", response.Spoof.ToString());
            Console.WriteLine("Medical: {0}", response.Medical.ToString());
            Console.WriteLine("Violence: {0}", response.Violence.ToString());
            // [END vision_safe_search_detection_gcs]
            // [END vision_safe_search_detection]
            return(0);
        }
        public ScanRecognizer()
        {
            var googleCredentials = Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS");

            if (googleCredentials == null)
            {
                Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", Path.Combine(Directory.GetCurrentDirectory(),
                                                                                                  "Resources", "CloudVision.json"));
            }
            context = new ImageContext();
            context.LanguageHints.Add("ru");
            context.LanguageHints.Add("uk");
            googleClient     = ImageAnnotatorClient.Create();
            imageTransformer = new ImageTransformer();
        }
Example #12
0
        // [END vision_text_detection]

        // [START vision_logo_detection_gcs]
        private static object DetectLogos(string bucketName, string objectName)
        {
            var client   = ImageAnnotatorClient.Create();
            var image    = Image.FromStorageUri($"gs://{bucketName}/{objectName}");
            var response = client.DetectLogos(image);

            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                {
                    Console.WriteLine(annotation.Description);
                }
            }
            return(0);
        }
Example #13
0
        static void runner(string filePath)
        {
            // Load an image from a local file.
            var image    = Image.FromFile(filePath);
            var client   = ImageAnnotatorClient.Create();
            var response = client.DetectText(image);

            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                {
                    Console.WriteLine(annotation.Description);
                }
            }
        }
Example #14
0
        public IList <Feature> Identify(IFormFile file)
        {
            var imagem = Image.FromStream(file.OpenReadStream());
            var client = ImageAnnotatorClient.Create();

            var response = client.DetectLabels(imagem);

            foreach (var annontation in response)
            {
                var feature = new Feature(annontation.Description, annontation.Score);

                _list.Add(feature);
            }

            return(_list);
        }
Example #15
0
        private void ProcessFile(string filePath)
        {
            var image    = Image.FromFile(filePath);
            var client   = ImageAnnotatorClient.Create();
            var response = client.DetectDocumentText(image);

            if (response == null || response.Text == null)
            {
                //Output.Add($"WARNING : Unable to process file {filePath}");
                return;
            }

            var text = response.Text;

            SaveToOutput(filePath, text);
        }
Example #16
0
        public async Task <IActionResult> Index(List <IFormFile> files)
        {
            var url        = @"C:\src\ImageAnalysis\key.json";
            var credential = GoogleCredential.FromFile(url);
            var file       = files.FirstOrDefault();
            var stream     = file?.OpenReadStream();
            var channel    = new Grpc.Core.Channel(ImageAnnotatorClient.DefaultEndpoint.ToString(), credential.ToChannelCredentials());
            var client     = ImageAnnotatorClient.Create(channel);
            var image      = await Image.FromStreamAsync(stream);

            var props = await client.DetectLabelsAsync(image);

            var json = JsonConvert.SerializeObject(props);

            return(View(json));
        }
Example #17
0
        /// <summary>
        /// Google Cloud Vision.
        /// Install-Package Google.Cloud.Vision.V1 -Pre
        /// gratuito si se hacen menos de 1000 OCR por mes
        /// </summary>
        public void VisionGoogleOCRProcess()
        {
            // Load an image from a local file.
            var image    = Image.FromFile(FilesDirectory.myDni);
            var client   = ImageAnnotatorClient.Create();
            var response = client.DetectText(image);


            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                {
                    Console.WriteLine(annotation.Description);
                }
            }
        }
Example #18
0
        public string ReadTextFromImage(string imagePath)
        {
            var client   = ImageAnnotatorClient.Create();
            var image    = Google.Cloud.Vision.V1.Image.FromFile(imagePath);
            var response = client.DetectText(image);

            foreach (var annotation in response)
            {
                if (!String.IsNullOrEmpty(annotation.Description))
                {
                    return(annotation.Description);
                }
            }

            return(null);
        }
        public void DetectImageProperties()
        {
            Image image = LoadResourceImage("SchmidtBrinPage.jpg");
            // Snippet: DetectImageProperties
            ImageAnnotatorClient client        = ImageAnnotatorClient.Create();
            ImageProperties      properties    = client.DetectImageProperties(image);
            ColorInfo            dominantColor = properties.DominantColors.Colors.OrderByDescending(c => c.PixelFraction).First();

            Console.WriteLine($"Dominant color in image: {dominantColor}");
            // End snippet

            Assert.Equal(0.18, dominantColor.PixelFraction, 2);
            Assert.Equal(new Color {
                Red = 16, Green = 13, Blue = 8
            }, dominantColor.Color);
        }
        public static void Main(string[] args)
        {
            var client = ImageAnnotatorClient.Create();

            var image = Image.FromFile("images/003.jpg");

            var response = client.DetectLabels(image);

            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                {
                    Console.WriteLine($"Score: {annotation.Score} Description: {annotation.Description}");
                }
            }
        }
Example #21
0
        //Detecta el cliente del cheque aplicando filtros de optimización de imagen
        private string DetectClienteBBVA(String selectedFile)
        {
            var photoBytes = File.ReadAllBytes(selectedFile);

            //**Realiza procesamiento de imagen previo a la conversion**//
            using (var inStream = new MemoryStream(photoBytes))
            {
                using (var outStream = new MemoryStream())
                {
                    using (ImageFactory imageFactory = new ImageFactory(false))
                    {
                        //Filtros
                        var img = imageFactory.Load(inStream)
                                  .Resize(new Size(697, 289))
                                  .Crop(new Rectangle(25, 186, 164, 52))
                                  .Format(new PngFormat {
                            Quality = 100
                        })
                                  .Resolution(1024, 1024)
                                  .Filter(MatrixFilters.GreyScale)
                                  .Contrast(50)
                                  .Tint(Color.White)


                                  //Se guarda en memoria los cambios
                                  .Save(outStream);
                    }

                    //Realiza la conversión con la imagen a texto a partir de los cambios realizados
                    var          image  = Google.Cloud.Vision.V1.Image.FromStream(outStream);
                    var          client = ImageAnnotatorClient.Create();
                    ImageContext ic     = new ImageContext();
                    ic.LanguageHints.Add("es");
                    var response = client.DetectDocumentText(image);
                    if (response != null)
                    {
                        Cliente = response.Text;
                        return(Cliente);
                    }
                    else
                    {
                        Cliente = "Error de lectura";
                        return(Cliente);
                    }
                }
            }
        }
Example #22
0
        // [END vision_safe_search_detection]

        // [START vision_image_property_detection_gcs]
        private static object DetectProperties(string bucketName, string objectName)
        {
            var    client   = ImageAnnotatorClient.Create();
            var    image    = Image.FromStorageUri($"gs://{bucketName}/{objectName}");
            var    response = client.DetectImageProperties(image);
            string header   = "Red\tGreen\tBlue\tAlpha\n";

            foreach (var color in response.DominantColors.Colors)
            {
                Console.Write(header);
                header = "";
                Console.WriteLine("{0}\t{0}\t{0}\t{0}",
                                  color.Color.Red, color.Color.Green, color.Color.Blue,
                                  color.Color.Alpha);
            }
            return(0);
        }
        /// <summary>
        /// 画像から文字情報を検出する
        /// </summary>
        /// <returns>文字情報</returns>
        public string ReadTextFromImage(System.Drawing.Image img)
        {
            Image  target   = ConvertImageFormatForV1(img);
            string ret      = "";
            var    client   = ImageAnnotatorClient.Create();
            var    response = client.DetectText(target);

            foreach (var annotation in response)
            {
                if (annotation.Description != null)
                {
                    ret += annotation.Description + System.Environment.NewLine;
                    Console.WriteLine(annotation.Description);
                }
            }
            return(ret);
        }
        public static void Main(string[] args)
        {
            // Instantiates a client
            var client = ImageAnnotatorClient.Create();
            // Load the image file into memory
            var image = Image.FromFile("wakeupcat.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);
                }
            }
        }
Example #25
0
        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...";
        }
        public void DetectLocalizedObjects()
        {
            Image image = Image.FromUri("https://cloud.google.com/vision/docs/images/bicycle_example.png");
            // Snippet: DetectLocalizedObjects
            ImageAnnotatorClient client = ImageAnnotatorClient.Create();
            IReadOnlyList <LocalizedObjectAnnotation> annotations = client.DetectLocalizedObjects(image);

            foreach (LocalizedObjectAnnotation annotation in annotations)
            {
                string poly = string.Join(" - ", annotation.BoundingPoly.Vertices.Select(v => $"({v.X}, {v.Y})"));
                Console.WriteLine(
                    $"Name: {annotation.Name}; ID: {annotation.Mid}; Score: {annotation.Score}; Bounding poly: {poly}");
            }
            // End snippet

            // TODO: Add assertions about the annotations.
        }
Example #27
0
        // [END vision_face_detection_gcs]

        // [START vision_face_detection]
        private static object DetectFaces(string filePath)
        {
            var client   = ImageAnnotatorClient.Create();
            var image    = Image.FromFile(filePath);
            var response = client.DetectFaces(image);
            int count    = 1;

            foreach (var faceAnnotation in response)
            {
                Console.WriteLine("Face {0}:", count++);
                Console.WriteLine("  Joy: {0}", faceAnnotation.JoyLikelihood);
                Console.WriteLine("  Anger: {0}", faceAnnotation.AngerLikelihood);
                Console.WriteLine("  Sorrow: {0}", faceAnnotation.SorrowLikelihood);
                Console.WriteLine("  Surprise: {0}", faceAnnotation.SurpriseLikelihood);
            }
            return(0);
        }
        public void DetectText()
        {
            Image image = LoadResourceImage("Ellesborough.png");
            // Snippet: DetectText
            ImageAnnotatorClient             client          = ImageAnnotatorClient.Create();
            IReadOnlyList <EntityAnnotation> textAnnotations = client.DetectText(image);

            foreach (EntityAnnotation text in textAnnotations)
            {
                Console.WriteLine($"Description: {text.Description}");
            }
            // End snippet

            var descriptions = textAnnotations.Select(t => t.Description).ToList();

            Assert.Contains("Ellesborough", descriptions);
        }
Example #29
0
        // [START vision_face_detection_gcs]
        private static object DetectFaces(string bucketName, string objectName)
        {
            var client   = ImageAnnotatorClient.Create();
            var image    = Image.FromStorageUri($"gs://{bucketName}/{objectName}");
            var response = client.DetectFaces(image);
            int count    = 1;

            foreach (var faceAnnotation in response)
            {
                Console.WriteLine("Face {0}:", count++);
                Console.WriteLine("  Joy: {0}", faceAnnotation.JoyLikelihood);
                Console.WriteLine("  Anger: {0}", faceAnnotation.AngerLikelihood);
                Console.WriteLine("  Sorrow: {0}", faceAnnotation.SorrowLikelihood);
                Console.WriteLine("  Surprise: {0}", faceAnnotation.SurpriseLikelihood);
            }
            return(0);
        }
Example #30
0
        // [END vision_image_property_detection_gcs]

        // [START vision_image_property_detection]
        private static object DetectProperties(string filePath)
        {
            var    client   = ImageAnnotatorClient.Create();
            var    image    = Image.FromFile(filePath);
            var    response = client.DetectImageProperties(image);
            string header   = "Red\tGreen\tBlue\tAlpha\n";

            foreach (var color in response.DominantColors.Colors)
            {
                Console.Write(header);
                header = "";
                Console.WriteLine("{0}\t{0}\t{0}\t{0}",
                                  color.Color.Red, color.Color.Green, color.Color.Blue,
                                  color.Color.Alpha);
            }
            return(0);
        }