private void defineCoordinateSystemButton_Click(object sender, EventArgs e) { // Initialize search rectangles. primaryAxisRectangle = new RotatedRectangleContour(new PointContour(191, 275), 378, 150, 0); secondaryAxisRectangle = new RotatedRectangleContour(new PointContour(170, 205), 300, 250, 0); // Initialize the options used for the coordinate transformation detection. findTransformRectsOptions = new FindTransformRectsOptions(FindReferenceDirection.BottomToTopIndirect, true, false, false, true); findTransformRectsOptions.PrimaryStraightEdgeOptions.SearchMode = StraightEdgeSearchMode.FirstRakeEdges; findTransformRectsOptions.PrimaryStraightEdgeOptions.AngleRange = 45; findTransformRectsOptions.PrimaryStraightEdgeOptions.StepSize = 5; findTransformRectsOptions.SecondaryStraightEdgeOptions.SearchMode = StraightEdgeSearchMode.FirstRakeEdges; findTransformRectsOptions.SecondaryStraightEdgeOptions.AngleRange = 45; findTransformRectsOptions.SecondaryStraightEdgeOptions.StepSize = 5; // Locate the coordinate system in the reference image. FindTransformReport transformReport = Algorithms.FindTransformRectangles(imageViewer1.Image, new Roi(new Shape[] { primaryAxisRectangle }), new Roi(new Shape[] { secondaryAxisRectangle }), FindTransformMode.FindReference, new CoordinateTransform(), findTransformRectsOptions); transform = transformReport.Transform; // Turn on search lines and edges found overlays. findTransformRectsOptions.ShowSearchLines = true; findTransformRectsOptions.ShowEdgesFound = true; // Update buttons defineCoordinateSystemButton.Enabled = false; defineTemplatesButton.Enabled = true; }
////////////////////////////////////////////////////////////////////////////// // // IVA_SplitRotatedRectangle // // Description: // Splits a rotated rectangle into two rotated rectangles // // Parameters: // roiToSplit - The rectangle roi to split. // direction - The direction of the search; the split occurs in the // perpendicular direction // firstRoi - The resulting first rectangle roi. // secondRoi - The resulting second rectangle roi. // // Return Value: // None // ////////////////////////////////////////////////////////////////////////////// public static void IVA_SplitRotatedRectangle(Roi roiToSplit, RakeDirection direction, out Roi firstRoi, out Roi secondRoi) { RotatedRectangleContour rectToSplit = (RotatedRectangleContour)roiToSplit[0].Shape; RotatedRectangleContour firstRect = new RotatedRectangleContour(); RotatedRectangleContour secondRect = new RotatedRectangleContour(); double xAdjustment; double yAdjustment; double shiftFactor; // Transfer the angle to each rectangle (the direction does not effect the angle). firstRect.Angle = rectToSplit.Angle; secondRect.Angle = rectToSplit.Angle; // Determine which direction to split the rectangle switch (direction) { case RakeDirection.LeftToRight: case RakeDirection.RightToLeft: // Split the rectangle down the verticle axis firstRect.Width = rectToSplit.Width / 2; firstRect.Height = rectToSplit.Height; secondRect.Width = rectToSplit.Width / 2; secondRect.Height = rectToSplit.Height; // Calculate the shift for the left coordinate of the two rects shiftFactor = (double)(rectToSplit.Width / 4.0); // Set the size of the adjustment xAdjustment = (double)(Math.Cos(rectToSplit.Angle * Math.PI / 180) * shiftFactor); yAdjustment = (double)(Math.Sin(rectToSplit.Angle * Math.PI / 180) * shiftFactor); // Fix the directions for the adjustments if (direction == RakeDirection.LeftToRight) { firstRect.Center.X = (int)(rectToSplit.Center.X - xAdjustment + (shiftFactor)); firstRect.Center.Y = (int)(rectToSplit.Center.Y - xAdjustment + (shiftFactor)); secondRect.Center.X = (int)(rectToSplit.Center.X + xAdjustment + (shiftFactor)); secondRect.Center.Y = (int)(rectToSplit.Center.Y - yAdjustment); } else { firstRect.Center.X = (int)(rectToSplit.Center.X + xAdjustment + (shiftFactor)); firstRect.Center.Y = (int)(rectToSplit.Center.Y - yAdjustment); secondRect.Center.X = (int)(rectToSplit.Center.X - xAdjustment + (shiftFactor)); secondRect.Center.Y = (int)(rectToSplit.Center.Y + yAdjustment); } break; case RakeDirection.TopToBottom: case RakeDirection.BottomToTop: // Split the rectangle down the horizontal axis firstRect.Width = rectToSplit.Width; firstRect.Height = rectToSplit.Height / 2; secondRect.Width = rectToSplit.Width; secondRect.Height = rectToSplit.Height / 2; // Calculate the shift for the top coordinate of the two rects shiftFactor = (double)(rectToSplit.Height / 4.0); // Set the size of the adjustment xAdjustment = (double)(Math.Sin(rectToSplit.Angle * Math.PI / 180) * shiftFactor); yAdjustment = (double)(Math.Cos(rectToSplit.Angle * Math.PI / 180) * shiftFactor); // Fix the directions for the adjustments if (direction == RakeDirection.TopToBottom) { firstRect.Center.X = (int)(rectToSplit.Center.X - xAdjustment); firstRect.Center.Y = (int)(rectToSplit.Center.Y - yAdjustment + (shiftFactor)); secondRect.Center.X = (int)(rectToSplit.Center.X + xAdjustment); secondRect.Center.Y = (int)(rectToSplit.Center.Y + yAdjustment + (shiftFactor)); } else { firstRect.Center.X = (int)(rectToSplit.Center.X + xAdjustment); firstRect.Center.Y = (int)(rectToSplit.Center.Y + yAdjustment + (shiftFactor)); secondRect.Center.X = (int)(rectToSplit.Center.X - xAdjustment); secondRect.Center.Y = (int)(rectToSplit.Center.Y - yAdjustment + (shiftFactor)); } break; } firstRoi = new Roi(firstRect); secondRoi = new Roi(secondRect); }
public static PointContour MatchPattern(VisionImage SourceImage, RectangleContour vaRect, string TemplateFile, int vaNumMatchesRequested, float vaMinMatchScore, float fUpper = 0, float fLower = 0) { PointContour point = new PointContour(); point.X = -10000; point.Y = -10000; // Creates a new, empty region of interest. Roi roi = new Roi(); // Creates a new RotatedRectangleContour using the given values. PointContour vaCenter = new PointContour(vaRect.Left + vaRect.Width / 2, vaRect.Top + vaRect.Height / 2); RotatedRectangleContour vaRotatedRect = new RotatedRectangleContour(vaCenter, vaRect.Width - 50, vaRect.Height - 50, 0); roi.Add(vaRotatedRect); // MatchPattern Grayscale // string TemplateFile = "D:\\t1.png"; MatchingAlgorithm matchAlgorithm = MatchingAlgorithm.MatchGrayValuePyramid; float[] minAngleVals = { fLower, 0 }; float[] maxAngleVals = { fUpper, 0 }; int[] advancedOptionsItems = { 102, 106, 107, 108, 109, 111, 112, 113, 103, 104, 105, 100 }; double[] advancedOptionsValues = { 10, 300, 0, 6, 1, 20, 10, 20, 1, 20, 0, 5 }; int numberAdvOptions = 12; //int vaNumMatchesRequested = 1; //float vaMinMatchScore = 800; using (VisionImage imageTemplate = new VisionImage(ImageType.U8, 7)) { Collection <PatternMatchReport> patternMatchingResults = new Collection <PatternMatchReport>(); // Read the image template. imageTemplate.ReadVisionFile(TemplateFile); // Set the angle range. Collection <RotationAngleRange> angleRange = new Collection <RotationAngleRange>(); for (int i = 0; i < 2; ++i) { angleRange.Add(new RotationAngleRange(minAngleVals[i], maxAngleVals[i])); } // Set the advanced options. Collection <PMMatchAdvancedSetupDataOption> advancedMatchOptions = new Collection <PMMatchAdvancedSetupDataOption>(); for (int i = 0; i < numberAdvOptions; ++i) { advancedMatchOptions.Add(new PMMatchAdvancedSetupDataOption((MatchSetupOption)advancedOptionsItems[i], advancedOptionsValues[i])); } // Searches for areas in the image that match a given pattern. patternMatchingResults = Algorithms.MatchPattern3(SourceImage, imageTemplate, matchAlgorithm, vaNumMatchesRequested, vaMinMatchScore, angleRange, roi, advancedMatchOptions); string sPatterScore = ""; if (patternMatchingResults.Count > 0) { for (int i = 0; i < 1 /* patternMatchingResults.Count*/; ++i) { point.X = patternMatchingResults[i].Position.X; point.Y = patternMatchingResults[i].Position.Y; sPatterScore += " " + patternMatchingResults[i].Score.ToString(); //SourceImage.Overlays.Default.AddRectangle(new RectangleContour(point.X - imageTemplate.Width / 2 - 1, point.Y - imageTemplate.Height / 2 - 1, imageTemplate.Width, imageTemplate.Height), Rgb32Value.GreenColor); LineContour l1 = new LineContour(); l1.Start.X = point.X - (imageTemplate.Width / 2 - 3); l1.Start.Y = point.Y; l1.End.X = point.X + (imageTemplate.Width / 2 - 3); l1.End.Y = point.Y; SourceImage.Overlays.Default.AddLine(l1, Rgb32Value.RedColor); LineContour l2 = new LineContour(); l2.Start.X = point.X; l2.Start.Y = point.Y - (imageTemplate.Height / 2 - 3); l2.End.X = point.X; l2.End.Y = point.Y + (imageTemplate.Height / 2 - 3); SourceImage.Overlays.Default.AddLine(l2, Rgb32Value.RedColor); } } } roi.Dispose(); return(point); }
public static PaletteType RectLeftPos(VisionImage image, Point pointoffset) { // Initialize the IVA_Data structure to pass results and coordinate systems. IVA_Data ivaData = new IVA_Data(12, 1); // Extract Color Plane using (VisionImage plane = new VisionImage(ImageType.U8, 7)) { // Extract the red color plane and copy it to the main image. Algorithms.ExtractColorPlanes(image, ColorMode.Rgb, plane, null, null); Algorithms.Copy(plane, image); } // Creates a new, empty region of interest. Roi roi = new Roi(); // Creates a new RectangleContour using the given values. RectangleContour vaRect = new RectangleContour(630, 1313, 1073, 416); roi.Add(vaRect); // MatchPattern Grayscale string dicpath = System.Windows.Forms.Application.StartupPath; string vaTemplateFile = dicpath + $"{ @"/ImageConfig/LeftRectPos.png"}"; MatchingAlgorithm matchAlgorithm = MatchingAlgorithm.MatchGrayValuePyramid; float[] minAngleVals = { -10, 0 }; float[] maxAngleVals = { 10, 0 }; int[] advancedOptionsItems = { 100, 102, 106, 107, 108, 109, 114, 116, 117, 118, 111, 112, 113, 103, 104, 105 }; double[] advancedOptionsValues = { 5, 10, 300, 0, 6, 1, 25, 0, 0, 0, 20, 10, 20, 1, 20, 0 }; int numberAdvOptions = 16; int vaNumMatchesRequested = 1; float vaMinMatchScore = 700; pmResults = IVA_MatchPattern(image, ivaData, vaTemplateFile, matchAlgorithm, minAngleVals, maxAngleVals, advancedOptionsItems, advancedOptionsValues, numberAdvOptions, vaNumMatchesRequested, vaMinMatchScore, roi, 2); roi.Dispose(); if (pmResults.Count == 1) { // Set Coordinate System int vaCoordSystemIndex = 0; int stepIndexOrigin = 2; int resultIndexOrigin = 1; int stepIndexAngle = 2; int resultIndexAngle = 3; double refSysOriginX = 1160.5; double refSysOriginY = 1500.5; double refSysAngle = 0; AxisOrientation refSysAxisOrientation = AxisOrientation.Direct; int vaCoordSystemType = 3; IVA_CoordSys(vaCoordSystemIndex, stepIndexOrigin, resultIndexOrigin, stepIndexAngle, resultIndexAngle, refSysOriginX, refSysOriginY, refSysAngle, refSysAxisOrientation, vaCoordSystemType, ivaData); // Creates a new, empty region of interest. Roi roi2 = new Roi(); // Creates a new RotatedRectangleContour using the given values. PointContour vaCenter = new PointContour(789, 965.5); RotatedRectangleContour vaRotatedRect = new RotatedRectangleContour(vaCenter, 72, 1119, 0); roi2.Add(vaRotatedRect); // Reposition the region of interest based on the coordinate system. int coordSystemIndex = 0; Algorithms.TransformRoi(roi2, new CoordinateTransform(ivaData.baseCoordinateSystems[coordSystemIndex], ivaData.MeasurementSystems[coordSystemIndex])); // Find Straight Edge EdgeOptions vaOptions = new EdgeOptions(); vaOptions.ColumnProcessingMode = ColumnProcessingMode.Average; vaOptions.InterpolationType = InterpolationMethod.Bilinear; vaOptions.KernelSize = 9; vaOptions.MinimumThreshold = Position.Instance.EdgeThreshold_Left; vaOptions.Polarity = EdgePolaritySearchMode.Falling; vaOptions.Width = 5; StraightEdgeOptions vaStraightEdgeOptions = new StraightEdgeOptions(); vaStraightEdgeOptions.AngleRange = 45; vaStraightEdgeOptions.AngleTolerance = 1; vaStraightEdgeOptions.HoughIterations = 5; vaStraightEdgeOptions.MinimumCoverage = 25; vaStraightEdgeOptions.MinimumSignalToNoiseRatio = 0; vaStraightEdgeOptions.NumberOfLines = 1; vaStraightEdgeOptions.Orientation = 0; Range vaRange = new Range(0, 1000); vaStraightEdgeOptions.ScoreRange = vaRange; vaStraightEdgeOptions.StepSize = 20; vaStraightEdgeOptions.SearchMode = StraightEdgeSearchMode.FirstRakeEdges; vaEdgeReport = IVA_FindEdge(image, roi2, RakeDirection.LeftToRight, vaOptions, vaStraightEdgeOptions, ivaData, 4); roi2.Dispose(); // Creates a new, empty region of interest. Roi roi3 = new Roi(); // Creates a new RotatedRectangleContour using the given values. PointContour vaCenter2 = new PointContour(1162.5, 263); RotatedRectangleContour vaRotatedRect2 = new RotatedRectangleContour(vaCenter2, 595, 78, 0); roi3.Add(vaRotatedRect2); // Reposition the region of interest based on the coordinate system. int coordSystemIndex2 = 0; Algorithms.TransformRoi(roi3, new CoordinateTransform(ivaData.baseCoordinateSystems[coordSystemIndex2], ivaData.MeasurementSystems[coordSystemIndex2])); // Find Straight Edge EdgeOptions vaOptions2 = new EdgeOptions(); vaOptions2.ColumnProcessingMode = ColumnProcessingMode.Average; vaOptions2.InterpolationType = InterpolationMethod.Bilinear; vaOptions2.KernelSize = 9; vaOptions2.MinimumThreshold = Position.Instance.EdgeThreshold_Left; vaOptions2.Polarity = EdgePolaritySearchMode.Falling; vaOptions2.Width = 9; StraightEdgeOptions vaStraightEdgeOptions2 = new StraightEdgeOptions(); vaStraightEdgeOptions2.AngleRange = 45; vaStraightEdgeOptions2.AngleTolerance = 1; vaStraightEdgeOptions2.HoughIterations = 5; vaStraightEdgeOptions2.MinimumCoverage = 25; vaStraightEdgeOptions2.MinimumSignalToNoiseRatio = 0; vaStraightEdgeOptions2.NumberOfLines = 1; vaStraightEdgeOptions2.Orientation = 0; Range vaRange2 = new Range(0, 1000); vaStraightEdgeOptions2.ScoreRange = vaRange2; vaStraightEdgeOptions2.StepSize = 20; vaStraightEdgeOptions2.SearchMode = StraightEdgeSearchMode.FirstRakeEdges; vaEdgeReport2 = IVA_FindEdge(image, roi3, RakeDirection.TopToBottom, vaOptions2, vaStraightEdgeOptions2, ivaData, 5); roi3.Dispose(); // Creates a new, empty region of interest. Roi roi4 = new Roi(); // Creates a new RotatedRectangleContour using the given values. PointContour vaCenter3 = new PointContour(1530, 968.5); RotatedRectangleContour vaRotatedRect3 = new RotatedRectangleContour(vaCenter3, 78, 1137, 0); roi4.Add(vaRotatedRect3); // Reposition the region of interest based on the coordinate system. int coordSystemIndex3 = 0; Algorithms.TransformRoi(roi4, new CoordinateTransform(ivaData.baseCoordinateSystems[coordSystemIndex3], ivaData.MeasurementSystems[coordSystemIndex3])); // Find Straight Edge EdgeOptions vaOptions3 = new EdgeOptions(); vaOptions3.ColumnProcessingMode = ColumnProcessingMode.Average; vaOptions3.InterpolationType = InterpolationMethod.Bilinear; vaOptions3.KernelSize = 9; vaOptions3.MinimumThreshold = Position.Instance.EdgeThreshold_Left; vaOptions3.Polarity = EdgePolaritySearchMode.Falling; vaOptions3.Width = 9; StraightEdgeOptions vaStraightEdgeOptions3 = new StraightEdgeOptions(); vaStraightEdgeOptions3.AngleRange = 45; vaStraightEdgeOptions3.AngleTolerance = 1; vaStraightEdgeOptions3.HoughIterations = 5; vaStraightEdgeOptions3.MinimumCoverage = 25; vaStraightEdgeOptions3.MinimumSignalToNoiseRatio = 0; vaStraightEdgeOptions3.NumberOfLines = 1; vaStraightEdgeOptions3.Orientation = 0; Range vaRange3 = new Range(0, 1000); vaStraightEdgeOptions3.ScoreRange = vaRange3; vaStraightEdgeOptions3.StepSize = 20; vaStraightEdgeOptions3.SearchMode = StraightEdgeSearchMode.FirstRakeEdges; vaEdgeReport3 = IVA_FindEdge(image, roi4, RakeDirection.RightToLeft, vaOptions3, vaStraightEdgeOptions3, ivaData, 6); roi4.Dispose(); // Creates a new, empty region of interest. Roi roi5 = new Roi(); // Creates a new RotatedRectangleContour using the given values. PointContour vaCenter4 = new PointContour(1171.5, 1691.5); RotatedRectangleContour vaRotatedRect4 = new RotatedRectangleContour(vaCenter4, 543, 75, 0); roi5.Add(vaRotatedRect4); // Reposition the region of interest based on the coordinate system. int coordSystemIndex4 = 0; Algorithms.TransformRoi(roi5, new CoordinateTransform(ivaData.baseCoordinateSystems[coordSystemIndex4], ivaData.MeasurementSystems[coordSystemIndex4])); // Find Straight Edge EdgeOptions vaOptions4 = new EdgeOptions(); vaOptions4.ColumnProcessingMode = ColumnProcessingMode.Average; vaOptions4.InterpolationType = InterpolationMethod.Bilinear; vaOptions4.KernelSize = 11; vaOptions4.MinimumThreshold = Position.Instance.EdgeThreshold_Left; vaOptions4.Polarity = EdgePolaritySearchMode.Falling; vaOptions4.Width = 9; StraightEdgeOptions vaStraightEdgeOptions4 = new StraightEdgeOptions(); vaStraightEdgeOptions4.AngleRange = 45; vaStraightEdgeOptions4.AngleTolerance = 1; vaStraightEdgeOptions4.HoughIterations = 5; vaStraightEdgeOptions4.MinimumCoverage = 25; vaStraightEdgeOptions4.MinimumSignalToNoiseRatio = 0; vaStraightEdgeOptions4.NumberOfLines = 1; vaStraightEdgeOptions4.Orientation = 0; Range vaRange4 = new Range(0, 1000); vaStraightEdgeOptions4.ScoreRange = vaRange4; vaStraightEdgeOptions4.StepSize = 20; vaStraightEdgeOptions4.SearchMode = StraightEdgeSearchMode.FirstRakeEdges; vaEdgeReport4 = IVA_FindEdge(image, roi5, RakeDirection.BottomToTop, vaOptions4, vaStraightEdgeOptions4, ivaData, 7); roi5.Dispose(); // Caliper // Delete all the results of this step (from a previous iteration) Functions.IVA_DisposeStepResults(ivaData, 8); // Computes the vaIntersection point between two lines. Collection <PointContour> vaIntersection = IVA_GetIntersection(image, ivaData, 8, 5, 0, 5, 2, 6, 0, 6, 2); caliperIntersection = vaIntersection[0]; // Caliper // Delete all the results of this step (from a previous iteration) Functions.IVA_DisposeStepResults(ivaData, 9); // Computes the vaIntersection point between two lines. Collection <PointContour> vaIntersection2 = IVA_GetIntersection(image, ivaData, 9, 6, 0, 6, 2, 7, 0, 7, 2); caliperIntersection2 = vaIntersection2[0]; // Caliper // Delete all the results of this step (from a previous iteration) Functions.IVA_DisposeStepResults(ivaData, 10); // Computes the vaIntersection point between two lines. Collection <PointContour> vaIntersection3 = IVA_GetIntersection(image, ivaData, 10, 4, 0, 4, 2, 7, 0, 7, 2); caliperIntersection3 = vaIntersection3[0]; // Caliper // Delete all the results of this step (from a previous iteration) Functions.IVA_DisposeStepResults(ivaData, 11); // Computes the vaIntersection point between two lines. Collection <PointContour> vaIntersection4 = IVA_GetIntersection(image, ivaData, 11, 4, 0, 4, 2, 5, 0, 5, 2); caliperIntersection4 = vaIntersection4[0]; //计算每个角的偏差 string str1 = Math.Round((-caliperIntersection.X - pointoffset.X + Position.Instance.SpecLeftPos_X[0]) / 96, 3).ToString() + ";" + Math.Round((-caliperIntersection.Y - pointoffset.Y + Position.Instance.SpecLeftPos_Y[0]) / 96, 3).ToString() + ";"; string str2 = Math.Round((-caliperIntersection2.X - pointoffset.X + Position.Instance.SpecLeftPos_X[1]) / 96, 3).ToString() + ";" + Math.Round((-caliperIntersection2.Y - pointoffset.Y + Position.Instance.SpecLeftPos_Y[1]) / 96, 3).ToString() + ";"; string str3 = Math.Round((-caliperIntersection3.X - pointoffset.X + Position.Instance.SpecLeftPos_X[2]) / 96, 3).ToString() + ";" + Math.Round((-caliperIntersection3.Y - pointoffset.Y + Position.Instance.SpecLeftPos_Y[2]) / 96, 3).ToString() + ";"; string str4 = Math.Round((-caliperIntersection4.X - pointoffset.X + Position.Instance.SpecLeftPos_X[3]) / 96, 3).ToString() + ";" + Math.Round((-caliperIntersection4.Y - pointoffset.Y + Position.Instance.SpecLeftPos_Y[3]) / 96, 3).ToString(); LeftCali = str1 + str2 + str3 + str4; LeftCaliArrary = new string[] { str1, str2, str3, str4 }; } else { LeftCali = "0;0;0;0;0;0;0;0"; LeftCaliArrary = new string[] { "0;0", "0;0", "0;0", "0;0" }; } // Dispose the IVA_Data structure. ivaData.Dispose(); // Return the palette type of the final image. return(PaletteType.Gray); }
/// <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); }