2

I have a problem in python opencv!

I want to use SIFT algorithm which is not a default algorithm in opencv package. So I have to build OpenCV with extra modules as bellow:

You can build OpenCV, so it will include the modules from this repository. Here is the CMake command for you:

$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j5
$ make install

I did all these steps and it was successfully build. But I'm getting error when I call sub modules of opencv (e.g. xfeatures2d, objdetect). I tried using following code;

$ import cv2
$ x = cv2.xfeatures2d()

It gives me error that "module' object has no attribute 'xfeatures2d'".

Do you have any ideas?

  • 1
    Possible duplicate of [Opencv 3.0 - module object has no attribute 'xfeatures2d'](http://stackoverflow.com/questions/29713312/opencv-3-0-module-object-has-no-attribute-xfeatures2d) – Mitty Apr 12 '16 at 16:20
  • @Mitty can you please tell me how I can find opencv_source_directory? or what it is? so that I can use Cmake GUI! –  Apr 12 '16 at 16:29
  • Check if you have followed the installation instructions here, https://github.com/Itseez/opencv_contrib – Mitty Apr 12 '16 at 16:33
  • And which OS are you using?. – Mitty Apr 12 '16 at 16:34
  • the link that you gave I have read several times. I want exactly to know what they mean by `opencv_source_directory`? what should I give there? please help.. –  Apr 12 '16 at 16:40
  • I assume you already downloaded the opencv_contrib abd extracted it or cloned it. But you have to create another directory for building that opencv_contrib. Here the source directory means the path where you have downloaded and stored the opencv_contrib. – Mitty Apr 12 '16 at 16:43
  • and so what should I write for the first one in the above second line( `opencv_contrib`)?. since I put the opencv downloaded directory for the second one and `opencv_contrib` directory for the first one. –  Apr 12 '16 at 16:49

1 Answers1

2
  1. Download opencv_contrib from here
  2. Download opencv from here
  3. Now create a new directory called opencv_build
  4. Now go to opencv_build directory
  5. Here <opencv_contrib> points to downloaded folder from step 1
  6. And <opencv_source_directory> points to downloaded folder from step 2
  7. Substitute their paths in your cmake command.
Mitty
  • 330
  • 2
  • 15