Ask Your Question
0

cannot import xfeatures2d in OpenCV 3- Python binding

asked 2015-02-15 08:19:44 -0600

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?

edit retag flag offensive close merge delete

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 ( 2015-02-15 08:31:12 -0600 )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 ( 2015-02-15 11:06:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-02-16 04:21:11 -0600

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.

edit flag offensive delete link more

Comments

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

Owen gravatar imageOwen ( 2015-10-01 15:02:55 -0600 )edit

which cmake file it is to change

sravanth gravatar imagesravanth ( 2016-06-20 23:58:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-02-15 08:19:44 -0600

Seen: 11,017 times

Last updated: Feb 15 '15