寻找Harris、Shi-Tomasi和亚像素角点

简介: Harris、Shi-Tomasi和亚像素角点都是角点,隶属于特征点这个大类(特征点可以分为边缘、角点、斑点).一、Harris角点检测是一种直接基于灰度图像的角点提取算法,稳定性较高,但是也可能出现有用信息丢失的情况。

Harris、Shi-Tomasi和亚像素角点都是角点,隶属于特征点这个大类(特征点可以分为边缘、角点、斑点).

一、Harris角点检测是一种直接基于灰度图像的角点提取算法,稳定性较高,但是也可能出现有用信息丢失的情况。
函数:cornerHarris()
void cv::cornerHarris ( InputArray  src,  //需要为8位单通道
    OutputArray  dst,  //结果
    int  blockSize, //领域大小
    int  ksize, //Sobel孔径大小
    double  k, //Harris参数
    int  borderType = BORDER_DEFAULT 
  )    

Harris corner detector.

The function runs the Harris corner detector on the image. Similarly to cornerMinEigenVal and cornerEigenValsAndVecs , for each pixel (x, y) it calculates a 2\times2 gradient covariance matrix M^{(x,y)} over a \texttt{blockSize} \times \texttt{blockSize} neighborhood. Then, it computes the following characteristic:

(特征点计算方法)

 

 

Corners in the image can be found as the local maxima of this response map.

Parameters
src Input single-channel 8-bit or floating-point image.
dst Image to store the Harris detector responses. It has the type CV_32FC1 and the same size as src .
blockSize Neighborhood size (see the details on cornerEigenValsAndVecs ).
ksize Aperture parameter for the Sobel operator.
k Harris detector free parameter. See the formula below.
borderType Pixel extrapolation method. See cv::BorderTypes.
调用:
 
    Mat srcGray = imread("e:/template/lena.jpg",IMREAD_GRAYSCALE);
    //进行角点检测
    Mat matHarris;
    cornerHarris(srcGray,matHarris,2,3,0.01);
    //显示
    Mat matDst;
    threshold(matHarris,matDst,0.00001,255,THRESH_BINARY);
    imshow("matDst",matDst);
    waitKey(0);
lena的结果:
二、Shi-Tomasi角点
一般认为是Harris的改进,因为当时提出的论文叫做《Good Features to Track》,所以这种角点再OpenCV中叫做goodFeatures
函数:goodFeaturesToTrack()
void cv::goodFeaturesToTrack ( InputArray  image,//输入图像
    OutputArray  corners,//输出向量
    int  maxCorners,//角点最大数量
    double  qualityLevel,//角点检测可接受的最小特征值
    double  minDistance,//角点之间的最小距离
    InputArray  mask = noArray(),//感兴趣区域
    int  blockSize = 3,//领域范围
    bool  useHarrisDetector = false,//true为harris;false为Shi-Tomasi
    double  k = 0.04 //权重系数
  )    

Determines strong corners on an image.

The function finds the most prominent corners in the image or in the specified image region, as described in [154]

  • Function calculates the corner quality measure at every source image pixel using the cornerMinEigenVal or cornerHarris .
  • Function performs a non-maximum suppression (the local maximums in 3 x 3 neighborhood are retained).
  • The corners with the minimal eigenvalue less than qualityLevelmaxx,yqualityMeasureMap(x,y) are rejected.
  • The remaining corners are sorted by the quality measure in the descending order.
  • Function throws away each corner for which there is a stronger corner at a distance less than maxDistance.

The function can be used to initialize a point-based tracker of an object.

Note
If the function is called with different values A and B of the parameter qualityLevel , and A > B, the vector of returned corners with qualityLevel=A will be the prefix of the output vector with qualityLevel=B .
Parameters
image Input 8-bit or floating-point 32-bit, single-channel image.
corners Output vector of detected corners.
maxCorners Maximum number of corners to return. If there are more corners than are found, the strongest of them is returned. maxCorners <= 0 implies that no limit on the maximum is set and all detected corners are returned.
qualityLevel Parameter characterizing the minimal accepted quality of image corners. The parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue (see cornerMinEigenVal ) or the Harris function response (see cornerHarris ). The corners with the quality measure less than the product are rejected. For example, if the best corner has the quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure less than 15 are rejected.
minDistance Minimum possible Euclidean distance between the returned corners.
mask Optional region of interest. If the image is not empty (it needs to have the type CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.
blockSize Size of an average block for computing a derivative covariation matrix over each pixel neighborhood. See cornerEigenValsAndVecs .
useHarrisDetector Parameter indicating whether to use a Harris detector (see cornerHarris) or cornerMinEigenVal.
k Free parameter of the Harris detector.
调用:
Mat srcGray = imread("e:/template/lena.jpg",IMREAD_GRAYSCALE);    
//进行角点检测
    Mat matHarris;
    vector<Point2f> corners;//输出向量
    goodFeaturesToTrack(srcGray,corners,100,0.01,10,Mat(),3,false,0.04);
    //显示
    Mat matDst = srcGray.clone();
    for (int i=0;i<corners.size();i++)
    {
        circle(matDst,corners[i],2,Scalar(255));
    }
     
    imshow("matDst",matDst);
    waitKey(0);
结果:
可以看到,眼部、帽子上面的尖端这些的却是"GoodFeatures"的地方都被标注了出来
三、如果需要亚像素的角点,我们必须更进一步。
函数:cornerSubPix()
void cv::cornerSubPix ( InputArray  image,
    InputOutputArray  corners,
    Size  winSize,
    Size  zeroZone,
    TermCriteria  criteria 
  )    
调用:需要注意现计算goodfeatures再算亚像素
Mat srcGray = imread("e:/template/lena.jpg",IMREAD_GRAYSCALE);
    //进行角点检测
    Mat matHarris;
    vector<Point2f> corners;//输出向量
    cv::goodFeaturesToTrack(
        srcGray,                              // Image to track
        corners,                          // Vector of detected corners (output)
        MAX_CORNERS,                       // Keep up to this many corners
        0.01,                              // Quality level (percent of maximum)
        5,                                 // Min distance between corners
        cv::noArray(),                     // Mask
        3,                                 // Block size
        false,                             // true: Harris, false: Shi-Tomasi
        0.04                               // method specific parameter
        );
    cv::cornerSubPix(
        srcGray,                          // Input image
        corners,                          // Vector of corners (input and output)
        cv::Size(55),      // Half side length of search window
        cv::Size(-1,-1),                   // Half side length of dead zone (-1=none)
        cv::TermCriteria(
            cv::TermCriteria::MAX_ITER | cv::TermCriteria::EPS,
            20,                              // Maximum number of iterations
            0.03                             // Minimum change per iteration
            )
        );
    //显示
    Mat matDst = srcGray.clone();
    for (int i=0;i<corners.size();i++)
    {
        circle(matDst,corners[i],2,Scalar(255));
        cout<<"\t"<<"序号"<<i<<"亚像素坐标("<<corners[i].x<<","<<corners[i].y<<")"<<endl;
    }
     
    imshow("matDst",matDst);
    waitKey(0);
结果:
可以看到其计算处理小数点后面的值。
四、小结
角点虽然现在用的比较少了,但是作为基本的知识有必要了解;下一步的更为复杂的特征点模型都是基于角点的,它们之间有着一脉相承的关系。

 

目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com
目录
相关文章
|
6月前
|
算法 API 计算机视觉
图像处理之角点检测与亚像素角点定位
图像处理之角点检测与亚像素角点定位
73 1
|
6月前
|
计算机视觉 Python
Shi-Tomasi角检测
【6月更文挑战第5天】Shi-Tomasi角检测。
23 2
harris角点检测
harris角点检测
39 0
角点检测汇总
角点检测汇总
41 0
GEE基础学习——Canny 边缘检测器(NDVI边缘提取)
GEE基础学习——Canny 边缘检测器(NDVI边缘提取)
409 0
GEE基础学习——Canny 边缘检测器(NDVI边缘提取)
|
机器学习/深度学习 传感器 数据采集
基于Zernike矩实现亚像素边缘检测附matlab代码
基于Zernike矩实现亚像素边缘检测附matlab代码
|
传感器 机器学习/深度学习 算法
【方位估计 】基于music算法均匀线阵的标量阵与矢量阵的方位估计附Matlab源码
【方位估计 】基于music算法均匀线阵的标量阵与矢量阵的方位估计附Matlab源码
|
算法 API 计算机视觉
图像特征提取与描述_角点特征01:Harris算法+Shi-Tomas算法
Harris角点检测的思想是通过图像的局部的小窗口观察图像,角点的特征是窗口沿任意方向移动都会导致图像灰度的明显变化
206 0
|
机器学习/深度学习 编解码 算法
CVPR2020丨DRN:用于单图像超分辨率的对偶回归网络
论文针对这两个主要的问题进行改进,提出了对偶回归策略,通过引入对 LR 图像额外的约束,从而减小解空间的大小。也就是说,模型除了学习LR到HR图像的映射外,还学习了额外的对偶回归映射,用于估计下采样内核并重建LR图像,从而形成一个闭环以提供额外的监督。
CVPR2020丨DRN:用于单图像超分辨率的对偶回归网络
|
资源调度 计算机视觉
CV10 图像模糊(均值、高斯、中值、双边滤波)
当我们只想得到感兴趣的物体时,通过图像模糊,可以将那些尺寸和亮度较小的物体过滤掉,较大的物体则易于检测。除了降低噪声,这就是图像平滑(模糊)的另一个重要应用:减少噪点,突出ROI,以便目标提取。
358 0