1

I am trying to build this code: https://docs.opencv.org/3.2.0/d5/d6f/tutorial_feature_flann_matcher.html

I am using Ubuntu 16.04 with CLion 2017.3 and have OpenCV 3.4 installed.

xfeatures2d.hpp can't be found on the system.

I have looked at many different problems on the internet, but couldn't find a solution.

Any help?

Leta
  • 331
  • 1
  • 4
  • 16
  • non-free libs need to be explicitly downloaded, did you do this? see https://stackoverflow.com/questions/27418668/nonfree-module-is-missing-in-opencv-3-0 the repository is here: https://github.com/opencv/opencv_contrib – EdChum May 21 '18 at 10:09
  • Thanks a lot! I haven't don this. I will try it right away... – Leta May 21 '18 at 10:26
  • All the non-free (patent protected stuff) and experimental libs are separate downloads from the main package so they have to be downloaded separately I think this change was made between openCV 2 and 3 – EdChum May 21 '18 at 10:28

2 Answers2

0

You have to include cmake comiplation flag to opencv OPENCV_EXTRA_MODULES_PATH and set it to the opencv_contrib/modules.

cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules

craken
  • 1,411
  • 11
  • 16
0

Here's what I had to do to compile OpenCV with xfeatures2d:

  • Download opencv_contrib (I took a release from the releases page). This step is what gives us xfeatures2d.
  • Unpack the tarball somewhere, e.g., ~/src/opencv_contrib-4.5.5
  • When configuring OpenCV (the main OpenCV source like opencv-4.5.2) with CMake, add the following option to cmake command line (adjusting the value to be your actual path to the modules subdirectory of the opencv_contrib tarball):
-DOPENCV_EXTRA_MODULES_PATH=$HOME/src/opencv_contrib-4.5.5/modules/
  • Now just build as you normally would and install.

The above actions gave me the expected file (among others): /usr/include/opencv4/opencv2/xfeatures2d.hpp.

Ruslan
  • 18,162
  • 8
  • 67
  • 136