public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            // create an instance of BarCodeReader class and read barcode file
            BarCodeReader barCodeReader = new BarCodeReader(dataDir + "Region.png", DecodeType.Code39Standard);

            // Try to recognize all possible barcodes in the image
            while (barCodeReader.Read())
            {
                // Get the region information
                BarCodeRegion region = barCodeReader.GetRegion();
                if (region != null)
                {
                    // Display x and y coordinates of barcode detected
                    Point[] point = region.Points;
                    Console.WriteLine("Top left coordinates: X = " + point[0].X + ", Y = " + point[0].Y);
                    Console.WriteLine("Top right coordinates: X = " + point[1].X + ", Y = " + point[1].Y);
                    Console.WriteLine("Bottom right coordinates: X = " + point[2].X + ", Y = " + point[2].Y);
                    Console.WriteLine("Bottom left coordinates: X = " + point[3].X + ", Y = " + point[3].Y);
                }
                Console.WriteLine("Codetext: " + barCodeReader.GetCodeText());
            }
            // Close reader
            barCodeReader.Close();
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_ManageAndOptimizeBarcodeRecognition();

            // Create an instance of BarCodeReader and set image and symbology type to recognize
            BarCodeReader barCodeReader = new BarCodeReader(dataDir + "code39.png", DecodeType.Code39Standard);

            int counter = 0;

            // Read all the barcodes from the images
            while (barCodeReader.Read())
            {
                // Display the symbology type
                Console.WriteLine("BarCode Type: " + barCodeReader.GetCodeType());
                // Display the codetext
                Console.WriteLine("BarCode CodeText: " + barCodeReader.GetCodeText());
                // Get the barcode region

                BarCodeRegion region = barCodeReader.GetRegion();
                if (region != null)
                {
                    // Initialize an object of type Image to get the Graphics object
                    Image image = Image.FromFile(dataDir + "code39.png");

                    // Initialize graphics object from the image
                    Graphics graphics = Graphics.FromImage(image);

                    // Draw the barcode edges
                    region.DrawBarCodeEdges(graphics, new Pen(Color.Red, 1f));

                    // Save the image
                    image.Save(dataDir + string.Format(@"edge_{0}.png", counter++));

                    // Fill the barcode area with some color
                    region.FillBarCodeRegion(graphics, Brushes.Green);
                    image.Save(dataDir + string.Format(@"fill_{0}.png", counter++));
                }
            }
            barCodeReader.Close();
        }
Esempio n. 3
0
 public FoundBarCodes(string text, BarCodeRegion reg)
 {
     CodeText = text;
     region   = reg;
 }