コード例 #1
0
        public void FloodFillTest()
        {
            // Create a Square
            Point[] square = new Point[4];
            square[0] = new Point(25, 25);
            square[1] = new Point(75, 25);
            square[2] = new Point(75, 75);
            square[3] = new Point(25, 75);

            // Create an Original Image
            var original = new Image <Bgr, Byte>(100, 100, new Bgr(255, 0, 0));

            original.FillConvexPoly(square, new Bgr(Color.Green));

            // Create an Expected Output Image
            var expected = new Emgu.CV.Image <Bgr, Byte>(100, 100, new Bgr(Preprocessing.MASK_COLOR));

            expected.FillConvexPoly(square, new Bgr(Color.White));

            // Perform the Flood fill
            Console.WriteLine("Perform Flood Fill ... ");
            var actual = new Emgu.CV.Image <Bgr, Byte>(Preprocessing.FloodFill(original.ToBitmap(), 0, 0, 1, new Bgr(255, 0, 0)));

            bool identical = true;

            for (int ii = 0; ii < expected.Width; ii++)
            {
                for (int jj = 0; jj < expected.Height; jj++)
                {
                    identical = identical && (Utility.IsEqual(expected[jj, ii], actual[jj, ii]));
                }
            }

            Assert.IsTrue(identical);
        }
コード例 #2
0
        public static void GetBlobsFromImage(String filepath)
        {
            string        imagesrc     = filepath;
            Bitmap        source       = new Bitmap(imagesrc);
            Bitmap        Mask         = Preprocessing.FloodFill(source, 100, 100, 100);
            List <Bitmap> extractedobj = Preprocessing.ExtractImages(source, Mask);
            // Display to the User
            var result = new Image <Bgr, Byte>(source);

            int ii = 0;

            foreach (Bitmap bm in extractedobj)
            {
                Bitmap bm2 = Preprocessing.Orient(bm);
                bm2.Save("image" + ii++ + ".jpg");
            }

            Emgu.CV.Image <Bgra, Byte> image = new Image <Bgra, byte>(Mask);
            ImageViewer display = new ImageViewer(image, "Mask");
            var         scale   = Math.Min(800.0 / (double)result.Height, 800.0 / (double)result.Width);

            display.ImageBox.SetZoomScale(scale, new Point(10, 10));
            display.ShowDialog();

            // Save to Working Dir
        }
コード例 #3
0
        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 = Picasso.Heuristics.DetectBackground(image1, 10);
            Bitmap mask1           = Preprocessing.FloodFill(image1, 100, 100, 50, backgroundColor);

            List <Bitmap> List1 = new List <Bitmap>();

            List1 = Picasso.Preprocessing.ExtractImages(image1, mask1);
            Assert.IsTrue(List1.Count == 17);
        }
コード例 #4
0
        public static void GetBlobsFromImage(String filepath, Bgr color)
        {
            string imagesrc = filepath;
            Bitmap source   = new Bitmap(imagesrc);

            System.Console.WriteLine("beginning flood fill...");
            Bitmap Mask = Preprocessing.FloodFill(source, 100, 100, 120, color);

            System.Console.WriteLine("flood fill complete...");
            System.Console.WriteLine("extracting objects...");
            List <Bitmap> extractedobj = Preprocessing.ExtractImages(source, Mask);

            System.Console.WriteLine("Extracted " + extractedobj.Count + " objects");
            // Display to the User
            var result = new Image <Bgr, Byte>(source);

            int ii = 0;

            foreach (Bitmap bm in extractedobj)
            {
                //  Bitmap bm2 = Preprocessing.Orient(bm);
                bm.Save("image" + ii++ + ".png");
            }

            System.Console.WriteLine("wrote files to disk");

            Emgu.CV.Image <Bgra, Byte> image = new Image <Bgra, byte>(Mask);
            ImageViewer display = new ImageViewer(image, "Mask");
            var         scale   = Math.Min(800.0 / (double)result.Height, 800.0 / (double)result.Width);

            display.ImageBox.SetZoomScale(scale, new Point(10, 10));
            display.ShowDialog();

            // Display Each Shred That is extracted
            foreach (var shred in  extractedobj)
            {
                Emgu.CV.Image <Bgra, Byte> cvShred = new Image <Bgra, byte>(shred);
                ImageViewer box        = new ImageViewer(cvShred, "Mask");
                var         shredScale = Math.Min(800.0 / (double)cvShred.Height, 800.0 / (double)cvShred.Width);
                display.ImageBox.SetZoomScale(shredScale, new Point(10, 10));
                box.ShowDialog();
            }

            // Save to Working Dir
        }
コード例 #5
0
        public static void GetFloodFillMask(String filepath, Bgr color)
        {
            string imagesrc = filepath;
            var    start    = System.DateTime.Now;
            Bitmap source   = new Bitmap(imagesrc);
            Bitmap mask     = Preprocessing.FloodFill(source, 0, 0, 110, color);

            // Display to the User
            var         result  = new Image <Bgr, Byte>(mask);
            ImageViewer display = new ImageViewer(result, "Mask");
            var         scale   = Math.Min(800.0 / (double)result.Height, 800.0 / (double)result.Width);

            display.ImageBox.SetZoomScale(scale, new Point(10, 10));
            var stop       = System.DateTime.Now;
            var difference = stop - start;

            Console.WriteLine("Total Time :" + difference.ToString());
            Console.WriteLine("Total Pixels: " + source.Width * source.Height);
            display.ShowDialog();
        }
コード例 #6
0
        public static void Run(string filepath)
        {
            System.Console.WriteLine("Loading Image : " + filepath);
            Bitmap load = new Bitmap(filepath);

            var start = DateTime.Now;

            System.Console.WriteLine("Running Background Detection ...");
            Bgr backgroundColor = Picasso.Heuristics.DetectBackground(load, 20);

            System.Console.WriteLine("Detected Background : " + backgroundColor.ToString());
            System.Console.WriteLine("Detected Background Completed in " + (DateTime.Now - start).TotalSeconds.ToString() + " seconds");
            Color sample = Color.FromArgb(255, (int)backgroundColor.Red, (int)backgroundColor.Green, (int)backgroundColor.Blue);

            System.Drawing.Point startFill = Heuristics.GetStartingFloodFillPoint(load, sample);
            var         backgroundGuess    = new Image <Bgr, Byte>(startFill.X, startFill.Y, backgroundColor);
            ImageViewer display            = new ImageViewer(backgroundGuess, "Mask");

            display.ShowDialog();

            System.Console.WriteLine("Running Shred Extraction ");
            System.Console.WriteLine("Image Size : " + load.Height * load.Width + " Pixels");

            string imagesrc = filepath;
            Bitmap source   = new Bitmap(imagesrc);

            System.Console.WriteLine("beginning flood fill...");
            Bitmap Mask = Preprocessing.FloodFill(source, 100, 100, 50, backgroundColor);

            System.Console.WriteLine("flood fill complete...");
            System.Console.WriteLine("extracting objects...");
            List <Bitmap> extractedobj = Preprocessing.ExtractImages(source, Mask);

            System.Console.WriteLine("Extracted " + extractedobj.Count + " objects");


            // Display to the User
            var result = new Image <Bgr, Byte>(source);



            Emgu.CV.Image <Bgra, Byte> image = new Image <Bgra, byte>(Mask);
            ImageViewer maskView             = new ImageViewer(image, "Mask");
            var         scale = Math.Min(800.0 / (double)result.Height, 800.0 / (double)result.Width);

            maskView.ImageBox.SetZoomScale(scale, new Point(10, 10));
            maskView.ShowDialog();

            // Display Each Shred That is extracted
            foreach (var shred in extractedobj)
            {
                Emgu.CV.Image <Bgra, Byte> cvShred = new Image <Bgra, byte>(shred);
                ImageViewer box        = new ImageViewer(cvShred, "Mask");
                var         shredScale = Math.Min(800.0 / (double)cvShred.Height, 800.0 / (double)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 += "\\";
            }

            System.Console.WriteLine("wrote files to disk");
            int           ii = 0;
            StringBuilder sb = new StringBuilder();

            foreach (Bitmap bm in extractedobj)
            {
                Bitmap bm2 = Preprocessing.Orient(bm);
                sb.Append(ii.ToString() + " : width: " + bm.Width + " height: " + bm.Height + " area: " +
                          bm.Height * bm.Width);
                bm2.Save(directory + "image" + ii++ + ".png");
            }
            using (StreamWriter sw = new StreamWriter(directory + "imageqr.txt", true))
            {
                sw.WriteLine(sb.ToString());
            }
        }
コード例 #7
0
        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());
        }
コード例 #8
0
        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");
            }
        }