Esempio n. 1
0
 public void GetImage()
 {
     var bytes = DocumentDbHelper
                 .GetImageAsync("5f34f4d0-8f0c-4b95-9b86-64bba863f74a")
                 .Result
                 .Bytes;
 }
Esempio n. 2
0
        public async Task <HttpResponseMessage> GetById(string id)
        {
            var image = await DocumentDbHelper
                        .GetImageAsync(id);

            if (image == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(
                    image.Bytes
                    )
            };

            result.Headers.CacheControl = new CacheControlHeaderValue
            {
                Public = true,
                MaxAge = TimeSpan.FromMinutes(30)
            };;

            result.Content.Headers.ContentType =
                // bit of an assumption but will suffice for the demo
                new MediaTypeHeaderValue("image/jpg");

            return(result);
        }
Esempio n. 3
0
        public void TestDocumentDbWrangling()
        {
            var newGuid = Guid.NewGuid();

            var image = new Image
            {
                Created     = DateTime.Now,
                Description = "Test description",
                id          = newGuid,
                Name        = "Test name",
                // use our fluffy test image
                Bytes = File.ReadAllBytes("Images/dog-medium-landing-hero.jpg")
            };

            Console.WriteLine($"{newGuid} written to database!");

            DocumentDbHelper.AddImageToDbAsync(
                image
                ).Wait();

            // get the image back
            var imageBack = DocumentDbHelper
                            .GetImageAsync($"{newGuid}")
                            .Result;

            imageBack.Created          = DateTime.Now;
            imageBack.IllegalWatermark = true;

            // Run the custom vision service
            //CustomerVisionHelper
            //    .RunCustomVisionService(imageBack);

            // can we call out to cognitive services?
            VisionApiHelper
            .AdornImageWithVisionMetadataAsync(imageBack);

            // change date and update the image
            DocumentDbHelper
            .UpdateImage(imageBack);

            // delete the image
            // get the image back
            DocumentDbHelper
            .DeleteImageAsync($"{newGuid}").Wait();
        }
Esempio n. 4
0
        public static void Run(
            [ServiceBusTrigger("images", AccessRights.Manage, Connection = "ServiceBusConnection")]
            string imageId, TraceWriter log)
        {
            log.Info($"New image detected from the queue: {imageId}");

            var image = DocumentDbHelper
                        .GetImageAsync($"{imageId}").Result;

            // if we can't find it in the database, do nothing
            if (image == null)
            {
                log.Info($"This image wasn't found in the database.");
                return;
            }

            VisionApiHelper
            .AdornImageWithVisionMetadataAsync(
                image
                );

            CustomerVisionHelper
            .RunCustomVisionService(image);

            // insert azureML code here

            //ThumbnailHelper
            //    .ApplyThumbnail(image);

            DocumentDbHelper
            .UpdateImage(image);

            if (image.Tags == null)
            {
                return;
            }

            log.Info($"Adorned image tags to it from cognitive services ({string.Join(",", image.Tags)})");
            log.Info($"And this description: ({image.PredictedCaption})");
        }
Esempio n. 5
0
        public async Task <IHttpActionResult> GetImages()
        {
            var images = DocumentDbHelper
                         .GetAllImageIds()
                         .Select(async ev => await DocumentDbHelper.GetImageAsync(ev))
                         .ToArray();

            await Task.WhenAll(tasks : images);

            var i2 = images
                     .Select(t => t.Result)
                     .Where(i => !string.IsNullOrWhiteSpace(i.PredictedCaption));

            // null off the binary data for all images

            foreach (var image in i2)
            {
                image.Bytes = null;
            }



            return(Ok(i2));
        }