コード例 #1
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
        }
コード例 #2
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());
        }
コード例 #3
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());
            }
        }
コード例 #4
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");
            }
        }