Problem compiling nonfree opencv modules


#1

Hi!

For a personal project I’m trying to identify if a small image is part of a bigger image.

After reading this forum and other websites I learned about the SIFT feature detection and matching algorithm. I also learned that the algorithm is proprietary (and therefore not included in the opencv library by default) and that, in order to use it, I should compile opencv with the opencv_contrib modules… but despite all my efforts I haven’t been able to use it with openframeworks.

My problem is that after I compile the library and run the code I get the following error:

Undefined symbols for architecture x86_64:
“cv::Feature2D::write(cv::FileStorage&) const”, referenced from:
vtable for cv::xfeatures2d::SIFT in ofApp.o
construction vtable for cv::Feature2D-in-cv::xfeatures2d::SIFT in ofApp.o
“cv::Feature2D::read(cv::FileNode const&)”, referenced from:
vtable for cv::xfeatures2d::SIFT in ofApp.o
construction vtable for cv::Feature2D-in-cv::xfeatures2d::SIFT in ofApp.o
“cv::Feature2D::getDefaultName() const”, referenced from:
vtable for cv::xfeatures2d::SIFT in ofApp.o
construction vtable for cv::Feature2D-in-cv::xfeatures2d::SIFT in ofApp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I’m using Xcode 10.1 and Mojave.

I’m quite new to OF and the first time I attempt to compile a library, so I’m probably doing something (or, well, several things) wrong.

Is there a way to fix that issue? Or a different approach I could use (for instance, could I find the library compiled somewhere?)


Here’s the process I’ve followed:

  1. Downloaded the 3.4.3 version of the opencv source
  2. Downloaded the 3.4 branch of opencv_contrib
  3. Used CMAKE to configure and generate the binaries using the following parameters:- Specified the “Unix Makefiles” generator and “Use default native compilers”
    • Unchecked BUILD_SHARED_LIBS and BUILD_TESTS (per Shiffman’s tutorial)
    • Pointed the OPENCV_EXTRA_MODULES_PATH to the opencv_contrib modules directory
    • Unchecked WITH_1394 and WITH_FFMPEG (per this guide)
    • Checked OPENCV_ENABLE_NONFREE
    • Set the CMAKE_OSX_SYSROOT to point to “/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk”
    • Added x86_64 to CMAKE_OSX_ARCHITECTURES (per this guide)

After setting that configuration I click on “Configure” again and then on “Generate”. When that has finished I run “make” and then “sudo make install” in the build directory.

After those commands are finished without errors my /usr/local/include/opencv2 directory contains the compiled modules with xfeatures2d.hpp and xfeatures2d/nonfree.hpp too.

Next thing I do is go to the addons folder of OF, open the ofxOpenCv directory and replace the /openframeworks/addons/ofxOpenCv/libs/opencv/include/opencv2 directory with the one I generated.

I also update the /openframeworks/addons/ofxOpenCv/libs/opencv/lib/emscripten directory with the libs I generated in the building process.

Then I open projectGenerator and create a new project with ofxCv and ofxOpenCv.

In order to use SIFT I add the following lines to ofApp.h:

#include “ofxOpenCv.h”
#include “ofxCv.h”

#include “opencv2/xfeatures2d/nonfree.hpp”

using namespace cv;
using namespace ofxCv;

and then, just to test everything, I add:

cv::xfeatures2d::SiftFeatureDetector detector;

to ofApp::setup()


#2

Ok, I just learned about apothecary, so I’m going to try to build the library using it.