public Affinity_Matrix(Affinity_Matrix Ini)
 {
     this.Stretch_X    = Ini.Stretch_X;
     this.Distortion_X = Ini.Distortion_X;
     this.Delta_X      = Ini.Delta_X;
     this.Stretch_Y    = Ini.Stretch_Y;
     this.Distortion_Y = Ini.Distortion_Y;
     this.Delta_Y      = Ini.Delta_Y;
 }
        /// <summary>
        /// abstract affinity parameter from array
        /// </summary>
        /// <param name="temp_array"></param>
        /// <returns></returns>
        public Affinity_Matrix Array_To_Affinity(double[] temp_array)
        {
            Affinity_Matrix Result = new Affinity_Matrix
            {
                //获取仿射变换参数
                Stretch_X    = Convert.ToDecimal(temp_array[0]),
                Distortion_X = Convert.ToDecimal(temp_array[1]),
                Delta_X      = Convert.ToDecimal(temp_array[2]),//x方向偏移
                Stretch_Y    = Convert.ToDecimal(temp_array[4]),
                Distortion_Y = Convert.ToDecimal(temp_array[3]),
                Delta_Y      = Convert.ToDecimal(temp_array[5])//y方向偏移
            };

            //返回结果
            return(Result);
        }
        /// <summary>
        /// 生成校准文件
        /// </summary>
        private void GenerateCorrectData()
        {
            if (string.IsNullOrEmpty(SysPara.SourceFilePath))//源数据文件目录为空
            {
                MessageBox.Show("源数据文件路径无效,请选择正确的源文件!!!");
                return;
            }
            if (!File.Exists(SysPara.SourceFilePath))
            {
                MessageBox.Show("源数据文件不存在!!!");
                return;
            }
            if (string.IsNullOrEmpty(SysPara.ResultFilePath))//结果数据文件为空
            {
                MessageBox.Show("结果数据文件路径无效,请选择正确的数据文件!!!");
                return;
            }
            //读取数据
            //建立变量
            List <Affinity_Matrix> Result               = new List <Affinity_Matrix>();
            List <Correct_Data>    OriginalDatas        = new List <Correct_Data>();
            Correct_Data           Temp_Correct_Data    = new Correct_Data();
            Affinity_Matrix        Temp_Affinity_Matrix = new Affinity_Matrix();
            //提取Csv数据
            DataTable Calibration_Data_Acquisition = OpenCSV(SysPara.SourceFilePath);
            Int16     i, j;
            decimal   Xo, Yo, Xm, Ym;

            //2.5mm步距进行数据提取和整合,使用INC指令
            for (i = 0; i < Calibration_Data_Acquisition.Rows.Count; i++)
            {
                //清空Temp_Correct_Data
                Temp_Correct_Data = new Correct_Data();
                if ((decimal.TryParse(Calibration_Data_Acquisition.Rows[i][0].ToString(), out Xo)) && (decimal.TryParse(Calibration_Data_Acquisition.Rows[i][1].ToString(), out Yo)) && (decimal.TryParse(Calibration_Data_Acquisition.Rows[i][2].ToString(), out Xm)) && (decimal.TryParse(Calibration_Data_Acquisition.Rows[i][3].ToString(), out Ym)))
                {
                    //数据保存
                    Temp_Correct_Data.Xo = Xo;                        //理论X坐标
                    Temp_Correct_Data.Yo = Yo;                        //理论Y坐标
                    Temp_Correct_Data.Xm = Xm - SysPara.Cal_DeviateX; //平台X坐标
                    Temp_Correct_Data.Ym = Ym - SysPara.Cal_DeviateY; //平台Y坐标
                    //添加进入List
                    OriginalDatas.Add(Temp_Correct_Data);
                }
            }
            //定义仿射变换数组
            Mat mat = new Mat(new Size(3, 2), Emgu.CV.CvEnum.DepthType.Cv32F, 1); //2行 3列 的矩阵

            //原坐标
            double[] temp_array;
            //数据处理
            if (SysPara.XCalibration * SysPara.YCalibration == OriginalDatas.Count)//矫正和差异数据完整
            {
                //定义点位数组
                PointF[] srcTri = new PointF[SysPara.CorrectMethod]; //标准数据
                PointF[] dstTri = new PointF[SysPara.CorrectMethod]; //差异化数据
                //数据处理
                for (i = 0; i < SysPara.YCalibration - 1; i++)
                {
                    for (j = 0; j < SysPara.XCalibration - 1; j++)
                    {
                        switch (SysPara.CorrectMethod)
                        {
                        case 3:
                            //标准数据  定位坐标
                            srcTri[0] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration].Xo), (float)(OriginalDatas[j + i * SysPara.YCalibration].Yo));
                            srcTri[1] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration].Xo), (float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration].Yo));
                            srcTri[2] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration + 1].Xo), (float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration + 1].Yo));    //计算仿射变换矩阵

                            //仿射数据  测量坐标
                            dstTri[0] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration].Xm), (float)(OriginalDatas[j + i * SysPara.YCalibration].Ym));
                            dstTri[1] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration].Xm), (float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration].Ym));
                            dstTri[2] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration + 1].Xm), (float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration + 1].Ym));

                            break;

                        case 4:
                            //标准数据  定位坐标
                            srcTri[0] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration].Xo), (float)(OriginalDatas[j + i * SysPara.YCalibration].Yo));
                            srcTri[1] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration].Xo), (float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration].Yo));
                            srcTri[2] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration + 1].Xo), (float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration + 1].Yo)); //计算仿射变换矩阵
                            srcTri[3] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration + 1].Xo), (float)(OriginalDatas[j + i * SysPara.YCalibration + 1].Yo));                                               //计算仿射变换矩阵

                            //仿射数据  测量坐标
                            dstTri[0] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration].Xm), (float)(OriginalDatas[j + i * SysPara.YCalibration].Ym));
                            dstTri[1] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration].Xm), (float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration].Ym));
                            dstTri[2] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration + 1].Xm), (float)(OriginalDatas[j + i * SysPara.YCalibration + SysPara.XCalibration + 1].Ym));
                            dstTri[3] = new PointF((float)(OriginalDatas[j + i * SysPara.YCalibration + 1].Xm), (float)(OriginalDatas[j + i * SysPara.YCalibration + 1].Ym));

                            break;

                        default:
                            break;
                        }

                        //计算仿射变换矩阵
                        if (SysPara.CorrectFunction == 0)
                        {
                            mat = CvInvoke.GetAffineTransform(srcTri, dstTri);
                        }
                        else if (SysPara.CorrectFunction == 1)
                        {
                            mat = CvInvoke.EstimateRigidTransform(srcTri, dstTri, true);
                        }
                        //提取矩阵数据
                        temp_array = mat.GetDoubleArray();
                        //获取仿射变换参数
                        Temp_Affinity_Matrix = Array_To_Affinity(temp_array);
                        //追加进入仿射变换List
                        Result.Add(new Affinity_Matrix(Temp_Affinity_Matrix));
                        //清除变量
                        Temp_Affinity_Matrix = new Affinity_Matrix();
                    }
                }
                //保存为文件
                Serialize_Affinity_Matrix(Result, SysPara.ResultFilePath);
            }
        }