Beispiel #1
0
        public void UniTest1()
        {
            var result = CognitiveServicesCaller.AnalyzeImage("http://dreamatico.com/data_images/girl/girl-8.jpg",
                                                              "96595dcf7af241c6a97da31fab5919ec");

            Assert.NotNull(result);
            Assert.NotNull(result.Tags[0]);
        }
Beispiel #2
0
        public IActionResult Create(IFormFile file)
        {
            if (file.Length > 0)
            {
                var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition);
                var filename = Guid.NewGuid() + parsedContentDisposition.FileName.Substring(parsedContentDisposition.FileName.LastIndexOf('.')).Replace("\"", "");

                var container = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=garbagecollectrstorage;AccountKey=wrhFgNhmUkCl+VtrIAxsGbgR5Gjl6+MgqIqCsiIfACkzB/4x5TFhojt9U4W4bEazRS61oS++jM7CF++L25COww==").CreateCloudBlobClient().GetContainerReference("images");
                container.CreateIfNotExists();

                var blockBlob = container.GetBlockBlobReference(filename);

                using (var fileStream = file.OpenReadStream())
                {
                    blockBlob.UploadFromStream(fileStream);
                }

                var result = CognitiveServicesCaller.AnalyzeImage(filename, "96595dcf7af241c6a97da31fab5919ec");

                var things = new ThingsManager(DbContext).GetThingFromTags(result.Tags);

                var allMaterials = new MaterialManager(this.DbContext).GetAll();

                var createImageResult = new CreateImageResult
                {
                    DbThings       = things,
                    PossibleThings = result.Tags,
                    AllMaterials   = allMaterials,
                    IsPerson       = result.Faces.Any()
                };

                return(new JsonResult(createImageResult));
            }

            return(new BadRequestResult());
        }