Ask Your Question
0

cannot import xfeatures2d in OpenCV 3- Python binding

asked Feb 15 '15

krips89 gravatar image

I am trying to access SIFT and SURF features from opencv 3 in python. As suggested by other people, I followed the installation of opencv_contrib. Some of the logs of the installation are:

[ 82%] Built target opencv_xfeatures2d
...
Installing: /usr/local/lib/libopencv_xfeatures2d.so
-- Set runtime path of "/usr/local/lib/libopencv_xfeatures2d.so.3.0.0" to "/usr/local/lib"
-- Installing: /usr/local/include/opencv2/xfeatures2d.hpp
-- Installing: /usr/local/include/opencv2/xfeatures2d/cuda.hpp
-- Installing: /usr/local/include/opencv2/xfeatures2d/nonfree.hpp

After that I import cv2 in python but could not import xfeatures2d.

>>> import cv2
>>> cv2.xfeatures2d.SIFT_create()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'xfeatures2d'

Also, cv2.__version__ gives '2.4.8'! How can I fix this?

Preview: (hide)

Comments

this means, that opencv got built, and also the opencv_contrib parts, but maybe not the python wrappers. can you look again at the cmake output ? somewhere at the top is a list of enabled / disabled modules.

also, python version ? are there more than 1 python install on your box ?

berak gravatar imageberak (Feb 15 '15)edit
1

@krips89: I guess, you have an opencv 2.4.8 version installed and your import cv2 still points to that, so you'd need to deinstall that and make sure your PYTHON_PATH points to the correct folder (containing the new cv2.so file). Please report back! In the near future I also want to migrate to OCV 3.0 (unfortunately currently too many features are still missing there which makes it barely usable for me)

Guanta gravatar imageGuanta (Feb 15 '15)edit

1 answer

Sort by » oldest newest most voted
2

answered Feb 16 '15

krips89 gravatar image

Hi, I traced everything and found the issue. The python module was not getting compiled (and hence pointing to the old installation) as cmake could not find PYTHON_INCLUDE_DIR (for some unknown reason, I have no idea, cmake could find PYTHON_LIBRARY and the interpreter but not the include directory) which is the reason though opencv_contrib was getting build, cv2.so was not. By doing some hit and trial in cmake, I could get Opencv 3 working in python, although Opencv 3 has issues on a very different level! Hope it helps.

Preview: (hide)

Comments

Did you ever find an answer to http://answers.opencv.org/questions/6... ?

Owen gravatar imageOwen (Oct 1 '15)edit

which cmake file it is to change

sravanth gravatar imagesravanth (Jun 21 '16)edit

Question Tools

1 follower

Stats

Asked: Feb 15 '15

Seen: 11,134 times

Last updated: Feb 15 '15