Fast角点检测算法
2021-07-30
1.角点定义
角点是一种局部特征,具有旋转不变性和不随光照条件变化而变化的特点,一般将图像中曲率足够高或者曲率变化明显的点作为角点。检测得到的角点特征通常用于图像匹配、目标跟踪、运动估计等方面。
2.Fast检测角点
1)基本思想
E.Rosten和T.Drummond两位大佬在06年一篇文章中提出了FAST特征算法,基本思想十分简单:以某个像素点为圆心,某半径的圆周上其他像素点与圆心像素点特性差异达到某种标准时即认为该点就是角点。
2)数学模型
经过测试发现,选取的圆形半径为3时可以兼顾检测结果和效率。如上图所示,点p与半径为3的圆周上的16个像素点比较其灰度差,若灰度差绝对值大于某阈值的点数超过设定数目(一般可以取9/10/11/12),则认为该点是角点。
使用小技巧加速该算法,这里取设定数目为12。
(1)判断点1和点9灰度值与点p差值绝对值是否都大于阈值,如果是则继续;否则pass该点
(2)判断点1、点5、点9、点13四点与点p灰度值差值大于阈值的数目是否大于2,如果是则继续;否则pass该点
(3)判断圆周上16点与点p灰度值差值大于阈值的数目是否不小于12,如果是则认为该点是候选点;否则pass该点
对图像中所有像素点进行上述操作后,得到候选点点集。通常使用非极大值抑制过滤局部非极大值点,在这之前需要先计算各候选点的score,score就定义为16个点与中心点灰度值差值的绝对值总和
3.opencv实现
个人使用vs2012+opencv2.4.13作为开发环境,具体实现如下
#include代码运行结果如下,比较第2/3张图可以发现,非极大值抑制具有过滤掉局部区域中非极大值角点的作用。 4.算法小结 该算法思想简单,运算量很小,适合实时检测方面的应用。不过也有缺点,主要表现为对于边缘点与噪点区分能力不强,当然后面也有很多人在此基础上加以改进提高算法的稳定性。#include #include #include #include using namespace std; using namespace cv; int getSum(uchar *p, int length) { int sum = 0; for(int i=0;i points; int rows, cols, threshold; rows = image.rows; cols = image.cols; threshold = 50; /* 2.检测Fast特征点 */ for(int x = 3; x < rows - 3; x++) { for(int y = 3; y < cols - 3; y++) { uchar delta[16] = {0}; uchar diff[16] = {0}; delta[0] = (diff[0] = abs(image.at (x,y) - image.at (x, y-3))) > threshold; delta[8] = (diff[8] = abs(image.at (x,y) - image.at (x, y+3))) > threshold; if(getSum(delta, 16) == 0) continue; else { delta[12] = (diff[12] = abs(image.at (x,y) - image.at (x-3, y))) > threshold; delta[4] = (diff[4] = abs(image.at (x,y) - image.at (x+3, y))) > threshold; if(getSum(delta, 16) < 3) continue; else { delta[1] = (diff[1] = abs(image.at (x,y) - image.at (x+1, y-3))) > threshold; delta[2] = (diff[2] = abs(image.at (x,y) - image.at (x+2, y-2))) > threshold; delta[3] = (diff[3] = abs(image.at (x,y) - image.at (x+3, y-1))) > threshold; delta[5] = (diff[5] = abs(image.at (x,y) - image.at (x+3, y+1))) > threshold; delta[6] = (diff[6] = abs(image.at (x,y) - image.at (x+2, y+2))) > threshold; delta[7] = (diff[7] = abs(image.at (x,y) - image.at (x+1, y+3))) > threshold; delta[9] = (diff[9] = abs(image.at (x,y) - image.at (x-1, y+3))) > threshold; delta[10] = (diff[10] = abs(image.at (x,y) - image.at (x-2, y+2))) > threshold; delta[11] = (diff[11] = abs(image.at (x,y) - image.at (x-3, y+1))) > threshold; delta[13] = (diff[13] = abs(image.at (x,y) - image.at (x-3, y-1))) > threshold; delta[14] = (diff[14] = abs(image.at (x,y) - image.at (x-2, y-2))) > threshold; delta[15] = (diff[15] = abs(image.at (x,y) - image.at (x-1, y-3))) > threshold; if(getSum(delta, 16) >= 12) { points.push_back(Point(y,x)); fastScore.at (x,y) = getSum(diff, 16); fastImg.at (x,y) = 255; } } } } } vector ::const_iterator itp = points.begin(); while(itp != points.end()) { circle(image, *itp, 3, Scalar(255), 1); ++itp; } //未进行非极大值抑制之前的特征点检测结果 namedWindow("Fast Image"); imshow("Fast Image", image); /* 3.对特征点候选点进行非极大值抑制 */ image = imread("../church01.jpg", 0); Mat dilated(fastScore.size(), CV_32F, Scalar(0)); Mat localMax; Mat element(7, 7, CV_8U, Scalar(1)); dilate(fastScore, dilated, element); compare(fastScore, dilated, localMax, CMP_EQ); bitwise_and(fastImg, localMax, fastImg); for(int x = 0;x < fastImg.cols; x++) { for(int y = 0; y < fastImg.rows; y++) { if(fastImg.at (y,x)) { circle(image, Point(x,y), 3, Scalar(255), 1); } } } //进行非极大值抑制之后的特征点检测结果 namedWindow("Fast Image2"); imshow("Fast Image2", image); waitKey(); return 0; }