• OpenCV教程(44) harris角的检测(2)


          在上一篇教程中,我们得到的harris特征角二值图中,角的数目特别多,本章我们用一个局部最大化的方法,只保留局部值最大的harris特征角。

    // Harris角计算
    cv::cornerHarris(image,cornerStrength,
            neighbourhood, // neighborhood size
            aperture,     // aperture size
            k);           // Harris parameter   
    // internal threshold computation
    double minStrength;

    得到harris角结果图中的最小值,最大值。
    cv::minMaxLoc(cornerStrength,
         &minStrength,&maxStrength);

    // local maxima detection
    cv::Mat dilated;  // temporary image

        使用一个膨胀操作,这样局部的值都会变为最大的值,然后再比较操作,这样localMax中,最大值位置的像素值为255,其它则为0。
    cv::dilate(cornerStrength,dilated,cv::Mat());
    cv::compare(cornerStrength,dilated,
                localMax,cv::CMP_EQ);

          下面左边的图是原始harris角检测图二值化后的结果,右边是检测结果局部最大化后的结果,可以看到局部最大化后,角的位置会有轻微的变化。

    imageimage
    用下面的代码,我们可以得到最大值的harris角,而对于其它值的角则移去。

    cv::threshold(cornerStrength,cornerTh,
                  threshold,255,cv::THRESH_BINARY);
    // convert to 8-bit image
    cornerTh.convertTo(cornerMap,CV_8U);   
    // non-maxima suppression
    cv::bitwise_and(cornerMap,localMax,cornerMap);

    去掉其它值的角后,harris角图为(白色的点):

    image

    对于cornerMap的点,我们可以用一个circle来标记它。

    程序运行后,结果如下:

    image

    程序代码:参考FirstOpenCV48

    代码下载:http://yunpan.cn/Q4a6K68ASC5Xy

  • 相关阅读:
    Java之美[从菜鸟到高手演变]之设计模式
    Akka边学边写(1)-- Hello, World!
    [D3 + AngularJS] 15. Create a D3 Chart as an Angular Directive
    [D3] 14. Line and Area Charts with D3
    [D3] 13. Cleaner D3 code with selection.call()
    [D3] 12. Basic Transitions with D3
    [D3] 9. Scatter Plot
    [D3] 8. Margins
    [D3] 7. Quantitative Scales
    Runoob-Java-高级教程-实例-字符串:09. Java 实例
  • 原文地址:https://www.cnblogs.com/mikewolf2002/p/3547437.html
Copyright © 2020-2023  润新知