高考的那倒計時100天起始,父親說,把高考的大目標,分成小目標,安排在這100天裏,逐步完成。
目標,列提綱,再細化。(高考)
要識別的目標,粗匹配,細匹配。(機器視覺識別)
門,綱,目,科,屬,種。(生物分類)
原來都是如此,但請不要忘記,把目標實現,限定在時光中。
我們前面的博客已經完成了標定目標確定和列提綱,現在要做的是再細化。
本節重點,harris角點(確定任意叉(×)整數角點A集合,在A集合中尋找正交(+)亞像素角點)。
需要說的是,harris角點,我們需要的是亞像素角點,第一步求的是任意×的整數角點,第二步,是在整數角點基礎上求正交+亞像素角點。圖中按鈕“全部harris”代碼實現:
1,高斯平滑
for (int j = 1; j < (h - 1); j++)
{
for (int i = 1; i < (w - 1); i++)
{
int n0 = (j * w + i);
tyimg[n0] = (byte)((tongyongimg33gaos[n0 - w - 1] + 2 * tongyongimg33gaos[n0 - w] + tongyongimg33gaos[n0 - w + 1] +
2 * tongyongimg33gaos[n0 - 1] + 4 * tongyongimg33gaos[n0] + 2 * tongyongimg33gaos[n0 + 1] +
tongyongimg33gaos[n0 + w - 1] + 2 * tongyongimg33gaos[n0 + w] + tongyongimg33gaos[n0 + w + 1]) / 16);
}
}
2,任意×的整數角點
for (int i = 1; i < (h - 1); i++)
{
for (int j = 1; j < (w - 1); j++)
{
int n0 = (i * w + j);
m_P2[i, j] = tyimg[n0 + 1] + tyimg[n0 - 1] - 2 * tyimg[n0];//
m_Q2[i, j] = tyimg[n0 + w] + tyimg[n0 - w] - 2 * tyimg[n0];//
m_Theta2[i, j] = tyimg[n0] - tyimg[n0 + 1] - tyimg[n0 + w] + tyimg[n0 + w + 1];//
int temp = m_P2[i, j] * m_Q2[i, j];//*
int temp2 = m_P2[i, j] + m_Q2[i, j];//拉普拉斯=+
int 特徵 = (temp - m_Theta2[i, j] * m_Theta2[i, j]);//*-*
int 跡 = temp2 * temp2;
//m_k=0.04
m_Harris[i, j] = (int)(特徵 - m_k * 跡);
if (Math.Abs(m_Harris[i, j]) > thres && i > 3 && j > 3 && i < h - 3 && j < w - 3)//已經更改201702121652
{//thres=200
tyimgshuzu[i * w + j] = 0;
}
else
{
tyimgshuzu[i * w + j] = 255;
}
}
}
3, 聚集的角點分組,亞像素角點必在其中
List<List<Point>> fenzu = new List<List<Point>>();
染色算法(ref fenzu, ref tyimgshuzu, W, H);//此算法參考找斑
4,找出分組中,harris響應最大的,亞像素必在其附近
List<Point> fenzuMaxPt = new List<Point>();
List<int> fenzumaxVal = new List<int>();
for (int i = 0; i < fenzu.Count; i++)
{
if (fenzu[i].Count < 3) continue;
List<Point> temp2 = new List<Point>();
temp2.AddRange(fenzu[i]);
int max = Math.Abs(m_Harris[temp2[0].Y, temp2[0].X]);
int maxI = 0, maxJ = 0;
for (int ii = 0; ii < temp2.Count; ii++)
{
int tempAbsVal = Math.Abs(m_Harris[temp2[ii].Y, temp2[ii].X]);
if (tempAbsVal >= max)
{
max = tempAbsVal;
maxI = temp2[ii].X;
maxJ = temp2[ii].Y;
}
}
fenzuMaxPt.Add(new Point(maxI, maxJ));//響應的最大值點
fenzumaxVal.Add(max);//響應的最大值
}
5,在分組最大響應角點處找亞像素角點
for (int m = 0; m < fenzuMaxPt.Count; m++)
{
int x = fenzuMaxPt[m].X;
int y = fenzuMaxPt[m].Y;
int[] xNum = new int[] { 1, 1, 0, -1, -1, -1, 0, 1 };
int[] yNum = new int[] { 0, -1, -1, -1, 0, 1, 1, 1 };
double 點積和 = 0;//初始化爲0不妥,爲什麼?202005101007
//點積和入門,最大harris響應角點處其八個鄰域內的點積和
for (int k = 0; k < 8; k++)
{
int xx = x + xNum[k];
int yy = y + yNum[k];
int x導數 = tyimg[(yy) * W + xx + 1] - tyimg[(yy) * W + xx];
int y導數 = tyimg[(yy) * W + xx + W] - tyimg[(yy) * W + xx];
int 梯度值 = Math.Abs(xdaoshu) + Math.Abs(ydaoshu);
float 梯度角 = (float)(jiaoduAndxiangxian(xdaoshu, ydaoshu) * 57.3);
float 向量X = (float)(梯度值 * Math.Cos(jiaoduAndxiangxian(x導數, y導數)));
float 向量Y = (float)(梯度值 * Math.Sin(jiaoduAndxiangxian(x導數, y導數)));
float 點積 = 向量X * (x - xx) + 向量Y * (y - yy);
點積和 += 點積;
}
//最大harris響應角點處,8*8矩形窗口中找亞像素角點(正交角點)
PointF tempcorner = tysubcorners1per8(fenzuMaxPt[m].X - 4, fenzuMaxPt[m].Y - 4, 8, 8, W, tyimg);
tyCA_subcornersflitCali.Add(tempcorner);
}
結果如下:
注:jiaoduAndxiangxian函數在線圖像工具設計中出現過;
tysubcorners1per8函數在亞像素角點最小二乘法實現中已經出現。