【问题标题】:Where is the FAST algorithm in OpenCV?OpenCV 中的 FAST 算法在哪里?
【发布时间】:2016-09-09 10:03:21
【问题描述】:

我无法在 Python OpenCV 模块中找到 FAST 角点检测器, 我试过这个this,就像link中描述的那样。我的 OpenCV 版本是 3.1.0。

我知道 SIFT 和 SURF 等特征描述算法已转移到 cv2.xfeatures2d,但 FAST 算法不在此处。

【问题讨论】:

    标签: python opencv corner-detection


    【解决方案1】:

    我认为 opencv-3.1.0 文档中的示例代码没有更新。提供的代码将不起作用。

    试试这个:

        # Ref: https://github.com/jagracar/OpenCV-python-tests/blob/master/OpenCV-tutorials/featureDetection/fast.py
    import numpy as np
    import cv2
    from matplotlib import pyplot as plt
    
    img = cv2.imread('simple.jpg',0)
    
    # Initiate FAST object with default values
    fast = cv2.FastFeatureDetector_create(threshold=25)
    
    # find and draw the keypoints
    kp = fast.detect(img,None)
    img2 = cv2.drawKeypoints(img, kp, None,color=(255,0,0))
    
    print("Threshold: ", fast.getThreshold())
    print("nonmaxSuppression: ", fast.getNonmaxSuppression())
    print("neighborhood: ", fast.getType())
    print("Total Keypoints with nonmaxSuppression: ", len(kp))
    
    cv2.imwrite('fast_true.png',img2)
    
    # Disable nonmaxSuppression
    fast.setNonmaxSuppression(0)
    kp = fast.detect(img,None)
    
    print "Total Keypoints without nonmaxSuppression: ", len(kp)
    
    img3 = cv2.drawKeypoints(img, kp, None, color=(255,0,0))
    
    cv2.imwrite('fast_false.png',img3)
    

    【讨论】:

      【解决方案2】:

      根据opencv-3.1.0 documentation你可以这样在python中运行FAST:

      import numpy as np
      import cv2
      from matplotlib import pyplot as plt
      
      img = cv2.imread('simple.jpg',0)
      
      # Initiate FAST object with default values
      fast = cv2.FastFeatureDetector_create()
      
      # find and draw the keypoints
      kp = fast.detect(img,None)
      img2 = cv2.drawKeypoints(img, kp, color=(255,0,0))
      
      # Print all default params
      print "Threshold: ", fast.getInt('threshold')
      print "nonmaxSuppression: ", fast.getBool('nonmaxSuppression')
      print "neighborhood: ", fast.getInt('type')
      print "Total Keypoints with nonmaxSuppression: ", len(kp)
      
      cv2.imwrite('fast_true.png',img2)
      
      # Disable nonmaxSuppression
      fast.setBool('nonmaxSuppression',0)
      kp = fast.detect(img,None)
      
      print "Total Keypoints without nonmaxSuppression: ", len(kp)
      
      img3 = cv2.drawKeypoints(img, kp, color=(255,0,0))
      
      cv2.imwrite('fast_false.png',img3)
      

      【讨论】:

      • 这段代码对我不起作用,但是 Yahya 的解决方案对我有用。
      【解决方案3】:

      此代码作为官方文档代码仅与特定版本的opencv兼容,之后不再更新

      from __future__ import print_function
      import cv2
      
      img = cv2.imread('simple.jpg',0)
      img = cv2.imread(f,0)
      
      # Initiate FAST object with default values
      fast = cv2.FastFeatureDetector_create(threshold=25)
      
      # find and draw the keypoints
      kp = fast.detect(img,None)
      img2 = cv2.drawKeypoints(img, kp, None,color=(255,0,0))
      
      print("Threshold: ", fast.getThreshold())
      print("nonmaxSuppression: ", fast.getNonmaxSuppression())
      print("neighborhood: ", fast.getType())
      print("Total Keypoints with nonmaxSuppression: ", len(kp))
      
      img2_vis = cv2.resize(img2, (1600, 1000))
      cv2.imshow('fast_true',img2_vis),cv2.waitKey()
      
      # Disable nonmaxSuppression
      fast.setNonmaxSuppression(0)
      kp = fast.detect(img,None)
      
      print("Total Keypoints without nonmaxSuppression: ", len(kp))
      
      img3 = cv2.drawKeypoints(img, kp, None, color=(255,0,0))
      
      img3_vis = cv2.resize(img3, (1600, 1000))
      cv2.imshow('fast_false',img3_vis),cv2.waitKey()
      
      

      【讨论】:

        猜你喜欢
        • 2023-03-18
        • 1970-01-01
        • 2015-04-21
        • 2012-04-03
        • 1970-01-01
        • 2012-01-24
        • 1970-01-01
        • 1970-01-01
        • 2020-04-14
        相关资源
        最近更新 更多