//Reading production programming in local. //每个程序文件保存该程序的相关参数,自动运行时选择对应程序可省略重复编程的麻烦。 public void ReadProgram(string name) { currentProgram = userProgram.FindAll(o => (o.Name == name))[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); }