Exemplo n.º 1
0
        // timer1_Tick is called when the timer interval has passed.  The next image
        // is read in, barcode settings are initialized based on the type,
        // and the barcode is read and processed.
        private void timer1_Tick(object sender, EventArgs e)
        {
            // Stop the timer so that we don't count the time spent reading the barcode
            timer1.Enabled = false;
            using (VisionImage tempImage = new VisionImage()) {
                // Load the barcode image.
                tempImage.ReadVisionFile(curImages[imageIndex]);

                Collection <Pdf417Report> pdf417Report = new Collection <Pdf417Report>();
                DataMatrixReport          dmReport     = new DataMatrixReport();
                QRReport qrReport = new QRReport();
                // Read barcode and time how long it takes.
                int startTime = System.Environment.TickCount;
                if (barcodeType.Text == "PDF417")
                {
                    // Decode a PDF417 code.
                    pdf417Report = Algorithms.ReadPdf417Barcode(tempImage);
                }
                else if (barcodeType.Text == "Data Matrix")
                {
                    // Decode a Data Matrix
                    DataMatrixDescriptionOptions descOptions   = new DataMatrixDescriptionOptions();
                    DataMatrixSizeOptions        sizeOptions   = new DataMatrixSizeOptions();
                    DataMatrixSearchOptions      searchOptions = new DataMatrixSearchOptions();
                    if (useOptionsBox.Checked)
                    {
                        // Read the options from the image.
                        GetDataMatrixCodeSettings(tempImage, ref descOptions, ref sizeOptions, ref searchOptions);
                    }
                    DataMatrixGradingMode gradingMode = DataMatrixGradingMode.None;
                    if (gradeDMBox.Checked)
                    {
                        gradingMode = DataMatrixGradingMode.PrepareForAim;
                    }
                    dmReport = Algorithms.ReadDataMatrixBarcode(tempImage, null, gradingMode, descOptions, sizeOptions, searchOptions);
                }
                else
                {
                    // Decode a QR Code
                    QRDescriptionOptions descOptions   = new QRDescriptionOptions();
                    QRSizeOptions        sizeOptions   = new QRSizeOptions();
                    QRSearchOptions      searchOptions = new QRSearchOptions();
                    if (useOptionsBox.Checked)
                    {
                        // Read the options from the image.
                    }
                    qrReport = Algorithms.ReadQRCode(tempImage, null, descOptions, sizeOptions, searchOptions);
                }
                int  elapsedTime = System.Environment.TickCount - startTime;
                bool found;
                if (barcodeType.Text == "PDF417")
                {
                    found = pdf417Report.Count > 0;
                }
                else if (barcodeType.Text == "Data Matrix")
                {
                    found = dmReport.Found;
                }
                else
                {
                    found = qrReport.Found;
                }
                // Process info
                if (found)
                {
                    PointContour centerPoint = new PointContour();
                    if (barcodeType.Text == "PDF417")
                    {
                        dataFound.Text = pdf417Report[0].StringData;
                        typeFound.Text = "Pdf417";
                        tempImage.Overlays.Default.AddPolygon(new PolygonContour(pdf417Report[0].Corners), Rgb32Value.GreenColor, DrawingMode.DrawValue);
                        // Center the viewer on the barcode.
                        centerPoint.Initialize((pdf417Report[0].Corners[0].X + pdf417Report[0].Corners[2].X) / 2, (pdf417Report[0].Corners[0].Y + pdf417Report[0].Corners[2].Y) / 2);
                    }
                    else if (barcodeType.Text == "Data Matrix")
                    {
                        if (dmReport.Binary)
                        {
                            dataFound.Text = System.Text.Encoding.Default.GetString(dmReport.GetBinaryData());
                        }
                        else
                        {
                            dataFound.Text = dmReport.StringData;
                        }
                        DisplayDataMatrixType(dmReport);
                        tempImage.Overlays.Default.AddPolygon(new PolygonContour(dmReport.Corners), Rgb32Value.GreenColor, DrawingMode.DrawValue);
                        // Center the viewer on the barcode.
                        centerPoint.Initialize((dmReport.Corners[0].X + dmReport.Corners[2].X) / 2, (dmReport.Corners[0].Y + dmReport.Corners[2].Y) / 2);
                        // Grade the barcode if requested.
                        if (gradeDMBox.Checked)
                        {
                            AimGradeReport gradeReport = Algorithms.GradeDataMatrixBarcodeAim(tempImage);
                            gradeOverall.Text               = gradeReport.OverallGrade.ToString();
                            gradeDecoding.Text              = gradeReport.DecodingGrade.ToString();
                            gradeSymbolContrast.Text        = gradeReport.SymbolContrastGrade.ToString();
                            gradePrintGrowth.Text           = gradeReport.PrintGrowthGrade.ToString();
                            gradeAxialNonuniformity.Text    = gradeReport.AxialNonuniformityGrade.ToString();
                            gradeUnusedErrorCorrection.Text = gradeReport.UnusedErrorCorrectionGrade.ToString();
                        }
                        else
                        {
                            gradeOverall.Text               = "";
                            gradeDecoding.Text              = "";
                            gradeSymbolContrast.Text        = "";
                            gradePrintGrowth.Text           = "";
                            gradeAxialNonuniformity.Text    = "";
                            gradeUnusedErrorCorrection.Text = "";
                        }
                    }
                    else
                    {
                        dataFound.Text = System.Text.Encoding.Default.GetString(qrReport.GetData());
                        DisplayQRType(qrReport);
                        tempImage.Overlays.Default.AddPolygon(new PolygonContour(qrReport.Corners), Rgb32Value.GreenColor, DrawingMode.DrawValue);
                        // Center the viewer on the barcode.
                        centerPoint.Initialize((qrReport.Corners[0].X + qrReport.Corners[2].X) / 2, (qrReport.Corners[0].Y + qrReport.Corners[2].Y) / 2);
                    }
                    readTime.Text = elapsedTime.ToString();
                    Algorithms.Copy(tempImage, imageViewer1.Image);
                    imageViewer1.RefreshImage();
                    imageViewer1.Center.Initialize(centerPoint.X, centerPoint.Y);
                }
            }
            // Set up for next image
            imageIndex     = (imageIndex + 1) % curImages.Count;
            timer1.Enabled = true;
        }
Exemplo n.º 2
0
 public static extern IntPtr imaqReadDataMatrixBarcode2(IntPtr image, ref ROI roi, DataMatrixGradingMode prepareForGrading, ref DataMatrixDescriptionOptions descriptionOptions, ref DataMatrixSizeOptions sizeOptions, ref DataMatrixSearchOptions searchOptions);