1、goodFeaturetoTrack函数
函数作用:
确定图像的强角点
2、goodFeaturetoTrack函数的调用形式
C++: void goodFeaturesToTrack(InputArray image, OutputArray corners, int maxCorners, double qualityLevel, double minDistance, InputArray mask=noArray(), int blockSize=3, bool useHarrisDetector=false, double k=0.04 )
参数详解:
InputArray image:输入图像。单通道图像,就是一般是灰度图像
OutputArray corners:输出的强角点的坐标属于vector<point2f> corners
int maxCorners:表示角点的最大数
double qualityLevel:最大最小特征值的乘法因子。定义可接受图像角点的最小质量因子。
double minDistance:限制因子。得到的角点的最小距离。使用 Euclidian 距离
InputArray mask=noArray():ROI:感兴趣区域。函数在ROI中计算角点,如果 mask 为 NULL,则选择整个图像。 必须为单通道的灰度图,大小与输入图像相同。mask对应的点不为0,表示计算该点。
int blockSize=3:计算某一像素点的协方差的邻域大小,3,5,7,9,。。。。。。
covariation matrix of derivatives over the neighborhood as:
double k=0.04 :HarrisDetector检测角点时所用的参数
opencv代码:
#include<opencv2/imgproc/imgproc.hpp> #include<opencv2/core/core.hpp> #include<opencv2/highgui/highgui.hpp> #include<iostream> using namespace cv; using namespace std; int main() { Mat src,src_gray; src= imread("D:6.jpg"); cvtColor(src, src_gray, CV_RGB2GRAY); vector<Point2f> corners; double qualityLevel = 0.01; double minDistance = 10; int blockSize = 3; bool useHarrisDetector = false; double k = 0.04; //<span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; background-color: rgb(248, 248, 248);">这里是0.04*max(min(e1,e2)),e1,e2是harris矩阵的特征值</span><span style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; background-color: rgb(248, 248, 248);"> </span> int maxCorners = 50; /// Copy the source image goodFeaturesToTrack(src_gray, corners, maxCorners, qualityLevel, minDistance, Mat(), blockSize, useHarrisDetector, k); /// Draw corners detected for (int i = 0; i < corners.size(); i++){ /*circle(src, corners[i], 5, Scalar(255), 2, 8, 0);*/ circle(src, corners[i], 4, Scalar(0, 255, 0), 2, 8, 0); } imshow("shiyan", src); waitKey(0); return 0; }