一、Harris角点检测
Harris角点检测通过判断点在水平和竖直方向上的变化程度来判断是否为角点,使用cornerHarris函数,处理后再用阈值来判断是否为角点。
int main()
{
RNG rng(12345);
Mat a = imread("1RT05508-0.jpg");
imshow("原图", a);
cvtColor(a, a, CV_RGB2GRAY);
Mat b = Mat::zeros(a.size(), CV_32FC1);
cornerHarris(a, b, 2, 3, 0.04); //进行检测
Mat c, d;
normalize(b, c, 0, 255, NORM_MINMAX, CV_32FC1); //标准化图像
convertScaleAbs(c, d);
for (int i = 0; i < c.cols; i++) //在认为是角点的地方画圆
{
for (int j = 0; j < c.rows; j++)
{
if ((int)c.at<float>(j, i)>150)
circle(d, Point(i, j), 3, Scalar(255, 255, 255), 2);
}
}
imshow("效果图", d);
cvWaitKey(10000);
}
二、Shi-Tomasi角点检测
Shi-Tomasi角点检测是基于Harris看角点检测的优化版。
使用的函数为goodFeaturesToTrack。
int main()
{
RNG rng(12345);
Mat a = imread("1RT05508-0.jpg");
imshow("原图", a);
cvtColor(a, a, CV_RGB2GRAY);
vector<Point2f> corners;
goodFeaturesToTrack(a,corners,23,0.01,10); //检测
cvtColor(a, a, CV_GRAY2BGR);
for (int i = 0; i < corners.size(); i++) //画点
{
circle(a, Point(corners[i].x, corners[i].y), 4, Scalar(255, 0, 255),2);
}
imshow("效果图", a);
cvWaitKey(10000);
}
三、FAST角点检测
FAST角点检测是通过将某一点与周边的点相比较来确定是否为角点,是一种公认的快速检测角点的算法
int main()
{
RNG rng(12345);
Mat a = imread("1RT05508-0.jpg");
imshow("原图", a);
cvtColor(a, a, CV_RGB2GRAY);
vector<KeyPoint> keyPoints;
FAST(a, keyPoints, 30);
cvtColor(a, a, CV_GRAY2RGB);
//drawKeypoints(a, keyPoints, a, Scalar(255,255,255), DrawMatchesFlags::DRAW_OVER_OUTIMG);
for each (auto point in keyPoints) //上面注释掉的代码也可以绘图,只是不能定义粗细
{
circle(a, Point(point.pt.x, point.pt.y), 4, Scalar(255, 0, 255), 2);
}
imshow("效果图", a);
cvWaitKey(10000);
}