这里头比较难的是找圆,找角点
其他,说白了,就是坐标系变换,
我们再现一下找角点的代码:
tempcorner[j] = glob_subcorner((int)(first[j].X - 4), (int)(first[j].Y - 4), 8, 8, w, tempImage3, ref 梯度和);
----------------------
first是我们图上的网格,实质和roi相似,其实就是旋转roi发展而来的;tempImage3是图像,w是图像宽度;tempcorner是存放找到的角点。
private PointF glob_subcorner(int left, int top, int w, int h, int picW, byte[] orgbyte, ref int tiduhe)//新版本有关亚像素梯度和202005151029
{
double D, A, B, E, F, G, H; A = B = D = E = F = G = H = 0;
double _D, _A, _B; _A = _B = _D = 0;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
{
//int xdaoshu = CA_orgImg[(top + i) * picW + left + j + 1] - CA_orgImg[(top + i) * picW + left + j];//无需考虑边界
//int ydaoshu = CA_orgImg[(i + top) * picW + j + left + picW] - CA_orgImg[(top + i) * picW + left + j];
int xdaoshu = orgbyte[(top + i) * picW + left + j + 1] - orgbyte[(top + i) * picW + left + j];//无需考虑边界
int ydaoshu = orgbyte[(i + top) * picW + j + left + picW] - orgbyte[(top + i) * picW + left + j];
double TiDuvalue = Math.Sqrt(xdaoshu * xdaoshu + ydaoshu * ydaoshu);
tiduhe += Math.Abs(xdaoshu) + Math.Abs(ydaoshu);
float MVX = (float)(TiDuvalue * Math.Cos(jiaoduAndxiangxian(xdaoshu, ydaoshu)));//梯度向量X
float MVY = (float)(TiDuvalue * Math.Sin(jiaoduAndxiangxian(xdaoshu, ydaoshu)));//梯度向量Y
_A += (MVX) * (MVX);
_B += (MVX) * (MVY);
_D += (MVY) * (MVY);
E += (MVX) * (MVX) * (left + j);//x
F += (MVX) * (MVY) * (top + i);//y
G += (MVX) * (MVY) * (left + j);//x
H += (MVY) * (MVY) * (top + i);//y
}
double result = _A * _D - _B * _B;
A = _D / (result * 1.0); B = -_B / (result * 1.0); D = _A / (result * 1.0);
double x = A * (E + F) + B * (G + H);
double y = B * (E + F) + D * (G + H);
return new PointF((float)(x), (float)(y));
}
这个是难点,好好消化。。。