【OpenCV】Harris角点检测

Harris角点特征检测的算法原理请参考:【目标检测】Harris角点特征学习记录。

#include 
#include 
#include 

#include 
#include 
#include 

Mat image;
image = imread("3.jpg");
Mat resizeImg;
resize(image, resizeImg, Size(), 0.5, 0.5, INTER_LINEAR);
Mat grayImg;
cvtColor(resizeImg, grayImg, CV_BGR2GRAY);

Mat dstImg = Mat::zeros(grayImg.size(), CV_32FC1);
cornerHarris(grayImg, dstImg, 3, 3, 0.04);
Mat norImg;
normalize(dstImg, norImg, 0, 255, CV_MINMAX, CV_32FC1, Mat());
Mat scaleImg;
convertScaleAbs(norImg, scaleImg);

int thresh = 100;
for (int i = 0; i < resizeImg.rows; i++)
{
	uchar *data = scaleImg.ptr(i);
	for (int j = 0; j < resizeImg.cols; j++)
	{
		if ((int)*data++ > thresh)
		{
			circle(resizeImg, Point(j, i), 5, Scalar(0, 0, 255), 1);
			circle(scaleImg, Point(j, i), 5, Scalar(0, 0, 255), 1);
		}
	}
}
imshow("原图", resizeImg);
imshow("角点", scaleImg);
waitKey(0);

输出结果:

【OpenCV】Harris角点检测_第1张图片

你可能感兴趣的:(计算机视觉,opencv)