Ejemplo n.º 1
0
        public static void LearnPattern(ImageViewer SourceImage, float fUpper = 0, float fLower = 0)
        {
            using (VisionImage plane = new VisionImage(ImageType.U8, 7))
            {
                // Extract the green color plane and copy it to the main image.
                if (SourceImage.Image.Type == ImageType.Rgb32)
                {
                    Algorithms.ExtractColorPlanes(SourceImage.Image, NationalInstruments.Vision.ColorMode.Rgb, null, plane, null);
                    Algorithms.Copy(plane, SourceImage.Image);
                }
            }
//          Algorithms.LearnPattern2(SourceImage.Image);
            OvalContour vaRect2 = new OvalContour(0, 0, 0, 0);
            Roi         roi     = new Roi();

            roi.Add(vaRect2);
            // Histogram Grayscale
            using (VisionImage imageMask = new VisionImage(ImageType.U8, 7))
            {
                RotationAngleRange ra        = new RotationAngleRange(fLower, fUpper);
                PixelValue         fillValue = new PixelValue(255);
                Algorithms.RoiToMask(imageMask, roi, fillValue, SourceImage.Image);
                Algorithms.LearnPattern2(SourceImage.Image, imageMask, MatchingAlgorithm.MatchGrayValuePyramid, ra);
            }
            roi.Dispose();
        }
Ejemplo n.º 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            // Get the next image.
            VisionImage image = GetNextImage();

            // Look for rotational shift in the image.
            PointContour imageCenter = new PointContour(image.Width / 2.0, image.Height / 2.0);
            double       angle       = Algorithms.DetectRotation(images[0], image, imageCenter, imageCenter, (int)(.475 * image.Width));

            // Transform the regions of interest.
            CoordinateTransform transform = new CoordinateTransform(new CoordinateSystem(imageCenter), new CoordinateSystem(imageCenter, angle));
            // Copy to a new Roi so we don't lose the information.
            Roi transformedRoi = new Roi(testLines);

            Algorithms.TransformRoi(transformedRoi, transform);

            // Find the actual number of edges along each line in the image.
            bool allTargetsPassed = true;

            for (int i = 0; i < transformedRoi.Count; ++i)
            {
                Collection <PointContour> linePoints = Algorithms.GetPointsOnLine((LineContour)transformedRoi[i].Shape);
                Collection <PointContour> edges      = Algorithms.SimpleEdge(image, linePoints, simpleEdgeOptions);

                // Display the results.
                GetActualTextBox(i).Text = edges.Count.ToString();
                foreach (PointContour pt in edges)
                {
                    image.Overlays.Default.AddOval(new OvalContour(pt.X - 2, pt.Y - 2, 5, 5), Rgb32Value.YellowColor, DrawingMode.PaintValue);
                }

                if (Int32.Parse(GetExpectedTextBox(i).Text) == edges.Count)
                {
                    // Part passes.
                    GetPassFailLed(i).Value = true;
                    image.Overlays.Default.AddLine((LineContour)transformedRoi[i].Shape, Rgb32Value.GreenColor);
                }
                else
                {
                    // Part fails.
                    GetPassFailLed(i).Value = false;
                    image.Overlays.Default.AddLine((LineContour)transformedRoi[i].Shape, Rgb32Value.RedColor);
                }
                allTargetsPassed = allTargetsPassed && GetPassFailLed(i).Value;
            }
            globalPassFailLed.Value = allTargetsPassed;
            // Overlay the outside circle of the part.
            OvalContour outsideOval = new OvalContour(image.Width * .025, image.Height * .025, image.Width * .95, image.Height * .95);

            image.Overlays.Default.AddOval(outsideOval, allTargetsPassed ? Rgb32Value.GreenColor : Rgb32Value.RedColor);

            imageViewer1.Attach(image);
        }
Ejemplo n.º 3
0
        public static double FindCircleHistogramMean(VisionImage image, OvalContour vaRect2)
        {
            Roi roi = new Roi();

            // Creates a new RectangleContour using the given values.

            roi.Add(vaRect2);
            // Histogram Grayscale
            double HistogramMean = -100;

            using (VisionImage imageMask = new VisionImage(ImageType.U8, 7))
            {
                PixelValue fillValue     = new PixelValue(255);
                Range      intervalRange = new Range(0, 0);

                Algorithms.RoiToMask(imageMask, roi, fillValue, image);

                // Calculates and returns statistical parameters on the image.
                HistogramMean = Algorithms.Histogram(image, 256, intervalRange, imageMask).Mean;
            }
            roi.Dispose();
            return(HistogramMean);
        }