Esempio n. 1
0
        public bool setTarget(List <HHomMat2D> mat2DsList)
        {
            if (mat2DsList == null || mat2DsList.Count < 1)
            {
                return(false);
            }

            if (GrabXld != null && GrabXld.IsInitialized())
            {
                GrabXld.Dispose();
            }
            if (GrabXld == null)
            {
                GrabXld = new HXLDCont();
                GrabXld.GenEmptyObj();
            }

            GrabRowTarget = new HTuple();
            GrabColTarget = new HTuple();
            HTuple rowTemp, colTemp;

            for (int i = 0; i < mat2DsList.Count; i++)
            {
                HOperatorSet.AffineTransPoint2d(mat2DsList[i], new HTuple(GrabRowOrg), new HTuple(GrabColOrg), out rowTemp, out colTemp);
                GrabRowTarget = GrabRowTarget.TupleConcat(rowTemp);
                GrabColTarget = GrabColTarget.TupleConcat(colTemp);
            }
            return(true);
        }
        /// <summary>
        /// 测试标定
        /// </summary>
        /// <returns></returns>
        public bool ceShiBiaoDing(ICalibrationShuJu Ical_, ref string col_pixel_x, ref string row_pixel_y)
        {
            bool ok = false;

            if (Ical_.HomMat2D == null)
            {
                return(false);
            }

            if ((col_pixel_x == "") || (row_pixel_y == ""))
            {
                return(false);
            }
            double x = Convert.ToDouble(col_pixel_x);
            double y = Convert.ToDouble(row_pixel_y);
            HTuple hv_col_x, hv_row_y, hv_x_col_out, hv_y_row_out;

            hv_col_x = x;
            hv_row_y = y;

            //HOperatorSet.AffineTransPixel(Ical_.HomMat2D, hv_col_x, hv_row_y, out hv_x_col_out, out hv_y_row_out);

            HOperatorSet.AffineTransPoint2d(Ical_.HomMat2D, hv_col_x, hv_row_y, out hv_x_col_out, out hv_y_row_out);

            col_pixel_x = hv_x_col_out.D.ToString();
            row_pixel_y = hv_y_row_out.D.ToString();

            ok = true;
            return(ok);
        }
        /// <summary>
        /// UserControls under Windows Forms do not support the mouse wheel event.
        /// As a solution, the user can set his MouseWheel event in his form to
        /// call this method.
        /// Please notice that the Visual Studio Designer does not show this event.
        /// The reason is that UserControls do not support this type of event.
        /// Hence, you need to manually add it to the initialization code of your
        /// Windows Form, and set it to call the HSmartWindowControl_MouseWheel
        /// method of the HALCON Window Control.
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void HSmartWindowControl_MouseWheel(object sender, MouseEventArgs e)
        {
            HMouseEventArgs e1 = (HMouseEventArgs)null;

            try
            {
                if (this._zooming != HSmartWindowControl.ZoomContent.Off)
                {
                    HTuple homMat2DIdentity;
                    HOperatorSet.HomMat2dIdentity(out homMat2DIdentity);
                    Point  client = this.PointToClient(Cursor.Position);
                    double rowImage;
                    double columnImage;
                    this._hwindow.ConvertCoordinatesWindowToImage((double)client.Y, (double)client.X, out rowImage, out columnImage);
                    double num = e.Delta < 0 ? Math.Sqrt(2.0) : 1.0 / Math.Sqrt(2.0);
                    if (this.HZoomContent == HSmartWindowControl.ZoomContent.WheelBackwardZoomsIn)
                    {
                        num = 1.0 / num;
                    }
                    for (int index = Math.Abs(e.Delta) / 120; index > 1; --index)
                    {
                        num *= e.Delta < 0 ? Math.Sqrt(2.0) : 1.0 / Math.Sqrt(2.0);
                    }
                    HTuple homMat2DScale;
                    HOperatorSet.HomMat2dScale(homMat2DIdentity, (HTuple)num, (HTuple)num, (HTuple)columnImage, (HTuple)rowImage, out homMat2DScale);
                    double l1;
                    double c1;
                    double l2;
                    double c2;
                    this.GetFloatPart(this._hwindow, out l1, out c1, out l2, out c2);
                    HTuple qx1;
                    HTuple qy1;
                    HOperatorSet.AffineTransPoint2d(homMat2DScale, (HTuple)c1, (HTuple)l1, out qx1, out qy1);
                    HTuple qx2;
                    HTuple qy2;
                    HOperatorSet.AffineTransPoint2d(homMat2DScale, (HTuple)c2, (HTuple)l2, out qx2, out qy2);
                    e1 = this.ToHMouse(e);
                    try
                    {
                        this._hwindow.SetPart((HTuple)qy1.D, (HTuple)qx1.D, (HTuple)qy2.D, (HTuple)qx2.D);
                    }
                    catch (Exception ex)
                    {
                        this._hwindow.SetPart((HTuple)l1, (HTuple)c1, (HTuple)l2, (HTuple)c2);
                    }
                }
            }
            catch (HalconException ex)
            {
                if (this.HErrorNotify != null)
                {
                    this.HErrorNotify(ex);
                }
            }
            if (this.HMouseWheel == null)
            {
                return;
            }
            this.HMouseWheel((object)this, e1);
        }
Esempio n. 4
0
        public void CreateUpDownCameraCoor(double[] ux, double[] uy, double[] dx, double[] dy)
        {
            try
            {
                if (ux.Length != uy.Length || ux.Length != dx.Length || ux.Length != dy.Length || ux.Length == 0)
                {
                    return;
                }
                HTuple Hom2D;
                HOperatorSet.VectorToHomMat2d(ux, uy, dx, dy, out Hom2D);
                m_Hom2Dutd = Hom2D.Clone();
                HOperatorSet.VectorToHomMat2d(dx, dy, ux, uy, out Hom2D);
                m_Hom2Ddtu = Hom2D.Clone();

                HTuple qx, qy;
                HTuple qx1, qy1;
                HOperatorSet.AffineTransPoint2d(m_Hom2Ddtu, dx[0], dy[0], out qx, out qy);
                HOperatorSet.AffineTransPoint2d(m_Hom2Dutd, qx, qy, out qx1, out qy1);
            }
            catch (Exception e)
            {
                String S = e.Message;
            }

            return;
        }
        private async void button1_Click_1(object sender, EventArgs e)
        {
            HObject _image = HardWareManager.Instance.Cmaera.SnapShot();

            VisionManager.Instance.ShapeModle.BackImage = _image.Clone();
            //DelegateControls.Instance.
            ModleFindResult result = VisionManager.Instance.ShapeModle.FindSimple();

            // return;
            if (result != null)
            {
                HTuple hommate2d;
                HOperatorSet.VectorAngleToRigid(0, 0, 0, result.Row, result.Column, result.Angle, out hommate2d);
                HOperatorSet.AffineTransContourXld(result.ModleRegion, out HObject hObject, hommate2d);
                RegionX regionX = new RegionX(hObject, "green");
                DelegateControls.Instance.DelegateHdisplay("FormMain_hDisplay1", _image, new List <HalWindow.RegionX>()
                {
                    regionX
                });
                HTuple calibratedata = VisionManager.Instance.Calibrate.CalibrateData;

                HTuple _x = new HTuple();
                HTuple _y = new HTuple();
                HOperatorSet.AffineTransPoint2d(calibratedata, result.Row, result.Column, out HTuple x, out HTuple y);
                HOperatorSet.AffineTransPoint2d(calibratedata, 1024, 1536, out _x, out _y);
                double   ox       = -x + _x + VisionManager.Instance.Calibrate.ToolOffsetX;
                double   oy       = -y + _y + VisionManager.Instance.Calibrate.ToolOffsetY;
                RobotPos robotPos = await HardWareManager.Instance.YaskawaRobot.GetRobotCPoint();

                double x1 = ox + robotPos.Y;
                double x2 = oy + robotPos.Z;
            }
        }
 public void GetRobotpoint(HTuple imageX, HTuple imageY, ref HTuple robotoffsetX, ref HTuple robotoffsetY)
 {
     HOperatorSet.AffineTransPoint2d(calibratedata, imageX, imageY, out HTuple x, out HTuple y);
     HOperatorSet.AffineTransPoint2d(calibratedata, 1024, 1536, out HTuple _x, out HTuple _y);
     robotoffsetX = _x - x + tooloffsetX;
     robotoffsetY = _y - y + tooloffsetY;
 }
Esempio n. 7
0
        public void AffineTransPoint()
        {
            TransLocationCross.Clear();
            ShapeMatchResult matchResult = Shape.OutputResult;

            for (int i = 0; i < matchResult.Count; i++)
            {
                HHomMat2D mat2d = new HHomMat2D();
                mat2d.VectorAngleToRigid(Shape.ModelImgRow, Shape.ModelImgCol, Shape.ModelimgAng,
                                         matchResult.Row[i].D, matchResult.Col[i].D, matchResult.Angle[i].D);
                PointF[] fs = Array.ConvertAll <Cross, PointF>(locationCross.GetAllPointFs(), e => e.Pixel);
                HTuple   tx, ty;
                HOperatorSet.AffineTransPoint2d(mat2d,
                                                Array.ConvertAll <PointF, double>(fs, e => e.Y).ToArray(),
                                                Array.ConvertAll <PointF, double>(fs, e => e.X).ToArray(),
                                                out ty,
                                                out tx);

                for (int m = 0; m < locationCross.Count; m++)
                {
                    Cross cross = new Cross();
                    cross.Pixel = new PointF(tx[m].F, ty[m].F);
                    cross.Angle = matchResult.Angle[m].D;
                    cross.Color = "green";
                    TransLocationCross.Add(cross);
                }
            }
        }
Esempio n. 8
0
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            try
            {
                double virx = (double)vir_x.Value;
                double viry = (double)vir_y.Value;

                if (HomMat2Dxy.Type != HTupleType.EMPTY)
                {
                    HTuple realx = 0, realy = 0, realz = 0;
                    HOperatorSet.AffineTransPoint2d(HomMat2Dxy, virx, viry, out realx, out realy);
                    HTuple tx = 0;
                    HTuple real_x1, real_y1;
                    if (HomMat2Dxy.Length > 0)
                    {
                        HOperatorSet.AffineTransPoint2d(HomMat2Dxy, virx, viry, out real_x1, out real_y1);
                    }
                    Realx.Value = (decimal)realx.D;
                    Realy.Value = (decimal)realy.D;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 9
0
        public static bool calculateAffineMatrix(HTuple col, HTuple row, HTuple x, HTuple y, out HTuple matrix, out HTuple err)
        {
            matrix = null;
            err    = null;
            HTuple qx, qy;
            HTuple distance, mean, max, min;

            try
            {
                HOperatorSet.VectorToHomMat2d(col, row, x, y, out matrix);

                if (null != matrix && 0 < matrix.Length)
                {
                    HOperatorSet.AffineTransPoint2d(matrix, col, row, out qx, out qy);
                    HOperatorSet.DistancePp(y, x, qy, qx, out distance);
                    HOperatorSet.TupleAbs(distance, out distance);
                    HOperatorSet.TupleMean(distance, out mean);
                    HOperatorSet.TupleMax(distance, out max);
                    HOperatorSet.TupleMin(distance, out min);
                    err    = new HTuple();
                    err[0] = mean;
                    err[1] = max;
                    err[2] = min;

                    return(true);
                }
            }
            catch (HalconException ex)
            {
                string msg = ex.GetErrorMessage();
            }
            return(false);
        }
        public void ReverseTransPoint2d(HTuple x, HTuple y, out HTuple tx, out HTuple ty)
        {
            HHomMat2D mat2D = matrix.HomMat2dInvert();

            Debug.Assert((x != null) && (y != null));
            Debug.Assert(x.Length == y.Length, string.Format("输入参数长度错误:x={0},Y={1}", x.Length, y.Length));
            HOperatorSet.AffineTransPoint2d(mat2D, x, y, out tx, out ty);
        }
Esempio n. 11
0
        private void AssignCoordinatePoint(Point point)
        {
            HTuple xOut, yOut;

            HOperatorSet.AffineTransPoint2d(_changeOfBaseInv, point.ImageX, point.ImageY, out xOut, out yOut);
            point.CoordinateX = xOut;
            point.CoordinateY = yOut;
        }
Esempio n. 12
0
        private void SavePho2butt_Click(object sender, EventArgs e)
        {
            if (camera3.IsCameraOpen())
            {
                camera3.StopCamera();
                //EnbToolBtn(true);
                McamStatusLbl.Text      = "Idle...";
                McamStatusLbl.BackColor = Color.Orange;
            }

            for (int c = 0; c < 3; c++)
            {
                if (c == 1)
                {
                    camera3.SetExposure(Para.RobotExposeTime + Convert.ToInt32((Convert.ToDouble(Para.RobotExposeTime) * 0.5)));
                }
                if (c == 2)
                {
                    camera3.SetExposure(Para.RobotExposeTime + Convert.ToInt32((Convert.ToDouble(Para.RobotExposeTime) * 1)));
                }

                bool GrabPass = false;
                for (int j = 0; j < 3; j++)
                {
                    if (camera3.Grab())
                    {
                        GrabPass = true;
                        break;
                    }
                    Application.DoEvents();
                }
                if (!GrabPass)
                {
                    return;
                }
                RobotData RDate = hWndCtrl3.RobotInspect(camera3.myImage, RobotClassPath + "\\Mod2");
                if (RDate.Found)
                {
                    HTuple hv_ReTuple = new HTuple();
                    HOperatorSet.ReadTuple(Para.RobotCurrentClass + "\\Mod2" + "\\BiaoDing2.tup", out hv_ReTuple);

                    HTuple xx, yy;
                    HOperatorSet.AffineTransPoint2d(hv_ReTuple, RDate.CenterX, RDate.CenterY, out xx, out yy);

                    hWndCtrl3.RobotMod[1].CenterX     = xx;
                    hWndCtrl3.RobotMod[1].CenterY     = yy;
                    hWndCtrl3.RobotMod[1].CenterAngle = RDate.CenterAngle;

                    hWndCtrl3.Save(mchSettingsFilePath);

                    MessageBox.Show("Photo2 Pos Save OK");
                    return;
                }
            }
            MessageBox.Show("Photo2 Pos Save Error");
        }
Esempio n. 13
0
        public override XYUPoint GetObjPonit(XYUPoint objVisoionpoint, XYUPoint SanpMachinePoint)
        {
            XYUPoint ObjPoint = new XYUPoint();
            HTuple   qx, qy;

            HOperatorSet.AffineTransPoint2d(m_Hom2Dutr, objVisoionpoint.x, objVisoionpoint.y, out qx, out qy);
            ObjPoint.x = SanpMachinePoint.x - qx[0].D;
            ObjPoint.y = SanpMachinePoint.y - qy[0].D;
            return(ObjPoint);
        }
Esempio n. 14
0
        public XYUPoint GetDispOrLaserPoint(XYUPoint OldMachineModlePos, XYUPoint NowMachineModlePos, XYUPoint OldPinPos)
        {
            HOperatorSet.VectorAngleToRigid(OldMachineModlePos.x, OldMachineModlePos.y, 0, NowMachineModlePos.x, NowMachineModlePos.y, NowMachineModlePos.u, out HTuple hom2d);
            HTuple qx, qy;

            HOperatorSet.AffineTransPoint2d(hom2d, OldPinPos.x, OldPinPos.y, out qx, out qy);
            XYUPoint NowPoint = new XYUPoint(qx[0].D, qy[0].D, NowMachineModlePos.u);

            return(NowPoint);
        }
Esempio n. 15
0
        public override XYUPoint GetObjPonit(XYUPoint objVisoionpoint, XYUPoint SanpMachinePoint)
        {
            XYUPoint objMachinePos = new XYUPoint();
            HTuple   hTuplex, hTupley;
            HTuple   qx, qy;

            HOperatorSet.AffineTransPoint2d(m_Hom2Ddtr, objVisoionpoint.x, objVisoionpoint.y, out qx, out qy);
            objMachinePos.x = qx[0].D;
            objMachinePos.y = qy[0].D;
            return(objMachinePos);
        }
Esempio n. 16
0
        /// <summary>
        /// 获得点的实际坐标
        /// </summary>
        /// <param name="markCenter"></param>
        /// <returns></returns>
        public PointH GetMarkAxis(PointH markCenter)
        {
            HTuple hv_Tx = null, hv_Ty = null;

            try
            {
                HOperatorSet.AffineTransPoint2d(hv_HomMat2D, markCenter.X, markCenter.Y, out hv_Tx, out hv_Ty);
                return(new PointH(hv_Tx[0].D, hv_Ty[0].D));
            }
            catch { return(new PointH()); }
        }
Esempio n. 17
0
        public override XYUPoint GetObjPonit(XYUPoint objVisoionpoint, XYUPoint SanpMachinePoint)
        {
            HTuple qx, qy;

            HOperatorSet.AffineTransPoint2d(m_Hom2Dutr, objVisoionpoint.x, objVisoionpoint.y, out qx, out qy);
            XYUPoint dstpoint = new XYUPoint();

            dstpoint.x = SanpMachinePoint.x - qx + AidPoint.x;
            dstpoint.y = SanpMachinePoint.y - qy + AidPoint.y;
            return(dstpoint);
        }
        public void RotateTrans(double x, double y, double r, out double tx, out double ty)
        {
            HHomMat2D mat2D = new HHomMat2D();

            mat2D = mat2D.HomMat2dRotate((HTuple)r, RotateCircle.Center.X, RotateCircle.Center.Y);
            HTuple qx, qy;

            HOperatorSet.AffineTransPoint2d(mat2D, x, y, out qx, out qy);
            tx = qx[0].D;
            ty = qy[0].D;
        }
Esempio n. 19
0
        /// <summary>
        /// 9点标定
        /// </summary>
        /// <param name="row">像素坐标</param>
        /// <param name="column">像素坐标</param>
        /// <param name="x">世界坐标,相对坐标置null</param>
        /// <param name="y">世界坐标,相对坐标置null</param>
        /// <returns></returns>
        public bool CalibNinePoint(double[] row, double[] column, double[] x = null, double[] y = null)
        {
            try
            {
                if ((row.Length < 3 || column.Length < 3) || (x == null && row.Length != 9))
                {
                    return(false);
                }

                IsRelative = false;

                if (x == null || y == null)
                {
                    IsRelative = true;

                    double[] px = new double[9];
                    double[] py = new double[9];
                    double[] wx = new double[9];
                    double[] wy = new double[9];

                    for (int i = 0; i < 9; i++)
                    {
                        px[i] = row[i] - row[4];
                        py[i] = column[i] - column[4];
                        wx[i] = (i % 3 - 1) * TranslationStep;
                        wy[i] = (i / 3 - 1) * TranslationStep;
                    }

                    row    = px;
                    column = py;
                    x      = wx;
                    y      = wy;
                }


                // 获取矩阵
                HOperatorSet.VectorToHomMat2d(row, column, x, y, out HomMat2D);

                // 获取最大误差
                HTuple qx, qy;
                HOperatorSet.AffineTransPoint2d(HomMat2D, row, column, out qx, out qy);
                double ex = qx.TupleSub(x).TupleAbs().TupleMax();
                double ey = qy.TupleSub(y).TupleAbs().TupleMax();
                HomMat2DError = ex > ey ? ex : ey;

                SaveConfig();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// 算出标定数据
        /// </summary>
        /// <param name="homMat2D"></param>
        /// <param name="pixel_row_y"></param>
        /// <param name="pixel_column_x"></param>
        /// <param name="world_row_y"></param>
        /// <param name="world_column_x"></param>
        /// <returns></returns>
        public bool Cal(HTuple homMat2D, ref HTuple pixel_row_y, ref HTuple pixel_column_x /*, out HTuple world_row_y, out HTuple world_column_x*/)
        {
            bool   ok = false;
            HTuple world_row_y, world_column_x;

            HOperatorSet.AffineTransPoint2d(homMat2D, pixel_column_x, pixel_row_y, out world_column_x, out world_row_y);
            // HOperatorSet.AffineTransPixel(homMat2D, pixel_row_y, pixel_row_y, out world_row_y, out world_column_x);
            pixel_column_x = world_column_x;
            pixel_row_y    = world_row_y;
            ok             = true;
            return(ok);
        }
Esempio n. 21
0
        /// <summary>
        /// 获取机器人U轴中心对准点
        /// </summary>
        /// <param name="snappos"></param>
        /// <param name="Hom2Ddtu"></param>
        /// <param name="Hom2Ddtr"></param>
        /// <param name="Point2dVisionCoor"></param>
        /// <returns></returns>
        public Point2d GetPosWhenUpCameraSnap(Point2d snappos, HTuple Hom2Ddtu, HTuple Hom2Ddtr, Point2d Point2dVisionCoor)
        {
            HTuple qx, qy;
            HTuple rqx, rqy;

            HOperatorSet.AffineTransPoint2d(Hom2Ddtu, Point2dVisionCoor.x, Point2dVisionCoor.y, out qx, out qy);
            HOperatorSet.AffineTransPoint2d(Hom2Ddtr, qx, qy, out rqx, out rqy);
            Point2d pos = new Point2d();

            pos.x = rqx + snappos.x - CalibPos.x;
            pos.y = rqy + snappos.y - CalibPos.y;
            return(pos);
        }
Esempio n. 22
0
        public ToolResult GetResult()
        {
            try
            {
                int             imageWidt, imageHeight;
                HMetrologyModel metrologyModel = new HMetrologyModel();
                HTuple          startRow, startCol, endRow, endCol;
                HHomMat2D       matd  = new HHomMat2D();
                HHomMat2D       matd3 = matd.HomMat2dRotate(info.Rectangle2Angle, 0.0, 0.0);
                HHomMat2D       matd4 = matd3.HomMat2dTranslate(info.Rectangle2Row, info.Rectangle2Col);
                HOperatorSet.AffineTransPoint2d(matd4, new HTuple(0.0), new HTuple(-info.Rectangle2Length1), out startRow, out startCol);
                HOperatorSet.AffineTransPoint2d(matd4, new HTuple(0.0), new HTuple(info.Rectangle2Length1), out endRow, out endCol);
                //创建找线工具
                Image.GetImageSize(out imageWidt, out imageHeight);
                int[]  value  = new int[] { Convert.ToInt32(startRow.D), Convert.ToInt32(startCol.D), Convert.ToInt32(endRow.D), Convert.ToInt32(endCol.D) };
                HTuple values = new HTuple(value);
                metrologyModel.CreateMetrologyModel();
                metrologyModel.SetMetrologyModelImageSize(imageWidt, imageHeight);
                int index = metrologyModel.AddMetrologyObjectGeneric("line", values, 20, 5, 1, 30, "min_score", 0.6);
                #region 设置参数
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_length1"), new HTuple(Convert.ToInt32(info.measure_length1)));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_length2"), new HTuple(Convert.ToInt32(info.measure_length2)));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_distance"), new HTuple(info.measure_distance));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("num_measures"), new HTuple(info.num_measures));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("num_instances"), new HTuple(info.num_instances));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_sigma"), new HTuple(info.measure_sigma));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_threshold"), new HTuple(info.measure_threshold));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_transition"), new HTuple(info.measure_transition.ToString()));
                #endregion

                HTuple   Row;
                HTuple   Col;
                HXLDCont modelXLD = metrologyModel.GetMetrologyObjectMeasures(index, "all", out Row, out Col);
                if (info.IsShowLineMeasureDetail)
                {
                    Window.SetColor("red");
                    modelXLD.DispXld(Window.Window);
                }

                return(ApplyMetrology(metrologyModel, index, info.ToolName));
            }
            catch (Exception e)
            {
                return(new ToolResult()
                {
                    ResultName = info.ToolName, Errormessage = e.ToString(), GetResultTime = DateTime.Now, IsSuccess = false
                });
            }
        }
Esempio n. 23
0
        public override XYUPoint GetDstPonit(XYUPoint dstVisoionpoint, XYUPoint SanpMachinePoint)
        {
            XYUPoint dstMachinePos = new XYUPoint();
            HTuple   hTuplex, hTupley;
            HTuple   qx, qy;

            HOperatorSet.AffineTransPoint2d(m_Hom2Dutd, dstVisoionpoint.x, dstVisoionpoint.y, out hTuplex, out hTupley);
            HOperatorSet.AffineTransPoint2d(m_Hom2Ddtr, hTuplex, hTupley, out qx, out qy);
            XYUPoint vec = new XYUPoint();

            vec.x = SanpMachinePoint.x - CalibPoint.x;
            vec.y = SanpMachinePoint.y - CalibPoint.y;

            dstMachinePos.x = qx[0].D + vec.x;
            dstMachinePos.y = qy[0].D + vec.y;
            return(dstMachinePos);
        }
Esempio n. 24
0
        /// <summary>
        /// 获取指定旋转中心旋转后的位置
        /// </summary>
        /// <param name="centerRow">旋转中心Row</param>
        /// <param name="centerColumn">旋转中心Column</param>
        /// <param name="row">当前位置Row</param>
        /// <param name="column">当前位置Column</param>
        /// <param name="startAngle">当前角度</param>
        /// <param name="endAngle">旋转后的角度</param>
        /// <param name="rotatedRow">旋转后的位置Row</param>
        /// <param name="rotatedColumn">旋转后的位置Column</param>
        public void GetRotatedPose(HTuple centerRow, HTuple centerColumn, HTuple row, HTuple column,
                                   HTuple startAngle, HTuple endAngle, out HTuple rotatedRow, out HTuple rotatedColumn)
        {
            try
            {
                HTuple homMat2DIdentity, homMat2DRotate;
                HTuple rad = endAngle.TupleRad() - startAngle.TupleRad();

                HOperatorSet.HomMat2dIdentity(out homMat2DIdentity);
                HOperatorSet.HomMat2dRotate(homMat2DIdentity, rad, centerRow, centerColumn, out homMat2DRotate);
                HOperatorSet.AffineTransPoint2d(homMat2DRotate, row, column, out rotatedRow, out rotatedColumn);
            }
            catch (Exception)
            {
                rotatedRow = rotatedColumn = null;
            }
        }
Esempio n. 25
0
        /// <summary>
        /// 获取对应Laser点和Pin的 现况下的位置
        /// </summary>
        /// <param name="OldVisoionModlePos">模板视觉坐标位置</param>
        /// <param name="NowVisionModlePos">现在匹配模板视觉坐标位置</param>
        /// <param name="OldSnapModlePos">模板拍照机械位置</param>
        /// <param name="OldPinMachinePos">开始设置的Pin机械位置</param>
        /// <param name=""></param>
        /// <returns></returns>

        public XYUPoint GetDispOrLaserPoint2(XYUPoint OldVisoionModlePos, XYUPoint NowVisionModlePos, XYUPoint OldSnapModlePos, XYUPoint OldPinMachinePos, XYUPoint NowSnapMchinePos)
        {
            HOperatorSet.VectorAngleToRigid(OldVisoionModlePos.x, OldVisoionModlePos.y, OldVisoionModlePos.u, NowVisionModlePos.x, NowVisionModlePos.y, NowVisionModlePos.u, out HTuple hom2d);

            HTuple   vx, vy;
            XYUPoint machineXY = new XYUPoint(OldSnapModlePos.x - OldPinMachinePos.x, OldSnapModlePos.y - OldPinMachinePos.y, 0);

            HOperatorSet.AffineTransPoint2d(m_Hom2Drtu, machineXY.x, machineXY.y, out vx, out vy);

            HTuple qvx, qvy;

            HOperatorSet.AffineTransPixel(hom2d, vx, vy, out qvx, out qvy);

            XYUPoint NowPinMachinePoint = GetDstPonit(new XYUPoint(qvx, qvy, 0), NowSnapMchinePos);


            return(NowPinMachinePoint);
        }
Esempio n. 26
0
        public static bool affineTransPoint(HTuple matrix, HTuple x, HTuple y, out HTuple xTrans, out HTuple yTrans)
        {
            xTrans = null;
            yTrans = null;

            try
            {
                HOperatorSet.AffineTransPoint2d(matrix, x, y, out xTrans, out yTrans);
                if (null != xTrans && 0 < xTrans.Length)
                {
                    return(true);
                }
            }
            catch (HalconException ex)
            {
                string msg = ex.GetErrorMessage();
            }
            return(false);
        }
Esempio n. 27
0
        string RunCalibDeviation(double[] Pix_X, double[] Pix_Y, out string Deviation)
        {
            Deviation = "";
            try
            {
                HTuple real_x = new HTuple();
                HTuple real_y = new HTuple();
                HTuple real_z = new HTuple();
                HTuple tx1    = 0;

                HOperatorSet.AffineTransPoint2d(HomMat2Dxy, Pix_X, Pix_Y, out real_x, out real_y);

                HTuple subx = AxisX - real_x;
                HTuple suby = AxisY - real_y;

                subx = subx.TupleAbs();
                suby = suby.TupleAbs();

                double max_x = subx.TupleMax();
                double max_y = suby.TupleMax();

                double min_x = subx.TupleMin();
                double min_y = suby.TupleMin();

                double Meanx = subx.TupleMean();
                double Meany = suby.TupleMean();

                max_x = Math.Round(max_x, 3);
                max_y = Math.Round(max_y, 3);
                min_x = Math.Round(min_x, 3);
                min_y = Math.Round(min_y, 3);
                Meanx = Math.Round(Meanx, 3);
                Meany = Math.Round(Meany, 3);

                Deviation = string.Format("最大误差x:{0};y: {1};\r\n最小误差x:{2};y: {3};\r\n平均误差x:{4};y: {5};", max_x.ToString(), max_y.ToString(), min_x.ToString(), min_y.ToString(), Meanx.ToString(), Meany.ToString());
                return("OK");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(ex.Message);
            }
        }
Esempio n. 28
0
        public void CreateDownRobotCoor(double[] dx, double[] dy, double[] rx, double[] ry)
        {
            if (rx.Length != ry.Length || dx.Length != dy.Length || rx.Length != dx.Length || rx.Length == 0)
            {
                return;
            }
            HTuple Hom2D;
            HTuple Hom2D1;

            HOperatorSet.VectorToHomMat2d(dx, dy, rx, ry, out Hom2D);
            m_Hom2Ddtr = Hom2D.Clone();
            HOperatorSet.VectorToHomMat2d(rx, ry, dx, dy, out Hom2D1);
            m_Hom2Drtd = Hom2D1.Clone();
            HTuple qx, qy;
            HTuple qx1, qy1;

            HOperatorSet.AffineTransPoint2d(m_Hom2Ddtr, dx[0], dy[0], out qx, out qy);
            HOperatorSet.AffineTransPoint2d(m_Hom2Drtd, qx, qy, out qx1, out qy1);
            return;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            HTuple calibratedata = VisionManager.Instance.Calibrate.CalibrateData;

            if (calibratedata != null)
            {
                HObject _image = m_Camera.SnapShot();
                m_ShapeModle.BackImage = _image;
                ModleFindResult result = m_ShapeModle.FindSimple();
                if (result != null)
                {
                    HOperatorSet.AffineTransPoint2d(calibratedata, result.Row, result.Column, out HTuple x, out HTuple y);
                    HOperatorSet.AffineTransPoint2d(calibratedata, 1024, 1536, out HTuple _x, out HTuple _y);
                    double ox = _x - x + offx;
                    double oy = _y - y + offy;
                    VisionManager.Instance.Calibrate.ToolOffsetX = ox;
                    VisionManager.Instance.Calibrate.ToolOffsetY = oy;
                    // Robot.RelativeMove(ox, oy);
                }
            }
        }
Esempio n. 30
0
        private bool calculate_part(
            HTuple hv_WindowHandle,
            HTuple hv_WindowWidth,
            HTuple hv_WindowHeight)
        {
            HTuple row1             = (HTuple)null;
            HTuple column1          = (HTuple)null;
            HTuple row2             = (HTuple)null;
            HTuple column2          = (HTuple)null;
            HTuple row              = (HTuple)null;
            HTuple column           = (HTuple)null;
            HTuple width            = (HTuple)null;
            HTuple height           = (HTuple)null;
            HTuple homMat2DIdentity = (HTuple)null;
            HTuple homMat2DScale    = (HTuple)null;
            HTuple qx   = (HTuple)null;
            HTuple qy   = (HTuple)null;
            bool   flag = true;

            HOperatorSet.GetPart(hv_WindowHandle, out row1, out column1, out row2, out column2);
            try
            {
                HTuple htuple1 = (column2 - column1 + 1) / (row2 - row1 + 1).TupleReal();
                HOperatorSet.GetWindowExtents(hv_WindowHandle, out row, out column, out width, out height);
                HTuple sx      = width / hv_WindowWidth.TupleReal();
                HTuple sy      = height / hv_WindowHeight.TupleReal();
                HTuple htuple2 = new HTuple().TupleConcat((row1 + row2) * 0.5).TupleConcat((column1 + column2) * 0.5);
                HOperatorSet.HomMat2dIdentity(out homMat2DIdentity);
                HOperatorSet.HomMat2dScale(homMat2DIdentity, sx, sy, htuple2.TupleSelect((HTuple)1), htuple2.TupleSelect((HTuple)0), out homMat2DScale);
                HOperatorSet.AffineTransPoint2d(homMat2DScale, column1.TupleConcat(column2), row1.TupleConcat(row2), out qx, out qy);
                HOperatorSet.SetPart(hv_WindowHandle, qy.TupleSelect((HTuple)0), qx.TupleSelect((HTuple)0), qy.TupleSelect((HTuple)1), qx.TupleSelect((HTuple)1));
            }
            catch (HalconException ex)
            {
                HOperatorSet.SetPart(hv_WindowHandle, row1, column1, row2, column2);
                flag = false;
            }
            return(flag);
        }