public static void DetectBackground(String filepath) { Console.WriteLine("Running Heuristic Background Detector"); var bg_color = Heuristics.DetectBackground(new System.Drawing.Bitmap(filepath)); Console.WriteLine("R,G,B : " + bg_color.Red + "," + bg_color.Green + "," + bg_color.Blue); var display = new ImageViewer(new Emgu.CV.Image <Bgr, Byte>(600, 600, bg_color), "Heuristic Background Detection Result"); display.ShowDialog(); }
public void DetectBackgroundTest() { var path1 = "PicassoUnitTest/DetectBackgroundTest/249-238-32.png"; var filepath1 = Path.Combine(Drive.GetDriveRoot(), path1); Bitmap image1 = new Bitmap(filepath1); Bgr expectedBackGround = new Bgr(249, 238, 32); Bgr actualBackGround = Heuristics.DetectBackground(image1, 10); Assert.IsTrue(Utility.IsEqual(expectedBackGround, actualBackGround)); }
public void ExtractImagesTest() { //var path1 = "PicassoUnitTest/PreprocessingTest/10images.jpg"; //var path2 = "PicassoUnitTest/PreprocessingTest/12images.jpg"; //var path3 = "PicassoUnitTest/PreprocessingTest/19images.jpg"; var path1 = "PicassoUnitTest/PreprocessingTest/17images.jpg"; var filepath1 = Path.Combine(Drive.GetDriveRoot(), path1); Bitmap image1 = new Bitmap(filepath1); Bgr backgroundColor = Heuristics.DetectBackground(image1, 10); Bitmap mask1 = Preprocessing.FloodFill(image1, 100, 100, 50, backgroundColor); List <Bitmap> List1 = new List <Bitmap>(); List1 = Preprocessing.ExtractImages(image1, mask1); Assert.IsTrue(List1.Count == 17); }
public void DetectBackgroundTest() { // Create a Square Point[] shred = new Point[4]; shred[0] = new Point(0, 0); shred[1] = new Point(0, 99); shred[2] = new Point(10, 99); shred[3] = new Point(10, 0); // Create an Original Image var original = new Image <Bgr, Byte>(100, 100, new Bgr(Color.HotPink)); original.FillConvexPoly(shred, new Bgr(Color.Gray)); var expected = new Bgr(Color.HotPink); Console.WriteLine("Performing Heuristic Background Detection"); var actual = Heuristics.DetectBackground(original.ToBitmap()); Assert.IsTrue(Picasso.Utility.IsEqual(expected, actual)); }
public static string Preprocess_Final(string filepath, string outPath, bool displayMode, int thresholding) { StringBuilder sb = new StringBuilder(); displayMode = false; sb.AppendLine("Loading Image : " + filepath); Bitmap load = new Bitmap(filepath); var start = DateTime.Now; sb.AppendLine("Running Background Detection ..."); Bgr backgroundColor = Heuristics.DetectBackground(load, 20); sb.AppendLine("Detected Background : " + backgroundColor.ToString()); sb.AppendLine("Detected Background Completed in " + (DateTime.Now - start).TotalSeconds.ToString() + " seconds"); var backgroundGuess = new Image <Bgr, Byte>(100, 100, backgroundColor); sb.AppendLine("Running Shred Extraction "); sb.AppendLine("Image Size : " + load.Height * load.Width + " Pixels"); string imagesrc = filepath; Bitmap source = new Bitmap(imagesrc); sb.AppendLine("beginning flood fill..."); Point startPoint = Heuristics.GetStartingFloodFillPoint(source, Color.FromArgb(255, (int)backgroundColor.Red, (int)backgroundColor.Green, (int)backgroundColor.Blue)); Bitmap Mask = Preprocessing.FloodFill(source, startPoint.X, startPoint.Y, 50, backgroundColor); sb.AppendLine("flood fill complete..."); sb.AppendLine("extracting objects..."); List <Bitmap> extractedobj = Preprocessing.ExtractImages(source, Mask); sb.AppendLine("Extracted " + extractedobj.Count + " objects"); // Prompt for input directory and Write to file Console.Write("Enter Output Directory (Default is Working): "); string directory = outPath;// Console.ReadLine(); if (String.IsNullOrEmpty(directory) || !Directory.Exists(directory)) { sb.AppendLine("Writing to Working Directory"); directory = string.Empty; } else { directory += "\\"; } sb.AppendLine("Rotating Images"); int ii = 0; int maxLen = extractedobj.Count.ToString().Length; foreach (Bitmap bm in extractedobj) { Bitmap bm2 = Preprocessing.Orient(bm); bm2.Save(directory + "image" + ii.ToString("D" + maxLen) + ".png"); ii++; } sb.AppendLine("Wrote Files To Disk"); return(sb.ToString()); }
public static void Run(string filepath) { Console.WriteLine("Loading Image : " + filepath); Bitmap load = new Bitmap(filepath); var start = DateTime.Now; Console.WriteLine("Running Background Detection ..."); Bgr backgroundColor = Heuristics.DetectBackground(load, 20); Console.WriteLine("Detected Background : " + backgroundColor.ToString()); Console.WriteLine("Detected Background Completed in " + (DateTime.Now - start).TotalSeconds.ToString() + " seconds"); var backgroundGuess = new Image <Bgr, Byte>(100, 100, backgroundColor); ImageViewer display = new ImageViewer(backgroundGuess, "Mask"); display.ShowDialog(); Console.WriteLine("Running Shred Extraction "); Console.WriteLine("Image Size : " + load.Height * load.Width + " Pixels"); string imagesrc = filepath; Bitmap source = new Bitmap(imagesrc); Console.WriteLine("beginning flood fill..."); Bitmap Mask = Preprocessing.FloodFill(source, 100, 100, 50, backgroundColor); Console.WriteLine("flood fill complete..."); Console.WriteLine("extracting objects..."); List <Bitmap> extractedobj = Preprocessing.ExtractImages(source, Mask); Console.WriteLine("Extracted " + extractedobj.Count + " objects"); // Display to the User var result = new Image <Bgr, Byte>(source); Image <Bgra, Byte> image = new Image <Bgra, byte>(Mask); ImageViewer maskView = new ImageViewer(image, "Mask"); var scale = Math.Min(800.0 / result.Height, 800.0 / result.Width); maskView.ImageBox.SetZoomScale(scale, new Point(10, 10)); maskView.ShowDialog(); // Display Each Shred That is extracted foreach (var shred in extractedobj) { Image <Bgra, Byte> cvShred = new Image <Bgra, byte>(shred); ImageViewer box = new ImageViewer(cvShred, "Mask"); var shredScale = Math.Min(800.0 / cvShred.Height, 800.0 / cvShred.Width); display.ImageBox.SetZoomScale(shredScale, new Point(10, 10)); box.ShowDialog(); } // Prompt for input directory and Write to file Console.Write("Enter Output Directory (Default is Working): "); string directory = Console.ReadLine(); if (!Directory.Exists(directory)) { Console.WriteLine("Writing to Working Directory"); directory = string.Empty; } else { directory += "\\"; } Console.WriteLine("wrote files to disk"); int ii = 0; foreach (Bitmap bm in extractedobj) { Bitmap bm2 = Preprocessing.Orient(bm); bm2.Save(directory + "image" + ii++ + ".png"); } }