コード例 #1
0
        public async Task <Dictionary <int, string> > RunG(DescRequest request)
        {
            var computerVision =
                new ComputerVisionClient(new ApiKeyServiceClientCredentials(ConfigHelper.GetSubscriptionKey()))
            {
                Endpoint = "https://francecentral.api.cognitive.microsoft.com/"
            };
            var analysisList = new Dictionary <int, string>();

            var storageClient =
                await StorageClient.CreateAsync(
                    GoogleCredential.FromFile(HttpContext.Current.Server.MapPath("~\\keys.json")));

            for (var i = 0; i < request.Count; i++)
            {
                var imageStream = new MemoryStream();

                await storageClient.DownloadObjectAsync("galeata_magica_123", $"{request.Filename}/{i}.jpg",
                                                        imageStream);

                var image = Image.FromStream(imageStream);

                var analysis =
                    await computerVision.AnalyzeImageInStreamAsync(image.ToStream(ImageFormat.Jpeg), Features);

                var text = analysis.Description.Captions.FirstOrDefault()?.Text ?? string.Empty;

                analysisList.Add(i, text);
            }
            return(analysisList);
        }
コード例 #2
0
 public async Task <IHttpActionResult> DescriptionG(DescRequest request)
 {
     return(Ok(await new DescHandler().RunG(request)));
 }