Adding modules from opencv_contrib to OpenCV

后端 未结 4 2013
闹比i
闹比i 2020-12-30 05:32

I\'m trying to add the xfeatures2d module from opencv_contrib to an existing OpenCV/Python project.

I\'ve downloaded the latest version of

相关标签:
4条回答
  • 2020-12-30 06:15

    you are missing the new, additional namespace:


    >>> help(cv2.xfeatures2d)
    Help on module cv2.xfeatures2d in cv2:
    
    NAME
        cv2.xfeatures2d
    
    FILE
        (built-in)
    
    FUNCTIONS
        SIFT(...)
            SIFT([, nfeatures[, nOctaveLayers[, contrastThreshold[, edgeThreshold[,
    sigma]]]]]) -> <xfeatures2d_SIFT object>
    
        SURF(...)
            SURF([hessianThreshold[, nOctaves[, nOctaveLayers[, extended[, upright]]
    ]]]) -> <xfeatures2d_SURF object>
    
        StarDetector(...)
            StarDetector([, _maxSize[, _responseThreshold[, _lineThresholdProjected[
    , _lineThresholdBinarized[, _suppressNonmaxSize]]]]]) -> <xfeatures2d_StarDetect
    or object>
    
    DATA
        FREAK_NB_ORIENPAIRS = 45
        FREAK_NB_PAIRS = 512
        FREAK_NB_SCALES = 64
    
    
    >>> surf = cv2.xfeatures2d.SURF(300)
    
    0 讨论(0)
  • 2020-12-30 06:23

    I encountered this same issue. I'm using python 2.7.6 and OpenCv 3.0 with the additional non-free modules. I do have xfeatures2d present in available modules and can import it, however it was as though xfeatures2d didn't contain SIFT or SURF. No matter how I called them it was the same Error:

    "AttributeError: 'module' object has no attribute 'SIFT'

    I tried the different name spaces suggested, and only recently noticed this detail and GOT IT WORKING!

    $ python

    >>>import cv2

    >>>help(cv2.xfeatures2d)

    You'll notice that it replies that it is now referred to as...

    FUNCTIONS

    SIFT_create(...)
    

    and

    SURF_create(...)
    

    So very simply - the namespace is NOT "cv2.SIFT()" or "cv2.xfeatures2d.SIFT" but rather

    cv2.xfeatures2d.SIFT_create()

    Please give it a shot!

    0 讨论(0)
  • 2020-12-30 06:27

    Another possibility (and the easiest one I found!) is to install the 2.4.9 release which already include SIFT and SURF algorithm. You just have to do then

    import cv2
    sift = cv2.SIFT()
    (...)
    
    0 讨论(0)
  • 2020-12-30 06:35

    Install it from pip

    Python 2.x

    pip install opencv-contrib-python
    

    Python 3.x

    pip3 install opencv-contrib-python
    

    Use sudo if a permsision error occurred.

    0 讨论(0)
提交回复
热议问题