Пример #1
0
        public string ProcessQR(VisionImage image, List <QRConfig> qRConfigs)
        {
            string qRInfo = string.Empty;
            // Initialize the IVA_Data structure to pass results and coordinate systems.
            IVA_Data ivaData = new IVA_Data(1, 0);

            for (int i = 0; i < qRConfigs.Count; i++)
            {
                // Creates a new, empty region of interest.
                Roi roi = new Roi();
                //// Creates a new RectangleContour using the given values.
                //RectangleContour vaRect = new RectangleContour(720, 96, 1792, 1240);
                RectangleContour vaRect = new RectangleContour(qRConfigs[i].Rectangle.Left,
                                                               qRConfigs[i].Rectangle.Top, qRConfigs[i].Rectangle.Height, qRConfigs[i].Rectangle.Width);
                roi.Add(vaRect);
                image.Overlays.Default.AddRoi(roi);
                // Read QR Code
                QRDescriptionOptions vaQROptions = new QRDescriptionOptions();
                vaQROptions.Dimensions = qRConfigs[i].QRDimension;
                vaQROptions.MirrorMode = QRMirrorMode.AutoDetect;
                vaQROptions.ModelType  = QRModelType.AutoDetect;
                vaQROptions.Polarity   = qRConfigs[i].Polarity;
                QRSizeOptions   vaQRSizeOptions   = new QRSizeOptions(3, 15);
                QRSearchOptions vaQRSearchOptions = new QRSearchOptions();
                vaQRSearchOptions.CellFilterMode     = QRCellFilterMode.AutoDetect;
                vaQRSearchOptions.CellSampleSize     = qRConfigs[i].CellSize;
                vaQRSearchOptions.DemodulationMode   = QRDemodulationMode.AutoDetect;
                vaQRSearchOptions.EdgeThreshold      = 30;
                vaQRSearchOptions.RotationMode       = QRRotationMode.Unlimited;
                vaQRSearchOptions.SkewDegreesAllowed = 10;
                vaQRSearchOptions.SkipLocation       = false;
                vaQRCode = Algorithms.ReadQRCode(image, roi, vaQROptions, vaQRSizeOptions, vaQRSearchOptions);
                if (vaQRCode.Found)
                {
                    image.Overlays.Default.AddPolygon(new PolygonContour(vaQRCode.Corners), Rgb32Value.RedColor, DrawingMode.DrawValue);
                }
                System.Text.ASCIIEncoding vaASCIIEncoding = new System.Text.ASCIIEncoding();
                vaQRCodeData = vaASCIIEncoding.GetString(vaQRCode.GetData());

                qRInfo += string.Format("{0},", vaQRCodeData);

                roi.Dispose();
            }
            qRInfo = qRInfo.Substring(0, qRInfo.Length - 1);
            // Dispose the IVA_Data structure.
            ivaData.Dispose();

            // Return the palette type of the final image.
            return(qRInfo);
        }
Пример #2
0
        private void DisplayQRType(QRReport report)
        {
            switch (report.ModelType)
            {
            case QRModelType.Micro:
                typeFound.Text = "QR Micro Code";
                break;

            case QRModelType.Model1:
                typeFound.Text = "QR Model 1 Code";
                break;

            case QRModelType.Model2:
                typeFound.Text = "QR Model 2 Code";
                break;
            }
        }
        public static string ReadCode(VisionImage image, Roi roi, CodeType type)
        {
            string code = string.Empty;

            try
            {
                if (type == CodeType.Code_1D39)
                {
                }
                else if (type == CodeType.Code_1D129)
                {
                }
                else if (type == CodeType.Code_1D93)
                {
                }
                else if (type == CodeType.Code_2D_Mat)
                {
                    DataMatrixReport datamatrixreport = Algorithms.ReadDataMatrixBarcode(image, roi);
                    if (datamatrixreport.StringData != null)
                    {
                        code = datamatrixreport.StringData;
                    }
                }
                else if (type == CodeType.Code_QR)
                {
                    QRReport qrreport = new QRReport();
                    qrreport = Algorithms.ReadQRCode(image, roi);
                    System.Text.ASCIIEncoding vaASCIIEncoding = new System.Text.ASCIIEncoding();
                    if (qrreport != null)
                    {
                        code = vaASCIIEncoding.GetString(qrreport.GetData());
                    }
                }
            }
            catch { code = string.Empty; }

            return(code);
        }
Пример #4
0
        /// <summary>
        /// Process QR code with coordinate
        /// </summary>
        /// <param name="image"></param>
        /// <param name="userProgram"></param>
        /// <returns>split with ','</returns>
        public string ProcessQRCoordinate(VisionImage image, UserProgram userProgram)
        {
            string          qRInfo         = string.Empty;
            TemplateConfig  templateConfig = userProgram.TemplateConfig;
            List <QRConfig> qRConfigs      = userProgram.QRConfigs;
            // Initialize the IVA_Data structure to pass results and coordinate systems.
            IVA_Data ivaData = new IVA_Data(3, 1);

            // Creates a new, empty region of interest.
            Roi roiFullRange = new Roi();
            // Creates a new RotatedRectangleContour using the given values.
            PointContour            vaCenter      = new PointContour(1405.5, 954);
            RotatedRectangleContour vaRotatedRect = new RotatedRectangleContour(vaCenter, 1661, 1184, 0);
            RectangleContour        rectangle     = new RectangleContour(templateConfig.Rectangle.Left, templateConfig.Rectangle.Top,
                                                                         templateConfig.Rectangle.Width, templateConfig.Rectangle.Height);

            roiFullRange.Add(rectangle);
            // MatchPattern Grayscale
            string    vaTemplateFile = templateConfig.TemplatePath;
            MatchMode vaMode         = MatchMode.RotationInvariant;
            bool      vaSubpixelVal  = false;

            int[]  minAngleVals          = { -20, 0 };
            int[]  maxAngleVals          = { 20, 0 };
            int    vaNumMatchesRequested = 1;
            double vaMinMatchScore       = 800;
            double vaOffsetX             = 0;
            double vaOffsetY             = 0;

            pmResults = IVA_MatchPattern(image, ivaData, vaTemplateFile, vaMode, vaSubpixelVal,
                                         minAngleVals, maxAngleVals, vaNumMatchesRequested, vaMinMatchScore, roiFullRange, vaOffsetX, vaOffsetY, 0);
            if (pmResults.Count < 1)
            {
                return(string.Empty);
            }
            foreach (PatternMatch match in pmResults)
            {
                image.Overlays.Default.AddPolygon(new PolygonContour(match.Corners), Rgb32Value.RedColor);
            }
            roiFullRange.Dispose();

            // Set Coordinate System
            int             vaCoordSystemIndex    = 0;
            int             stepIndexOrigin       = 0;
            int             resultIndexOrigin     = 1;
            int             stepIndexAngle        = 0;
            int             resultIndexAngle      = 3;
            double          refSysOriginX         = templateConfig.Position.X;
            double          refSysOriginY         = templateConfig.Position.Y;
            double          refSysAngle           = 0;
            AxisOrientation refSysAxisOrientation = AxisOrientation.Direct;
            int             vaCoordSystemType     = 3;

            IVA_CoordSys(vaCoordSystemIndex, stepIndexOrigin, resultIndexOrigin, stepIndexAngle,
                         resultIndexAngle, refSysOriginX, refSysOriginY, refSysAngle, refSysAxisOrientation, vaCoordSystemType, ivaData);

            for (int i = 0; i < qRConfigs.Count; i++)
            {
                // Creates a new, empty region of interest.
                Roi roi = new Roi();
                // Creates a new RectangleContour using the given values.
                RectangleContour vaRect = new RectangleContour(qRConfigs[i].Rectangle.Left,
                                                               qRConfigs[i].Rectangle.Top, qRConfigs[i].Rectangle.Width, qRConfigs[i].Rectangle.Height);
                roi.Add(vaRect);
                // Reposition the region of interest based on the coordinate system.
                int coordSystemIndex = 0;
                Algorithms.TransformRoi(roi, new CoordinateTransform(ivaData.baseCoordinateSystems[coordSystemIndex],
                                                                     ivaData.MeasurementSystems[coordSystemIndex]));
                // Read QR Code
                QRDescriptionOptions vaQROptions = new QRDescriptionOptions();
                vaQROptions.Dimensions = qRConfigs[i].QRDimension;
                vaQROptions.MirrorMode = QRMirrorMode.AutoDetect;
                vaQROptions.ModelType  = QRModelType.AutoDetect;
                vaQROptions.Polarity   = qRConfigs[i].Polarity;
                QRSizeOptions   vaQRSizeOptions   = new QRSizeOptions(3, 15);
                QRSearchOptions vaQRSearchOptions = new QRSearchOptions();
                vaQRSearchOptions.CellFilterMode     = QRCellFilterMode.AutoDetect;
                vaQRSearchOptions.CellSampleSize     = qRConfigs[i].CellSize;
                vaQRSearchOptions.DemodulationMode   = QRDemodulationMode.AutoDetect;
                vaQRSearchOptions.EdgeThreshold      = 30;
                vaQRSearchOptions.RotationMode       = QRRotationMode.Unlimited;
                vaQRSearchOptions.SkewDegreesAllowed = 5;
                vaQRSearchOptions.SkipLocation       = false;
                vaQRCode = Algorithms.ReadQRCode(image, roi, vaQROptions, vaQRSizeOptions, vaQRSearchOptions);

                if (vaQRCode.Found)
                {
                    image.Overlays.Default.AddPolygon(new PolygonContour(vaQRCode.Corners), Rgb32Value.RedColor, DrawingMode.DrawValue);
                }

                System.Text.ASCIIEncoding vaASCIIEncoding = new System.Text.ASCIIEncoding();
                vaQRCodeData = vaASCIIEncoding.GetString(vaQRCode.GetData());
                qRInfo      += string.Format("{0},", vaQRCodeData);
                roi.Dispose();
            }
            if (!string.IsNullOrEmpty(qRInfo))
            {
                qRInfo = qRInfo.Substring(0, qRInfo.Length - 1);
            }
            // Dispose the IVA_Data structure.
            ivaData.Dispose();
            // Return the palette type of the final image.
            return(qRInfo);
        }
Пример #5
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;
        }