Esempio n. 1
0
        public static List <TagSuggestion> RequestVisionAnalysis(string imageFilePath)
        {
            if (client == null)
            {
                SetVisionAuthViaDialog();
            }
            if (client == null)
            {
                return(new List <TagSuggestion>());
            }

            var req = new AnnotateImageRequest()
            {
                Image = Image.FromFile(imageFilePath)
            };

            req.AddAllFeatures();

            var res = client.Annotate(req);

            return(ParseAnnotations(res));
        }
Esempio n. 2
0
        public static Dictionary <string, List <TagSuggestion> > RequestBatchVisionAnalysis(IEnumerable <string> paths)
        {
            if (client == null)
            {
                SetVisionAuthViaDialog();
            }
            if (client == null)
            {
                return(new Dictionary <string, List <TagSuggestion> >());
            }
            var result = new Dictionary <string, List <TagSuggestion> >();

            var req            = new List <AnnotateImageRequest>();
            var imageFilePaths = new List <string>(paths);

            for (int i = 0; i < imageFilePaths.Count; i++)
            {
                var reqItem = new AnnotateImageRequest();
                reqItem.Image = Image.FromFile(imageFilePaths[i]);
                reqItem.AddAllFeatures();
                req.Add(reqItem);
            }
            try
            {
                var batchResponse = client.BatchAnnotateImages(req);
                for (int i = 0; i < imageFilePaths.Count; i++)
                {
                    var res = batchResponse.Responses[i];
                    result.Add(imageFilePaths[i], ParseAnnotations(res));
                }
            }
            catch (Exception e)
            {
                MessageBox.Show($"vision API has encountered an error: \n\n {e}");
            }
            return(result);
        }