|
圆上均匀取点拟合
- Col1 = Convert.ToInt32(OuterCol - OuterRadius);
- Col2 = Convert.ToInt32(OuterCol + OuterRadius);
- int ColStep = Convert.ToInt32((Col2 - Col1) / 10); // 默认10个列坐标,圆上上下对称,就是20个点坐标
- List<int> Cols = new List<int>();
- List<int> Rows = new List<int>();
- //Witiaicv.Witiai.OverPaintGray2(M_Image, M_RectRegionMargin, M_RectRegionMargin);
- //for (int Coli = Col1 + ColStep; Coli < Col2 - ColStep; Coli = Coli + ColStep)
- {
- int Coli = Col1 + 9 * ColStep;
- // 一列圆上有两个点(最外边的大圆)
- int Rowi1 = Convert.ToInt32(OuterRow - Math.Sqrt(OuterRadius * OuterRadius - (Coli - OuterCol) * (Coli - OuterCol)));
- int Rowi2 = Convert.ToInt32(OuterRow + Math.Sqrt(OuterRadius * OuterRadius - (Coli - OuterCol) * (Coli - OuterCol)));
- // 拟合直线,外接圆圆心和外圆环上一个点连成的直线,与内圆相交,求解其交点
- double k1 = (OuterRow - Rowi1) / (OuterCol - Coli + 0.00000001); // 斜率1,2-3象限
- double k2 = (OuterRow - Rowi2) / (OuterCol - Coli + 0.00000001); // 斜率2,1-4象限
- // 内圆相交点坐标:
- double xx = Math.Atan(k1) * 180 / 3.1415926;
- double yy = Math.Atan(k2) * 180 / 3.1415926;
- int innerRow1 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k1)));
- int innerCol1 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k1)));
- int innerRow2 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k2)));
- int innerCol2 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k2)));
- if (Math.Atan(k1) * 180 / 3.1415926 < 90 && Math.Atan(k1) * 180 / 3.1415926 > 0)
- {
- innerRow1 = Convert.ToInt32(OuterRow - OuterRadius2 * Math.Sin(Math.Atan(k1)));
- innerCol1 = Convert.ToInt32(OuterCol - OuterRadius2 * Math.Cos(Math.Atan(k1)));
- }
- else if (Math.Atan(k1) * 180 / 3.1415926 > 90)
- {
- innerRow1 = Convert.ToInt32(OuterRow - OuterRadius2 * Math.Sin(Math.Atan(k1)));
- innerCol1 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k1)));
- }
- else if (Math.Atan(k1) * 180 / 3.1415926 > -90 && Math.Atan(k1) * 180 / 3.1415926 < 0)
- {
- innerRow1 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k1)));
- innerCol1 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k1)));
- }
- else if (Math.Atan(k1) * 180 / 3.1415926 < -90)
- {
- innerRow1 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k1)));
- innerCol1 = Convert.ToInt32(OuterCol - OuterRadius2 * Math.Cos(Math.Atan(k1)));
- }
- //
- if (Math.Atan(k2) * 180 / 3.1415926 < -90)
- {
- innerRow2 = Convert.ToInt32(OuterRow - OuterRadius2 * Math.Sin(Math.Atan(k2)));
- innerCol2 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k2)));
- }
- else if (Math.Atan(k2) * 180 / 3.1415926 > -90 && Math.Atan(k2) * 180 / 3.1415926 < 0)
- {
- innerRow2 = Convert.ToInt32(OuterRow - OuterRadius2 * Math.Sin(Math.Atan(k2)));
- innerCol2 = Convert.ToInt32(OuterCol - OuterRadius2 * Math.Cos(Math.Atan(k2)));
- }
- else if (Math.Atan(k2) * 180 / 3.1415926 > 0 && Math.Atan(k2) * 180 / 3.1415926 < 90)
- {
- innerRow2 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k2)));
- innerCol2 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k2)));
- }
- else if (Math.Atan(k2) * 180 / 3.1415926 > 90)
- {
- innerRow2 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k2)));
- innerCol2 = Convert.ToInt32(OuterCol - OuterRadius2 * Math.Cos(Math.Atan(k2)));
- }
- // 绘制交叉点cross
- //Mat CrossRegion = new Mat();
- //DispCross(M_Image, innerRow1, innerCol1, 15, 45, out CrossRegion);
- //Witiaicv.Witiai.OverPaintGray2(M_Image, CrossRegion, CrossRegion);
- //DispCross(M_Image, innerRow2, innerCol2, 15, 45, out CrossRegion);
- //Witiaicv.Witiai.OverPaintGray2(M_Image, CrossRegion, CrossRegion);
- //DispCross(M_Image, Rowi1, Coli, 15, 45, out CrossRegion);
- //Witiaicv.Witiai.OverPaintGray2(M_Image, CrossRegion, CrossRegion);
- //DispCross(M_Image, Rowi2, Coli, 15, 45, out CrossRegion);
- //Witiaicv.Witiai.OverPaintGray2(M_Image, CrossRegion, CrossRegion);
复制代码
|
|