Пример #1
0
        /// <summary>
        /// 根据吸嘴获得实际坐标
        /// </summary>
        /// <param name="nz">输入-吸嘴</param>
        /// <param name="capturePt"></param>
        /// <param name="imagePt"></param>
        /// <param name="wroldPt"></param>
        /// <returns></returns>
        public bool WroldPt(Nozzle nz, PointF capturePt, PointContour imagePt, out PointF wroldPt)
        {
            Camera camera = Camera.Bottom1;

            if (nz == Nozzle.Nz3 || nz == Nozzle.Nz4)
            {
                camera = Camera.Bottom2;
            }
            int i = 0;

            if (nz == Nozzle.Nz2 || nz == Nozzle.Nz4)
            {
                i = 1;
            }

            wroldPt = new PointF();

            try
            {
                PointF pt1 = CameraDefine.Instance.CameraList[this.Module][camera].Mat2D[i].Pixel2World(imagePt);
                wroldPt   = pt1;
                wroldPt.X = capturePt.X - (pt1.X - CameraDefine.Instance.CameraList[this.Module][camera].Mat2D[i].CliabCenter.X);
                wroldPt.Y = capturePt.Y - (pt1.Y - CameraDefine.Instance.CameraList[this.Module][camera].Mat2D[i].CliabCenter.Y);
                return(true);
            }
            catch { return(false); }
        }
Пример #2
0
        private void imageSet_ImageMouseMove(object sender, NationalInstruments.Vision.WindowsForms.ImageMouseEventArgs e)
        {
            this.imageSet.Image.Overlays.Default.Clear();
            double angle = (double)this.nAngle.Value;

            if (bShowCross)
            {
                PointContour center = new PointContour(this.imageSet.Image.Width / 2, this.imageSet.Image.Height / 2);
                this.showCross(angle, center, Rgb32Value.RedColor);
            }

            if (GetBasePt)
            {
                BasePt = e.Point;
            }
            else if (GetCurPt)
            {
                CurPt = e.Point;
                PointF basePt = new PointF();
                PointF curPt  = new PointF();
                var    cur    = Form_Main.Instance.XYPos;
                basePt = Form_Main.Instance.Point2CCDCenter(cur, this.BasePt, CAM.Top, 0);
                curPt  = Form_Main.Instance.Point2CCDCenter(cur, this.CurPt, CAM.Top, 0);
                var          dist   = this.GetDist(basePt, curPt, (double)this.nAngle.Value);
                PointContour textPt = new PointContour();
                textPt.X = e.Point.X - 20;
                textPt.Y = e.Point.Y - 50;
                this.imageSet.Image.Overlays.Default.AddText($"X:{dist.X:N2},\r\nY:{dist.Y:N2}", textPt, Rgb32Value.BlueColor, new OverlayTextOptions("Consolas", 36));
            }

            this.showCross(angle, BasePt, Rgb32Value.YellowColor);
            this.showCross(angle, CurPt, Rgb32Value.BlueColor);
        }
Пример #3
0
        public PointContour ToReal(PointContour xy)
        {
            try
            {
                PointContour temp = new PointContour(xy.X, xy.Y);

                if (XPoly.Coefficients.Length > 0 &&
                    (xy.X >= X[0] - 20) &&
                    (xy.X <= (X.Last() + 20)))
                {
                    temp.X -= XPoly.Evaluate(xy.X);
                }

                if (YPoly.Coefficients.Length > 0 &&
                    (xy.Y >= Y[0] - 20) &&
                    (xy.Y <= Y.Last() + 20))
                {
                    temp.Y -= YPoly.Evaluate(xy.Y);
                }

                return(temp);
            }
            catch { }
            return(xy);
        }
        //////////////////////////////////////////////////////////////////////////////
        //
        //  IVA_MeasureMinDistance
        //
        //  Description:
        //      Measures the minimum distance between edges of two rake reports
        //
        //  Parameters:
        //      firstReport             -   The first rake report.
        //      secondReport            -   The second rake report.
        //      firstPerpendicularLine  -   Upon return, a line perpendicular to the
        //                                  first edge point.
        //      lastPerpendicularLine   -   Upon return, a line perpendicular to the
        //                                  last edge point.
        //      distance                -   Upon return, the distance between the two
        //                                  perpendicular lines.
        //      firstEdge               -   Upon return, the location of the first edge.
        //      lastEdge                -   Upon return, the location of the last edge.
        //
        //  Return Value:
        //      The distance
        //
        //////////////////////////////////////////////////////////////////////////////
        public static double IVA_MeasureMinDistance(RakeReport firstReport, RakeReport secondReport, out LineContour firstPerpendicularLine, out LineContour lastPerpendicularLine, out PointContour firstEdge, out PointContour lastEdge)
        {
            // Intialize all returned data to zero
            firstPerpendicularLine = new LineContour(new PointContour(0, 0), new PointContour(0, 0));
            lastPerpendicularLine  = new LineContour(new PointContour(0, 0), new PointContour(0, 0));
            firstEdge = new PointContour(0, 0);
            lastEdge  = new PointContour(0, 0);
            double distance = 0;

            // Only proceed if there was at least one rake line in each rake report
            if (firstReport.SearchLines.Count > 0 && secondReport.SearchLines.Count > 0)
            {
                // Find the edges that are closest to the boundaries of each search area
                firstEdge = IVA_FindExtremeEdge(firstReport, true);
                lastEdge  = IVA_FindExtremeEdge(secondReport, true);

                // Find the edge lines by find perpendicular lines from the edges to the rake lines.
                LineContour tempPerpendicularLine1 = Algorithms.FindPerpendicularLine(firstReport.SearchLines[0].Line, firstEdge);
                LineContour tempPerpendicularLine2 = Algorithms.FindPerpendicularLine(firstReport.SearchLines[firstReport.SearchLines.Count - 1].Line, firstEdge);
                firstPerpendicularLine.Start = tempPerpendicularLine1.End;
                firstPerpendicularLine.End   = tempPerpendicularLine2.End;
                tempPerpendicularLine1       = Algorithms.FindPerpendicularLine(firstReport.SearchLines[0].Line, lastEdge);
                tempPerpendicularLine2       = Algorithms.FindPerpendicularLine(firstReport.SearchLines[firstReport.SearchLines.Count - 1].Line, lastEdge);
                lastPerpendicularLine.Start  = tempPerpendicularLine1.End;
                lastPerpendicularLine.End    = tempPerpendicularLine2.End;

                // Compute the distance
                distance = Algorithms.FindPointDistances(new Collection <PointContour>(new PointContour[] { firstPerpendicularLine.Start, lastPerpendicularLine.Start }))[0];
            }
            return(distance);
        }
Пример #5
0
        private void OverlayCoordinateSystem(Overlay overlay, CoordinateSystem system)
        {
            const int axisLength = 150;

            // Overlay the origin point.
            overlay.AddRectangle(new RectangleContour(system.Origin.X - 2, system.Origin.Y - 2, 5, 5), Rgb32Value.RedColor, DrawingMode.PaintValue);

            // Draw the main axis line.
            double       theta    = system.Angle * Math.PI / 180.0;
            PointContour axisEnd  = new PointContour(system.Origin.X + axisLength * Math.Cos(theta), system.Origin.Y - axisLength * Math.Sin(theta));
            LineContour  axisLine = new LineContour(system.Origin, axisEnd);

            overlay.AddLine(axisLine, Rgb32Value.RedColor);
            // Draw an arrow on the end of the line.
            DrawArrow(overlay, axisLine, Rgb32Value.RedColor);

            // Overlay the main axis legend.
            overlay.AddText("X", new PointContour(axisLine.End.X - 10, axisLine.End.Y - 10), Rgb32Value.RedColor, new OverlayTextOptions("Arial", 16));

            // Overlay the secondary axis line.
            if (system.AxisOrientation == AxisOrientation.Indirect)
            {
                theta += Math.PI;
            }
            axisLine.End.Initialize(system.Origin.X - axisLength * Math.Sin(theta), system.Origin.Y - axisLength * Math.Cos(theta));
            overlay.AddLine(axisLine, Rgb32Value.RedColor);
            // Draw an arrow on the end of the line.
            DrawArrow(overlay, axisLine, Rgb32Value.RedColor);

            // Overlay the secondary axis legend.
            overlay.AddText("Y", new PointContour(axisLine.End.X - 10, axisLine.End.Y - 10), Rgb32Value.RedColor, new OverlayTextOptions("Arial", 16));
        }
Пример #6
0
        /// <summary>
        /// 点绕点旋转
        /// </summary>
        /// <param name="PTtoRotate"></param>
        /// <param name="RotateCenter"></param>
        /// <param name="RotatethetaAngle"></param>
        /// <param name="PTRotated"></param>
        public void PtRotate(PointContour PTtoRotate, PointContour RotateCenter, double RotatethetaAngle, out PointContour PTRotated)//点绕点旋转算法(逆时针为正)
        {
            double deg = RotatethetaAngle / 180.0 * Math.PI;

            PTRotated   = new PointContour();
            PTRotated.X = (PTtoRotate.X - RotateCenter.X) * (float)Math.Cos(deg) + (PTtoRotate.Y - RotateCenter.Y) * (float)Math.Sin(deg) + RotateCenter.X;
            PTRotated.Y = -(PTtoRotate.X - RotateCenter.X) * (float)Math.Sin(deg) + (PTtoRotate.Y - RotateCenter.Y) * (float)Math.Cos(deg) + RotateCenter.Y;
        }
Пример #7
0
        private void btnFindCorner_Click(object sender, EventArgs e)
        {
            PointContour cross = new PointContour();
            LineContour  line1 = new LineContour();
            LineContour  line2 = new LineContour();

            CPKTools.FindCorss(this.cbxCorner.SelectedIndex, this.cpkIni, ref cross, ref line1, ref line2);
        }
Пример #8
0
        public static void IVA_OverlayLine(VisionImage image, int[] xCoordinates, int[] yCoordinates, byte[] colors)
        {
            Rgb32Value   color      = new Rgb32Value(colors[0], colors[1], colors[2]);
            PointContour startPoint = new PointContour(xCoordinates[0], yCoordinates[0]);
            PointContour endPoint   = new PointContour(xCoordinates[1], yCoordinates[1]);

            image.Overlays.Default.AddLine(new LineContour(startPoint, endPoint), color);
        }
Пример #9
0
        public static double Get2LineAngle(PointContour p1, PointContour p2, PointContour p3, PointContour p4)
        {
            double baseLine   = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X);
            double newLine    = Math.Atan2(p4.Y - p3.Y, p4.X - p3.X);
            double deltaAngle = newLine - baseLine;

            return(deltaAngle * 180 / Math.PI);
        }
Пример #10
0
        public PointF MachinePtToActPt(PointF machinePt)
        {
            PointContour actPt = new PointContour();

            actPt.X = machinePt.X * HardwareOrgHelper.Instance[this.Module].XRate;
            actPt.Y = machinePt.Y + machinePt.X * HardwareOrgHelper.Instance[this.Module].YRate;
            actPt   = HardwareOrgHelper.Instance[this.Module].ToReal(actPt);
            return(new PointF((float)actPt.X, (float)actPt.Y));
        }
Пример #11
0
        public PointContour PtRotateDown(PointContour PTtoRotate, PointContour RotateCenter, double RotatethetaAngle)//点绕点旋转算法(逆时针为正)
        {
            double deg       = RotatethetaAngle / 180.0 * Math.PI;
            var    PTRotated = new PointContour();

            PTRotated.X = (PTtoRotate.X - RotateCenter.X) * Math.Cos(deg) + (PTtoRotate.Y - RotateCenter.Y) * Math.Sin(deg) + RotateCenter.X;
            PTRotated.Y = -(PTtoRotate.X - RotateCenter.X) * Math.Sin(deg) + (PTtoRotate.Y - RotateCenter.Y) * Math.Cos(deg) + RotateCenter.Y;
            return(PTRotated);
        }
        private void bCalRotateCenter_Click(object sender, EventArgs e)
        {
            if (fm_SoftwareCliab.FindTemp == null || fm_SoftwareCliab.FindTemp.GetInvocationList().Length <= 0)
            {
                MessageBox.Show("请打开相机轴控界面!!");
                return;
            }

            Task.Factory.StartNew(() => {
                var entiy             = SystemEntiy.Instance[this.module.Module];
                PointF curPos         = entiy.XYPos;
                Nozzle nz             = this.selectNz2.SelectNz;
                PointContour circle   = new PointContour();
                List <PointF> ImagePt = new List <PointF>();

                Camera camera = Camera.Bottom1;
                if (nz == Nozzle.Nz3 || nz == Nozzle.Nz4)
                {
                    camera = Camera.Bottom2;
                }

                // 12 次拟合
                for (int I = 0; I < 6; ++I)
                {
                    entiy.RGoAngleTillStop(I * 60, nz);
                    Thread.Sleep(200);

                    var result = fm_SoftwareCliab.FindTemp.Invoke(this.module.Module, camera);
                    if (result.State == VisionResultState.OK)
                    {
                        ImagePt.Add(new PointF((float)result.Point.X, (float)result.Point.Y));
                    }
                    else
                    {
                        MessageBox.Show("侦测失败!!");
                        return;
                    }
                }
                double x, y, r = 0;

                if (VisionHelper.FitCircle(ImagePt.ToArray(), out x, out y, out r))
                {
                    circle.X = x;
                    circle.Y = y;
                    this.BeginInvoke(new Action(() => {
                        this.tDetectX.Text = x.ToString("f3");
                        this.tDetectY.Text = y.ToString("f3");
                    }));

                    MessageBox.Show("旋转中心检测成功!!");
                }
                else
                {
                    MessageBox.Show("拟合圆失败!!");
                }
            });
        }
Пример #13
0
        public PointF ActPtToMachinePt(PointF actPt)
        {
            PointContour machinePt = new PointContour();
            PointContour Pt        = new PointContour(actPt.X, actPt.Y);

            Pt          = HardwareOrgHelper.Instance[this.Module].ToMachine(Pt);
            machinePt.X = Pt.X / HardwareOrgHelper.Instance[this.Module].XRate;
            machinePt.Y = Pt.Y - machinePt.X * HardwareOrgHelper.Instance[this.Module].YRate;
            return(new PointF((float)machinePt.X, (float)machinePt.Y));
        }
Пример #14
0
        private void MeasureDistortionTarget(VisionImage image, Collection <PointContour> pixelPoints, Collection <PointContour> realWorldPoints, Direction d)
        {
            OverlayTextOptions overlayOptions = new OverlayTextOptions("Arial", 16);

            overlayOptions.TextDecoration.Bold = true;
            if (d == Direction.Horizontal)
            {
                overlayOptions.HorizontalAlignment = HorizontalTextAlignment.Right;
                overlayOptions.VerticalAlignment   = VerticalTextAlignment.Baseline;
            }
            else
            {
                overlayOptions.HorizontalAlignment = HorizontalTextAlignment.Center;
                overlayOptions.VerticalAlignment   = VerticalTextAlignment.Bottom;
            }
            for (int i = 0; i < 3; ++i)
            {
                // Measure the real-world distance.
                Collection <PointContour> realWorldDistancePoints = new Collection <PointContour>();
                realWorldDistancePoints.Add(realWorldPoints[2 * i]);
                realWorldDistancePoints.Add(realWorldPoints[9 - 2 * i]);
                double realWorldDistance = Algorithms.FindPointDistances(realWorldDistancePoints)[0];

                // Find the line to overlay.
                LineContour line = new LineContour();
                line.Start = pixelPoints[2 * i];
                line.End   = pixelPoints[9 - 2 * i];

                if (d == Direction.Horizontal)
                {
                    // Measurement is horizontal, so arrows stack vertically.
                    line.Start.Y += (2 - i) * 30;
                    line.End.Y   += (2 - i) * 30;
                }
                else
                {
                    // Measurement is vertical, so arrows stack horizontally.
                    line.Start.X += (2 - i) * 30;
                    line.End.X   += (2 - i) * 30;
                }

                // Draw the line with arrows.
                image.Overlays.Default.AddLine(line, Rgb32Value.RedColor);
                DrawArrow(image.Overlays.Default, line, Rgb32Value.RedColor);
                // Flip the start and end to draw an arrow at the beginning.
                PointContour tempStart = line.Start;
                line.Start = line.End;
                line.End   = tempStart;
                DrawArrow(image.Overlays.Default, line, Rgb32Value.RedColor);

                // Find the origin of the text to overlay.
                image.Overlays.Default.AddText(String.Format("{0:0.00}", realWorldDistance), tempStart, Rgb32Value.RedColor, overlayOptions);
            }
        }
        /////////////////////////////////////////////////////////////////////////////////
        ///
        /// Function Name: IVA_GetPoint
        ///
        /// Description  : Retrieves a point from the PointsResults array
        ///
        /// Parameters   : ivaData     -  Internal data structure
        ///                stepIndex   -  Index of the step that produced the point
        ///                pointIndex  -  Index of the x value.
        ///
        /// Return Value : point
        ///
        /////////////////////////////////////////////////////////////////////////////////
        public static PointContour IVA_GetPoint(IVA_Data ivaData, int stepIndex, int pointIndex)
        {
            PointContour point = new PointContour();

            if ((pointIndex + 1) < ivaData.stepResults[stepIndex].results.Count)
            {
                point.X = ivaData.stepResults[stepIndex].results[pointIndex].resultVal.numVal;
                point.Y = ivaData.stepResults[stepIndex].results[pointIndex + 1].resultVal.numVal;
            }
            return(point);
        }
Пример #16
0
        private void DisplayDistance(PointContour point1, PointContour point2)
        {
            Collection <PointContour> points = new Collection <PointContour>(new PointContour[] { point1, point2 });
            double             distance      = Algorithms.FindPointDistances(points)[0];
            OverlayTextOptions textOptions   = new OverlayTextOptions();

            textOptions.FontSize            = 14;
            textOptions.BackgroundColor     = Rgb32Value.WhiteColor;
            textOptions.HorizontalAlignment = HorizontalTextAlignment.Center;
            imageViewer1.Image.Overlays.Default.AddText(String.Format("{0:0.00}", distance), new PointContour((point1.X + point2.X) / 2, (point1.Y + point2.Y) / 2), Rgb32Value.BlackColor, textOptions);
        }
Пример #17
0
        public void showCross(double angle, PointContour center, Rgb32Value colcor)
        {
            double      rate  = angle / 180 * Math.PI;
            LineContour line1 = new LineContour(new PointContour(center.X - 2000 * Math.Sin(rate), center.Y - 2000 * Math.Cos(rate)),
                                                new PointContour(center.X + 2000 * Math.Sin(rate), center.Y + 2000 * Math.Cos(rate)));

            LineContour line2 = new LineContour(new PointContour(center.X + 2000 * Math.Cos(rate), center.Y - 2000 * Math.Sin(rate)),
                                                new PointContour(center.X - 2000 * Math.Cos(rate), center.Y + 2000 * Math.Sin(rate)));

            this.imageSet.Image.Overlays.Default.AddLine(line1, colcor);
            this.imageSet.Image.Overlays.Default.AddLine(line2, colcor);
        }
Пример #18
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);
        }
Пример #19
0
        /// <summary>
        /// 求旋转中心过后的点
        /// </summary>
        /// <param name="nz"></param>
        /// <param name="imagePt"></param>
        /// <param name="angle"></param>
        /// <returns></returns>
        public PointF RotatePtDown(Nozzle nz, PointContour imagePt, double angle)
        {
            var rotatedPt = Vision.VisionHelper.PtRotate(imagePt, this.MachineConfig[nz].RotatePoint, angle);

            PointF wroldPt = new PointF();

            if (!this.WroldPt(nz, this.MachineConfig[nz].RotateCamPoint, rotatedPt, out wroldPt))
            {
                return(this.MachineConfig[nz].RotateCamPoint);
            }

            return(wroldPt);
        }
 private void button4_Click(object sender, EventArgs e)
 {
     if (Form_Main.Instance.imageSet.Roi.Count > 0 && Form_Main.Instance.imageSet.Roi[0].Shape.GetType() == typeof(RectangleContour))
     {
         RectangleContour rect   = (RectangleContour)Form_Main.Instance.imageSet.Roi[0].Shape;
         PointContour     center = new PointContour();
         center.X = rect.Left + rect.Width / 2;
         center.Y = rect.Top + rect.Height / 2;
         PointF xyPos = new PointF((float)Form_Main.Instance.X.Pos, (float)Form_Main.Instance.Y.Pos);
         nz4      = Form_Main.Instance.Point2CCDCenter(xyPos, center, Camera.CAM.Bottom1);
         isCaled4 = true;
     }
 }
Пример #21
0
        public static PaletteType ProcessImage(VisionImage image)
        {
            // Initialize the IVA_Data structure to pass results and coordinate systems.
            IVA_Data ivaData = new IVA_Data(2, 0);

            // Creates a new, empty region of interest.
            Roi roi = new Roi();

            // 建一條巡邊線Star(229,40) End(229,300)
            PointContour vaStartPoint = new PointContour(229, 40);
            PointContour vaEndPoint   = new PointContour(229, 300);
            LineContour  vaLine       = new LineContour(vaStartPoint, vaEndPoint);

            roi.Add(vaLine);

            // 邊緣偵測;採用簡單邊緣偵測方式
            SimpleEdgeOptions vaSimpleEdgeOptions = new SimpleEdgeOptions();

            vaSimpleEdgeOptions.Process    = EdgeProcess.All;
            vaSimpleEdgeOptions.Type       = LevelType.Absolute;
            vaSimpleEdgeOptions.Threshold  = 128;
            vaSimpleEdgeOptions.Hysteresis = 2;
            vaSimpleEdgeOptions.SubPixel   = true;
            simpleEdges = IVA_SimpleEdge(image, roi, vaSimpleEdgeOptions, ivaData, 0);
            roi.Dispose();

            // Caliper
            // Delete all the results of this step (from a previous iteration)
            Functions.IVA_DisposeStepResults(ivaData, 1);

            // Computes the vaDistance between two points.
            Collection <double> vaDistance = IVA_GetDistance(image, ivaData, 1, 0, 3, 0, 5);

            caliperDistance = vaDistance[0];

            // Dispose the IVA_Data structure.
            ivaData.Dispose();

            //列出相關AOI資料
            MessageBox.Show("座標點1" + simpleEdges[2].ToString() + "\r\n" +
                            "座標點2" + simpleEdges[0].ToString() + "\r\n" +
                            "座標點3" + simpleEdges[1].ToString() + "\r\n" + "\r\n" +
                            "間距量測" + caliperDistance.ToString());

            //繪出檢測直線(巡邊線)
            //Graphics g = Graphics.FromImage(FileName)
            //g.DrawLine(0, 0, 100, 100);

            // Return the palette type of the final image.
            return(PaletteType.Gray);
        }
Пример #22
0
        /// <summary>
        /// 图像上坐标转位机器坐标
        /// </summary>
        /// <param name="capturePt"></param>
        /// <param name="pixelPt"></param>
        /// <returns></returns>
        public PointF ImagePt2WorldPt(PointF capturePt, PointContour pixelPt, int calib)
        {
            PointF pos         = new PointF();
            var    coordreport = Algorithms.ConvertPixelToRealWorldCoordinates(this.CalibImage[calib], pixelPt);

            if (coordreport.Points.Count == 0)
            {
                return(pos);
            }

            pos.X = (float)(capturePt.X - (coordreport.Points[0].X - this.CenterPt[calib].X));
            pos.Y = (float)(capturePt.Y - (coordreport.Points[0].Y - this.CenterPt[calib].Y));
            return(pos);
        }
Пример #23
0
        /// <summary>
        /// 获得实际坐标
        /// </summary>
        /// <param name="camera">输入-相机</param>
        /// <param name="capturePt">输入-拍照位置</param>
        /// <param name="imagePt">输入-图像坐标</param>
        /// <param name="wroldPt">输出-实际坐标</param>
        /// <returns></returns>
        public bool WroldPt(Camera camera, PointF capturePt, PointContour imagePt, out PointF wroldPt)
        {
            wroldPt = new PointF();

            try
            {
                PointF pt1 = CameraDefine.Instance.CameraList[this.Module][camera].Mat2D[0].Pixel2World(imagePt);
                wroldPt.X = capturePt.X - (pt1.X - CameraDefine.Instance.CameraList[this.Module][camera].Mat2D[0].CliabCenter.X);
                wroldPt.Y = capturePt.Y - (pt1.Y - CameraDefine.Instance.CameraList[this.Module][camera].Mat2D[0].CliabCenter.Y);
                return(true);
            }
            catch { return(false); }
            //return
        }
        //////////////////////////////////////////////////////////////////////////////
        //
        //  IVA_FindExtremeEdge
        //
        //  Description:
        //      Finds the edge that is either closest or farthest from the start
        //      of a set of rake lines.
        //
        //  Parameters:
        //      report          -   The rake report to process.
        //      findClosestEdge -   The direction of the main axis.
        //                          If false, report must contain both first and last
        //                          edge information
        //
        //  Return Value:
        //      The extreme edge
        //
        //////////////////////////////////////////////////////////////////////////////
        public static PointContour IVA_FindExtremeEdge(RakeReport report, bool findClosestEdge)
        {
            Double       extremeDistance;
            Double       tempDistance;
            PointContour edge = new PointContour(0, 0);

            // Determine if the function should process the first edges or the last edges array
            if (findClosestEdge)
            {
                if (report.FirstEdges.Count > 0)
                {
                    extremeDistance = report.FirstEdges[0].Distance;
                    edge            = report.FirstEdges[0].Position;

                    // Then find the edge that is closest to the boundary of the search area
                    for (int i = 1; i < report.FirstEdges.Count; i++)
                    {
                        tempDistance = report.FirstEdges[i].Distance;
                        if (tempDistance < extremeDistance)
                        {
                            extremeDistance = tempDistance;
                            edge            = report.FirstEdges[i].Position;
                        }
                    }
                }
            }
            else
            {
                if (report.LastEdges.Count > 0)
                {
                    // First, intialize the value with the first edge in the array
                    extremeDistance = report.LastEdges[0].Distance;
                    edge            = report.LastEdges[0].Position;

                    // Then find the edge that are closest to the boundary of the search area
                    for (int i = 1; i < report.LastEdges.Count; i++)
                    {
                        tempDistance = report.LastEdges[i].Distance;
                        if (tempDistance < extremeDistance)
                        {
                            extremeDistance = tempDistance;
                            edge            = report.LastEdges[i].Position;
                        }
                    }
                }
            }

            return(edge);
        }
Пример #25
0
        public static PaletteType ProcessImage(VisionImage image)
        {
            // Initialize the IVA_Data structure to pass results and coordinate systems.
            IVA_Data ivaData = new IVA_Data(4, 0);

            // Creates a new, empty region of interest.
            Roi roi = new Roi();
            // Creates a new AnnulusContour using the given values.
            PointContour   vaCenter = new PointContour(1295, 970);
            AnnulusContour vaOval   = new AnnulusContour(vaCenter, 412, 954, 0, 0);

            roi.Add(vaOval);
            // Find Circular Edge
            EdgeOptions vaOptions = new EdgeOptions();

            vaOptions.ColumnProcessingMode = ColumnProcessingMode.Average;
            vaOptions.InterpolationType    = InterpolationMethod.Bilinear;
            vaOptions.KernelSize           = 3;
            vaOptions.MinimumThreshold     = 50;
            vaOptions.Polarity             = EdgePolaritySearchMode.Rising;
            vaOptions.Width = 3;
            CircularEdgeFitOptions vaFitOptions = new CircularEdgeFitOptions();

            vaFitOptions.ProcessType    = RakeProcessType.GetBestEdges;
            vaFitOptions.StepSize       = 10;
            vaFitOptions.MaxPixelRadius = 3;

            vaCircularEdgeReport = IVA_FindCircularEdge(image, roi, SpokeDirection.InsideToOutside, vaOptions, vaFitOptions, ivaData, 1);

            roi.Dispose();

            // Overlays a line onto the image.
            int[]  xCoords = { 1296, 1296 };
            int[]  yCoords = { 0, 1944 };
            byte[] vaColor = { 6, 0, 239 };
            IVA_OverlayLine(image, xCoords, yCoords, vaColor);

            // Overlays a line onto the image.
            int[]  xCoords2 = { 0, 2592 };
            int[]  yCoords2 = { 972, 972 };
            byte[] vaColor2 = { 6, 0, 239 };
            IVA_OverlayLine(image, xCoords2, yCoords2, vaColor2);

            // Dispose the IVA_Data structure.
            ivaData.Dispose();

            // Return the palette type of the final image.
            return(PaletteType.Gray);
        }
Пример #26
0
        private void btnFindCircle1_Click(object sender, EventArgs e)
        {
            if (Form_Main.Instance.imageSet.Roi.Count > 0 && Form_Main.Instance.imageSet.Roi[0].Shape.GetType() == typeof(RectangleContour))
            {
                short        rMin   = short.Parse(this.upCircleRmin.Text);
                short        rMax   = short.Parse(this.upCircleRmax.Text);
                PointContour center = new PointContour();
                double       radius = 0;
                VisionImage  image  = Form_Main.Instance.GrabImage2View(Camera.CAM.Top);

                RectangleContour rect = (RectangleContour)Form_Main.Instance.imageSet.Roi[0].Shape;
                CPKTools.FindCircle(image, rect, rMin, rMax, ref center, ref radius, 0, 0, 0);
                this.upCurR.Text = radius.ToString();
            }
        }
 /// <summary>
 /// 重置自动运行参数
 /// </summary>
 public void ResetAutoRunParam()
 {
     Nozzle_Down_Angle       = 0;
     Nozzle_DownXY_Pos       = new PointContour();
     RUN_PasteRealAngle      = 0;
     RUN_PasteRealPoint      = new PointF();
     RUN_PastePointIndex     = 0;
     RUN_Nozzle_FeederIndex  = 0;
     RUN_dNozzleDownVisionED = 1;
     RUN_bNozzleUse          = false;
     RUN_PasteInfoIndex_List = 0;
     RUN_PasteInfoIndex      = 0;
     RUN_MarkCount           = 0;
     this.RUN_ZHeight        = 0;
 }
Пример #28
0
        private static Collection <PointContour> IVA_SimpleEdge(VisionImage image,
                                                                Roi roi,
                                                                SimpleEdgeOptions simpleEdgeOptions,
                                                                IVA_Data ivaData,
                                                                int stepIndex)
        {
            // Calculates the profile of the pixels along the edge of each contour in the region of interest.
            using (VisionImage monoImage = new VisionImage(ImageType.U8, 7))
            {
                if (image.Type == ImageType.Rgb32 || image.Type == ImageType.Hsl32)
                {
                    Algorithms.ExtractColorPlanes(image, ColorMode.Hsl, null, null, monoImage);
                }
                else
                {
                    Algorithms.Copy(image, monoImage);
                }

                RoiProfileReport roiProfile = Algorithms.RoiProfile(monoImage, roi);

                // Finds prominent edges along the array of pixel coordinates.
                Collection <PointContour> edges = Algorithms.SimpleEdge(monoImage, roiProfile.Pixels, simpleEdgeOptions);

                // Store the results in the data structure.

                // First, delete all the results of this step (from a previous iteration)
                Functions.IVA_DisposeStepResults(ivaData, stepIndex);

                ivaData.stepResults[stepIndex].results.Add(new IVA_Result("# of Edges", edges.Count));

                for (int i = 0; i < edges.Count; ++i)
                {
                    ivaData.stepResults[stepIndex].results.Add(new IVA_Result(String.Format("Edge {0}.X Position (Pix.)", i + 1), edges[i].X));
                    ivaData.stepResults[stepIndex].results.Add(new IVA_Result(String.Format("Edge {0}.Y Position (Pix.)", i + 1), edges[i].Y));

                    // If the image is calibrated, convert the pixel values to real world coordinates.
                    if ((image.InfoTypes & InfoTypes.Calibration) != 0)
                    {
                        PointContour      edgeLocation      = new PointContour(edges[i].X, edges[i].Y);
                        CoordinatesReport realWorldPosition = Algorithms.ConvertPixelToRealWorldCoordinates(image, new Collection <PointContour>(new PointContour[] { edgeLocation }));

                        ivaData.stepResults[stepIndex].results.Add(new IVA_Result(String.Format("Edge {0}.X Position (World)", i + 1), realWorldPosition.Points[0].X));
                        ivaData.stepResults[stepIndex].results.Add(new IVA_Result(String.Format("Edge {0}.Y Position (World)", i + 1), realWorldPosition.Points[0].Y));
                    }
                }
                return(edges);
            }
        }
        private void bFindCircle_Click(object sender, EventArgs e)
        {
            if (this.dGV_Global.SelectedRows.Count > 0 &&
                this.dGV_Global.SelectedRows[0].Index <= this.dGV_Global.Rows.Count - 1 &&
                Form_Main.Instance.imageSet.Roi.Count > 0 &&
                Form_Main.Instance.imageSet.Roi[0].Shape.GetType() == typeof(RectangleContour))
            {
                int       row  = this.dGV_Global.SelectedRows[0].Index;
                MarkEntiy temp = ViewModel.Mark[row];

                short minr = short.Parse(tMinR.Text);
                short maxr = short.Parse(tMaxR.Text);
                temp.MinR = minr;
                temp.MaxR = maxr;

                PointContour a   = new PointContour();
                double       r   = 0;
                short        rtn = Form_Main.Instance.CamDetect_Circle(Form_Main.Instance.imageSet.Image, Form_Main.Instance.imageSet.Roi, minr, maxr, ref a, ref r);

                if (rtn == 0)
                {
                    var    rect    = (RectangleContour)Form_Main.Instance.imageSet.Roi[0].Shape;
                    string strRect = rect.Top.ToString("f3");
                    strRect += ",";
                    strRect += rect.Left.ToString("f3");
                    strRect += ",";
                    strRect += rect.Width.ToString("f3");
                    strRect += ",";
                    strRect += rect.Height.ToString("f3");
                    temp.ROI = strRect;

                    PointF xy = new PointF();
                    xy.X = (float)Form_Main.Instance.X.Pos;
                    xy.Y = (float)Form_Main.Instance.Y.Pos;

                    temp.MarkXY = Form_Main.Instance.Point2CCDCenter(xy, a, Camera.CAM.Top, 0);// Camera.CameraDefine.Instance[Camera.CAM.Top].ImagePt2WorldPt(xy, a, 0);

                    ViewModel.BaseAngle = Form_Main.Instance.getAngle(ViewModel.Mark[0].MarkXY.X, ViewModel.Mark[0].MarkXY.Y,
                                                                      ViewModel.Mark[1].MarkXY.X, ViewModel.Mark[1].MarkXY.Y);
                    this.tBaseAngle.Text = ViewModel.BaseAngle.ToString("f3");
                    UpdateToRow(row);
                }
                else
                {
                    MessageBox.Show("侦测失败");
                }
            }
        }
        //////////////////////////////////////////////////////////////////////////////
        //
        //  IVA_ComputePMOffset
        //
        //  Description:
        //      Computes the offset based on the new angle
        //
        //  Parameters:
        //      matchOffsetX  -  match offset X
        //      matchOffsetY  -  match offset Y
        //      angle         -  match angle
        //
        //  Return Value:
        //      offset as PointContour
        //
        //////////////////////////////////////////////////////////////////////////////
        public static PointContour IVA_ComputePMOffset(double matchOffsetX, double matchOffsetY, double angle)
        {
            Collection <PointContour> points = new Collection <PointContour>();

            points.Add(new PointContour(0, 0));
            points.Add(new PointContour(matchOffsetX, matchOffsetY));

            Collection <double> distances = Algorithms.FindPointDistances(points);
            double r       = distances[0];
            double teta    = Math.Atan2(matchOffsetY, matchOffsetX);
            double newTeta = teta - (angle * 2 * Math.PI / 360);

            PointContour matchOffset = new PointContour(r * Math.Cos(newTeta), r * Math.Sin(newTeta));

            return(matchOffset);
        }