private void button1_Click(object sender, EventArgs e)
        {
            LabelExtraction barcode = new LabelExtraction();
            OpenFileDialog fileDialog = new OpenFileDialog();

            // allow image files only
            fileDialog.Filter = "Image Files (JPEG,GIF,BMP,PNG)|*.jpg;*.jpeg;*.gif;*.bmp;*.png|JPEG Files(*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF Files(*.gif)|*.gif|BMP Files(*.bmp)|*.bmp|PNG Files(*.png)|*.png";

            // check if we opened a valid file
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                Bitmap sourceImage = new Bitmap(fileDialog.FileName);
                // Get label positions
                List<Rectangle> results = barcode.GetLabels(sourceImage);
                Bitmap processImage = barcode.Image;

                Graphics gSource = Graphics.FromImage(sourceImage);
                Graphics gProcess = Graphics.FromImage(processImage);

                // draw the rectangles of the label positions
                foreach (Rectangle rectangle in results)
                {
                    gSource.DrawRectangle(Pens.Yellow, rectangle);
                    gProcess.DrawRectangle(Pens.Yellow, rectangle);
                }

                picOriginal.Picture = null;
                picFilter.Picture = null;

                // save image for debugging
                sourceImage.Save(@"C:\Temp\labels_source.png");

                //// save image for debugging
                //processImage.Save(@"C:\Temp\labels_process.png");

                //picOriginal.Picture = @"C:\Temp\labels_source.png";
                //picFilter.Picture = @"C:\Temp\labels_process.png";

                //System.Diagnostics.Process.Start(@"C:\Temp\");
                //Close();
            }
            else
                Close();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            if (CheckParameters(args))
            {
                // start stop watch to measure execution time
                System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
                stopwatch.Start();

                LabelExtraction barcode = new LabelExtraction();

                if (args[1].Substring(args[1].Length - 1) != "\\")
                    args[1] = args[1] + "\\";

                Console.WriteLine("Label Extraction");
                Console.WriteLine("-------------------------");

                int numberOfLabelsFound = barcode.SaveLabels(args[1], new Bitmap(args[0]));

                stopwatch.Stop();
                TimeSpan timeElapsed = TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds);

                Console.WriteLine("Successfull!");
                Console.WriteLine("Found " + numberOfLabelsFound + " labels. Elapsed time: " + timeElapsed.ToString());

                // open the folder
                System.Diagnostics.Process.Start(args[1]);

                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Label Extraction");
                Console.WriteLine("-------------------------");
                Console.WriteLine("Usage:");
                Console.WriteLine("ExtractCodeBar.exe <source.img> <path to extract>");
                Console.ReadLine();
            }
        }