Hello Mat

 找回密码
 立即注册
查看: 414|回复: 0

圆上均匀取点拟合

[复制链接]

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2023-11-28 18:05:21 | 显示全部楼层 |阅读模式
圆上均匀取点拟合
  1. Col1 = Convert.ToInt32(OuterCol - OuterRadius);
  2.             Col2 = Convert.ToInt32(OuterCol + OuterRadius);
  3.             int ColStep = Convert.ToInt32((Col2 - Col1) / 10);        // 默认10个列坐标,圆上上下对称,就是20个点坐标
  4.             List<int> Cols = new List<int>();
  5.             List<int> Rows = new List<int>();
  6.             //Witiaicv.Witiai.OverPaintGray2(M_Image, M_RectRegionMargin, M_RectRegionMargin);
  7.             //for (int Coli = Col1 + ColStep; Coli < Col2 - ColStep; Coli = Coli + ColStep)
  8.             {
  9.                 int Coli = Col1 + 9 * ColStep;
  10.                 // 一列圆上有两个点(最外边的大圆)
  11.                 int Rowi1 = Convert.ToInt32(OuterRow - Math.Sqrt(OuterRadius * OuterRadius - (Coli - OuterCol) * (Coli - OuterCol)));
  12.                 int Rowi2 = Convert.ToInt32(OuterRow + Math.Sqrt(OuterRadius * OuterRadius - (Coli - OuterCol) * (Coli - OuterCol)));
  13.                 // 拟合直线,外接圆圆心和外圆环上一个点连成的直线,与内圆相交,求解其交点
  14.                 double k1 = (OuterRow - Rowi1) / (OuterCol - Coli + 0.00000001);  // 斜率1,2-3象限
  15.                 double k2 = (OuterRow - Rowi2) / (OuterCol - Coli + 0.00000001);  // 斜率2,1-4象限
  16.                 // 内圆相交点坐标:
  17.                 double xx = Math.Atan(k1) * 180 / 3.1415926;
  18.                 double yy = Math.Atan(k2) * 180 / 3.1415926;
  19.                 int innerRow1 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k1)));
  20.                 int innerCol1 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k1)));
  21.                 int innerRow2 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k2)));
  22.                 int innerCol2 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k2)));
  23.                 if (Math.Atan(k1) * 180 / 3.1415926 < 90 && Math.Atan(k1) * 180 / 3.1415926 > 0)
  24.                 {
  25.                     innerRow1 = Convert.ToInt32(OuterRow - OuterRadius2 * Math.Sin(Math.Atan(k1)));
  26.                     innerCol1 = Convert.ToInt32(OuterCol - OuterRadius2 * Math.Cos(Math.Atan(k1)));
  27.                 }
  28.                 else if (Math.Atan(k1) * 180 / 3.1415926 > 90)
  29.                 {
  30.                     innerRow1 = Convert.ToInt32(OuterRow - OuterRadius2 * Math.Sin(Math.Atan(k1)));
  31.                     innerCol1 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k1)));
  32.                 }
  33.                 else if (Math.Atan(k1) * 180 / 3.1415926 > -90 && Math.Atan(k1) * 180 / 3.1415926 < 0)
  34.                 {
  35.                     innerRow1 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k1)));
  36.                     innerCol1 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k1)));
  37.                 }
  38.                 else if (Math.Atan(k1) * 180 / 3.1415926 < -90)
  39.                 {
  40.                     innerRow1 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k1)));
  41.                     innerCol1 = Convert.ToInt32(OuterCol - OuterRadius2 * Math.Cos(Math.Atan(k1)));
  42.                 }
  43.                 //
  44.                 if (Math.Atan(k2) * 180 / 3.1415926 < -90)
  45.                 {
  46.                     innerRow2 = Convert.ToInt32(OuterRow - OuterRadius2 * Math.Sin(Math.Atan(k2)));
  47.                     innerCol2 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k2)));
  48.                 }
  49.                 else if (Math.Atan(k2) * 180 / 3.1415926 > -90 && Math.Atan(k2) * 180 / 3.1415926 < 0)
  50.                 {
  51.                     innerRow2 = Convert.ToInt32(OuterRow - OuterRadius2 * Math.Sin(Math.Atan(k2)));
  52.                     innerCol2 = Convert.ToInt32(OuterCol - OuterRadius2 * Math.Cos(Math.Atan(k2)));
  53.                 }
  54.                 else if (Math.Atan(k2) * 180 / 3.1415926 > 0 && Math.Atan(k2) * 180 / 3.1415926 < 90)
  55.                 {
  56.                     innerRow2 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k2)));
  57.                     innerCol2 = Convert.ToInt32(OuterCol + OuterRadius2 * Math.Cos(Math.Atan(k2)));
  58.                 }
  59.                 else if (Math.Atan(k2) * 180 / 3.1415926 > 90)
  60.                 {
  61.                     innerRow2 = Convert.ToInt32(OuterRow + OuterRadius2 * Math.Sin(Math.Atan(k2)));
  62.                     innerCol2 = Convert.ToInt32(OuterCol - OuterRadius2 * Math.Cos(Math.Atan(k2)));
  63.                 }

  64.                 // 绘制交叉点cross
  65.                 //Mat CrossRegion = new Mat();
  66.                 //DispCross(M_Image, innerRow1, innerCol1, 15, 45, out CrossRegion);
  67.                 //Witiaicv.Witiai.OverPaintGray2(M_Image, CrossRegion, CrossRegion);

  68.                 //DispCross(M_Image, innerRow2, innerCol2, 15, 45, out CrossRegion);
  69.                 //Witiaicv.Witiai.OverPaintGray2(M_Image, CrossRegion, CrossRegion);

  70.                 //DispCross(M_Image, Rowi1, Coli, 15, 45, out CrossRegion);
  71.                 //Witiaicv.Witiai.OverPaintGray2(M_Image, CrossRegion, CrossRegion);

  72.                 //DispCross(M_Image, Rowi2, Coli, 15, 45, out CrossRegion);
  73.                 //Witiaicv.Witiai.OverPaintGray2(M_Image, CrossRegion, CrossRegion);
复制代码




算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-4-28 12:51 , Processed in 0.217158 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表