Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            // Get the next image.
            VisionImage curImage = GetNextImage();

            imageNumberLabel.Text = imageNumber.ToString();

            // Locate the coordinate system in the reference image.
            FindTransformReport transformReport = Algorithms.FindTransformRectangles(curImage, new Roi(new Shape[] { primaryAxisRectangle }), new Roi(new Shape[] { secondaryAxisRectangle }), FindTransformMode.UpdateTransform, transform, findTransformRectsOptions);
            // Transform the Roi with the found transform.
            Roi tempRoi = new Roi(matchPatternRoi);

            Algorithms.TransformRoi(tempRoi, transformReport.Transform);
            RectangleContour searchArea = ((RotatedRectangleContour)tempRoi[0].Shape).GetBoundingRectangle();

            // Overlay the search area.
            curImage.Overlays.Default.AddRoi(tempRoi);
            // Try to match the first template.
            bool found = false;
            Collection <PatternMatch> matches = Algorithms.MatchPattern(curImage, imageViewer2.Image, matchPatternOptions, searchArea);

            if (matches.Count > 0)
            {
                found = true;
                // Overlay the results.
                // First draw the bounding box.
                curImage.Overlays.Default.AddPolygon(new PolygonContour(matches[0].Corners), Rgb32Value.RedColor);
                // Now draw the center point.
                curImage.Overlays.Default.AddOval(new OvalContour(matches[0].Position.X - 5, matches[0].Position.Y - 5, 11, 11), Rgb32Value.RedColor, DrawingMode.DrawValue);
                // Finally draw the crosshair.
                curImage.Overlays.Default.AddLine(new LineContour(new PointContour(matches[0].Position.X - 10, matches[0].Position.Y), new PointContour(matches[0].Position.X + 10, matches[0].Position.Y)), Rgb32Value.RedColor);
                curImage.Overlays.Default.AddLine(new LineContour(new PointContour(matches[0].Position.X, matches[0].Position.Y - 10), new PointContour(matches[0].Position.X, matches[0].Position.Y + 10)), Rgb32Value.RedColor);
            }
            else
            {
                // Try to match the second template.
                matches = Algorithms.MatchPattern(curImage, imageViewer3.Image, matchPatternOptions, searchArea);
                if (matches.Count > 0)
                {
                    found = true;
                    // Overlay the results.
                    // First draw the bounding box.
                    curImage.Overlays.Default.AddPolygon(new PolygonContour(matches[0].Corners), Rgb32Value.RedColor);
                    // Now draw the center point.
                    curImage.Overlays.Default.AddOval(new OvalContour(matches[0].Position.X - 5, matches[0].Position.Y - 5, 11, 11), Rgb32Value.RedColor, DrawingMode.DrawValue);
                    // Finally draw the crosshair.
                    curImage.Overlays.Default.AddLine(new LineContour(new PointContour(matches[0].Position.X - 10, matches[0].Position.Y), new PointContour(matches[0].Position.X + 10, matches[0].Position.Y)), Rgb32Value.RedColor);
                    curImage.Overlays.Default.AddLine(new LineContour(new PointContour(matches[0].Position.X, matches[0].Position.Y - 10), new PointContour(matches[0].Position.X, matches[0].Position.Y + 10)), Rgb32Value.RedColor);
                }
            }
            passOrFail.Value = found;
            string     overlayText;
            Rgb32Value overlayColor;

            if (found)
            {
                overlayColor = Rgb32Value.GreenColor;
                overlayText  = "PASS";
            }
            else
            {
                overlayColor = Rgb32Value.RedColor;
                overlayText  = "FAIL";
            }
            curImage.Overlays.Default.AddText(overlayText, new PointContour(380, 395), overlayColor, overlayTextOptions);

            // Display the resulting image.
            imageViewer1.Attach(curImage);
        }