예제 #1
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();
        }
예제 #2
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})");
        }