I\'m trying to add the xfeatures2d
module from opencv_contrib
to an existing OpenCV/Python project.
I\'ve downloaded the latest version of
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)
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!
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()
(...)
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.