示例#1
0
        /// <summary>
        /// 计算基于特征点的标定转换矩阵
        /// </summary>
        public void CalculateCaliPointHomMatrix()
        {
            if (CaliSolution != null &&
                CaliSolution.CalibrationPointPairBList.Count > 3)
            {
                HalconDotNet.HTuple row, col, axis1, axis2;
                HalconDotNet.HTuple sx, sy, phi, theta, tx, ty;
                HalconDotNet.HTuple tmp1, tmp2, pixelError, physicalError;
                CaliSolution.IsEffective = false;

                try
                {
                    row   = new HalconDotNet.HTuple(CaliSolution.CalibrationPointPairBList[0].PC.Row);
                    col   = new HalconDotNet.HTuple(CaliSolution.CalibrationPointPairBList[0].PC.Col);
                    axis1 = new HalconDotNet.HTuple(CaliSolution.CalibrationPointPairBList[0].WC.X);
                    axis2 = new HalconDotNet.HTuple(CaliSolution.CalibrationPointPairBList[0].WC.Y);

                    int count = CaliSolution.CalibrationPointPairBList.Count;
                    for (int i = 1; i < count; i++)
                    {
                        row = row.TupleConcat(new HalconDotNet.HTuple(CaliSolution.CalibrationPointPairBList[i].PC.Row));
                        col = col.TupleConcat(new HalconDotNet.HTuple(CaliSolution.CalibrationPointPairBList[i].PC.Col));

                        axis1 = axis1.TupleConcat(new HalconDotNet.HTuple(CaliSolution.CalibrationPointPairBList[i].WC.X));
                        axis2 = axis2.TupleConcat(new HalconDotNet.HTuple(CaliSolution.CalibrationPointPairBList[i].WC.Y));
                    }

                    HalconDotNet.HOperatorSet.VectorToHomMat2d(row, col, axis1, axis2, out _p2whomMat2D);
                    HalconDotNet.HOperatorSet.VectorToHomMat2d(axis1, axis2, row, col, out _w2phomMat2D);

                    //1-根据转换关系,物理坐标系点转换为像素点
                    HalconDotNet.HOperatorSet.AffineTransPoint2d(_w2phomMat2D, axis1, axis2, out tmp1, out tmp2);
                    pixelError = ((row - tmp1) * (row - tmp1) + (col - tmp2) * (col - tmp2)).TupleMean();

                    //2-根据转换关系,像素坐标系点转换为物理点
                    HalconDotNet.HOperatorSet.AffineTransPoint2d(_p2whomMat2D, row, col, out tmp1, out tmp2);
                    physicalError = ((axis1 - tmp1) * (axis1 - tmp1) + (axis2 - tmp2) * (axis2 - tmp2)).TupleMean();

                    HalconDotNet.HOperatorSet.HomMat2dToAffinePar(_p2whomMat2D, out sx, out sy, out phi, out theta, out tx, out ty);

                    CaliSolution.ResultOfCaliPoint = new Communal.ResultOfCalibrationPoint();
                    CaliSolution.ResultOfCaliPoint.PC2WCHomMat2D            = _p2whomMat2D.ToDArr();
                    CaliSolution.ResultOfCaliPoint.WC2PCHomMat2D            = _w2phomMat2D.ToDArr();
                    CaliSolution.ResultOfCaliPoint.Sx                       = sx.D;
                    CaliSolution.ResultOfCaliPoint.Sy                       = sy.D;
                    CaliSolution.ResultOfCaliPoint.Phi                      = phi.D;
                    CaliSolution.ResultOfCaliPoint.Theta                    = theta.D;
                    CaliSolution.ResultOfCaliPoint.Tx                       = tx.D;
                    CaliSolution.ResultOfCaliPoint.Ty                       = ty.D;
                    CaliSolution.ResultOfCaliPoint.CalibrationPhysicalError = physicalError;
                    CaliSolution.ResultOfCaliPoint.CalibrationPixelError    = pixelError;
                    CaliSolution.IsEffective = true;
                }
                catch { }
            }
        }
示例#2
0
 public override HalconDotNet.HTuple GetModeData()
 {
     HalconDotNet.HTuple mdData = new HalconDotNet.HTuple(new double[] { _locateRow, _locateCol });
     mdData.TupleConcat(new HalconDotNet.HTuple(_sizeRows)).TupleConcat(new HalconDotNet.HTuple(_sizeCols));
     return(mdData);
 }