shi_tomasi特征点,GFTTDetector
哈里斯(Harris)角点会出现聚簇现象(cornerHarris函数),为避免此现象,提出shi_tomasi角点检测算法goodFeatureToTrack,GFTTDetector实现了此算法。
【函数】
Ptr<GFTTDetector> create( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1,int blockSize=3, bool useHarrisDetector=false, double k=0.04 );
Ptr<GFTTDetector> create( int maxCorners, double qualityLevel, double minDistance,int blockSize, int gradiantSize, bool useHarrisDetector=false, double k=0.04 );
【参数说明】
maxCorners——最大角点数目
qualityLevel——角点可以接受的最小特征值,一般0.1或者0.01,不超过1
minDistance——角点之间的最小距离
blockSize——倒数自相关矩阵的邻域范围
useHarrisDetector——是否使用角点检测
khessian——自相关矩阵的相对权重系数,一般为0.04
【案例】
#include <opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace cv; int main() { Mat srcImage = imread("D:/sunflower.png"); Mat srcGrayImage; if (srcImage.channels() == 3) { cvtColor(srcImage,srcGrayImage,CV_RGB2GRAY); } else { srcImage.copyTo(srcGrayImage); } vector<KeyPoint>detectKeyPoint; Mat keyPointImage1,keyPointImage2; Ptr<GFTTDetector> gftt = GFTTDetector::create(); gftt->detect(srcGrayImage,detectKeyPoint); drawKeypoints(srcImage,detectKeyPoint,keyPointImage1,Scalar(0,0,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS); drawKeypoints(srcImage,detectKeyPoint,keyPointImage2,Scalar(0,0,255),DrawMatchesFlags::DEFAULT); imshow("src image",srcImage); imshow("keyPoint image1",keyPointImage1); imshow("keyPoint image2",keyPointImage2); waitKey(0); return 0; }