Harris corner 角點偵測源代碼 source code
bool harris(const vector<float>& p,
size_t w, size_t y, size_t x)
{
// 閥值
constexpr float r = 10;
constexpr float thre = ((r + 1)*(r + 1)) / r;
// 二維讀取
auto at2d = [&](int y, int x) {return p[y*w + x];};
// 公式
float Dxx = 2 * at2d(y, x) - at2d(y, x-1) - at2d(y, x+1);
float Dyy = 2 * at2d(y, x) - at2d(y-1, x) - at2d(y+1, x);
float Dxy = at2d(y+1, x+1) + at2d(y-1, x-1)
- at2d(y-1, x+1) - at2d(y+1, x-1);
Dxy /= 4;
float Tr = Dxx + Dyy;
float Det = Dxx * Dyy - Dxy*Dxy;
// 判斷閥值
if ((Tr*Tr / Det) < thre) {
return 1;
} return 0;
}
沒有針對邊緣防呆,記得避開邊緣的點
測試圖
沒有留言:
張貼留言