public static void ResizeImageToWithinAnalysisLimitsTest(string filename)
        {
            Bitmap sourceImage = Program.LoadImage(Program.LoadImageType.Test, filename);

            Assert.False(ImageTransforms.IsWithinAnalysisLimits(sourceImage));

            Bitmap resizedImage = ImageTransforms.ResizeToWithinAnalysisLimits(sourceImage);

            Assert.True(ImageTransforms.IsWithinAnalysisLimits(resizedImage));
        }
Beispiel #2
0
        static void CreateAppraisals(PostToTwitterMode postToTwitterMode, int numberOfAppraisals)
        {
            Console.WriteLine("Getting collection listing");

            Art art = new Art(new IArtSource[] { new HarvardArtMuseum(), new MetropolitanMuseumOfArt() });

            IEnumerable <Art.Object> responseObjects = art.GetRandomObjects(numberOfAppraisals);

            Console.WriteLine("Found " + responseObjects.Count() + " results");

            int objectCounter = 0;

            foreach (Art.Object responseObject in responseObjects)
            {
                Console.WriteLine("-----------------------------------------------------------------------");

                string imageUrl = responseObject.imageURL;
                Console.WriteLine("image url: " + imageUrl);

                string fullListingURL = responseObject.listingURL;
                Console.WriteLine("Listing page: " + fullListingURL);

                Bitmap originalImage = Web.DownloadImage(imageUrl);

                if (originalImage != null)
                {
                    Bitmap resizedImage = ImageTransforms.ResizeToWithinAnalysisLimits(originalImage);

                    if (Directory.Exists("images"))
                    {
                        string originalDestinationFilePath = @"images/sourceImage" + objectCounter + ".jpg";
                        originalImage.Save(originalDestinationFilePath);

                        string resizedDestinationFilePath = @"images/resizedImage" + objectCounter + ".jpg";
                        resizedImage.Save(resizedDestinationFilePath);
                    }

                    ComputerVisionService.AnalysisBlob analysisBlob = ComputerVisionService.GetAnalysisBlob(resizedImage);

                    string tagString = "";
                    foreach (string tag in analysisBlob.generalAnalysisResult.Description.Tags)
                    {
                        tagString += tag + ", ";
                    }
                    Console.WriteLine("Tags: " + tagString);

                    string accentColor = ColorTable.GetClosestColorName(analysisBlob.generalAnalysisResult.Color.AccentColor);

                    Console.WriteLine("Foreground: " + analysisBlob.generalAnalysisResult.Color.DominantColorForeground + " Background: " + analysisBlob.generalAnalysisResult.Color.DominantColorBackground + " Accent: " + accentColor);

                    if (analysisBlob.generalAnalysisResult.Categories != null)
                    {
                        string categoryString = "";
                        foreach (Category category in analysisBlob.generalAnalysisResult.Categories)
                        {
                            categoryString += category.Name + ", ";
                        }
                        Console.WriteLine("Categories: " + categoryString);
                    }

                    Appraisal appraisal     = CreateAppraisal(originalImage, analysisBlob);
                    string    tweetableText = GetTweetableText(appraisal.comment, responseObject.listingURL, responseObject.artSourceHashTag);

                    if (Directory.Exists("images"))
                    {
                        string destinationFilePath = @"images/finalImage" + objectCounter + ".jpg";
                        appraisal.image.Save(destinationFilePath);

                        using (StreamWriter file = File.CreateText(@"images/comment" + objectCounter + ".txt"))
                        {
                            file.WriteLine(tweetableText);
                        }
                    }

                    if (postToTwitterMode == PostToTwitterMode.Yes)
                    {
                        TweetAppraisal(appraisal.image, tweetableText);
                    }
                }

                objectCounter++;
            }
        }