之前角点检测的算法中,一个是cornerHarris计算角点,但是这种角点检测算法容易出现聚簇现象以及角点信息有丢失和位置偏移现象,所以后面又提出一种名为goodFeatureToTrack的角点检测算法,opencv的feature2D接口集成了这种算法,名称为GFTTDetector。
函数接口
cv::Ptr<cv::GFTTDetector> create( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1,
int blockSize=3, bool useHarrisDetector=false, double k=0.04 );
参数 | 说明 |
---|---|
maxCorners | 最大角点数目 |
qualityLevel | 角点可以接受的最小特征值,一般0.1或者0.01,不超过1 |
minDistance | 角点之间的最小距离 |
blockSize | 倒数自相关矩阵的邻域范围 |
useHarrisDetector | 是否使用角点检测 |
khessian | 自相关矩阵的相对权重系数,一般为0.04 |
代码实例
int main(int argc,char* argv[])
{
Mat srcImage = imread("F:\\opencv\\OpenCVImage\\FeatureDetectSrc1.jpg");
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;
}