Ask Your Question
0

Feature matching tutorial compilation problem

asked 2013-07-26 15:36:08 -0500

LadyZayin gravatar image

I am trying to compile the code in this tutorial, but I get the following error messages:

feature.cpp: In function ‘int main(int, char**)’:
feature.cpp:26:3: error: ‘SurfFeatureDetector’ was not declared in this scope
feature.cpp:26:23: error: expected ‘;’ before ‘detector’
feature.cpp:30:3: error: ‘detector’ was not declared in this scope
feature.cpp:34:3: error: ‘SurfDescriptorExtractor’ was not declared in this scope
feature.cpp:34:27: error: expected ‘;’ before ‘extractor’
feature.cpp:38:3: error: ‘extractor’ was not declared in this scope
feature.cpp:24:7: warning: unused variable ‘minHessian’ [-Wunused-variable]

However, I am pretty sure I linked the right libraries. Here is my build command (from Geany):

g++ -Wall -o "%e" "%f" -I /usr/include/opencv2/ -lopencv_features2d -lopencv_core -lopencv_highgui -lopencv_imgproc

I don't understand why it doesn't work because the core and highgui libraries are not causing any issue. I checked my /usr/include/opencv2/features2d folder and I did find features2d.hpp. However, if I replace

#include "opencv2/features2d/features2d.hpp"

in the program by

#include "opencv2/nonfree/features2d.hpp"

I get the following compilation error:

/usr/bin/ld: /tmp/ccVyvyXB.o: undefined reference to symbol 'cv::flann::SearchParams::SearchParams(int, float, bool)'
/usr/bin/ld: note: 'cv::flann::SearchParams::SearchParams(int, float, bool)' is defined in DSO /usr/lib/libopencv_flann.so.2.3 so try adding it to the linker command line
/usr/lib/libopencv_flann.so.2.3: could not read symbols: Invalid operation
collect2: ld returned 1 exit status

What am I doing wrong? Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2013-07-28 14:42:28 -0500

Guanta gravatar image

I don't know how often this question already came up. It seems the tutorial is a little bit outdated, so not your fault (however you could have searched here this forum!). Anyway the solution is to include both features2d/features2d.hpp and nonfree/nonfree.hpp, if you want to use flann, also include flann/flann.hpp . Furthermore call initModule_nonfree(); before using the nonfree-module.

edit flag offensive delete link more

Comments

Thanks for your reply. I do have searched the forum, but the questions I found were slightly different... Anyway, I have included all of the following:

"<opencv2/core/core.hpp> <opencv2/nonfree/nonfree.hpp> <opencv2/features2d/features2d.hpp> <opencv2/highgui/highgui.hpp> <stdio.h> <iostream>"

but I still get:

/usr/bin/ld: /tmp/ccPbfO0y.o: undefined reference to symbol 'cv::flann::SearchParams::SearchParams(int, float, bool)'

/usr/bin/ld: note: 'cv::flann::SearchParams::SearchParams(int, float, bool)' is defined in DSO /usr/lib/libopencv_flann.so.2.3 so try adding it to the linker command line

/usr/lib/libopencv_flann.so.2.3: could not read symbols: Invalid operation

Then, I included flann.hpp as well and added -lopencv_flann to the build command and I get new errors, such as

LadyZayin gravatar imageLadyZayin ( 2013-07-29 09:57:56 -0500 )edit

feature.cpp:(.text._ZN2cv4SURFD1Ev[cv::SURF::~SURF()]+0x1e): undefined reference to `vtable for cv::SURF'

feature.cpp:(.text._ZN2cv4SURFD1Ev[cv::SURF::~SURF()]+0x6b): undefined reference to `cv::Algorithm::~Algorithm()'

Actually, I just realized that there is no nonfree folder in /usr/include/opencv2. I just tried to find a way of installing it individually, but I couldn't find a way. Hmm.

LadyZayin gravatar imageLadyZayin ( 2013-07-29 10:04:44 -0500 )edit

Hve you also called initModule_nonfree() before calling any SURF methods? And did you link also against nonfree-lib?

Guanta gravatar imageGuanta ( 2013-07-29 10:24:41 -0500 )edit

Yes I have. I'm reinstalling OpenCV now and making sure nonfree is too. Hopefully that'll fix the issue. [Edit] It's still not working. Here is my current build command:

g++ -Wall -o "feature" "feature.cpp" -I /usr/include/opencv2/ -lopencv_features2d -lopencv_highgui -lopencv_imgproc -lopencv_nonfree -lopencv_flann -lopencv_core

And this is what I get:

/usr/bin/ld: warning: libopencv_core.so.2.4, needed by /usr/local/lib/libopencv_nonfree.so, may conflict with libopencv_core.so.2.3

/usr/bin/ld: /tmp/ccGzJyU9.o: undefined reference to symbol 'cv::Algorithm::~Algorithm()'

/usr/bin/ld: note: 'cv::Algorithm::~Algorithm()' is defined in DSO /usr/local/lib/libopencv_core.so.2.4 so try adding it to the linker command line

Does the order of linked libraries matter?

LadyZayin gravatar imageLadyZayin ( 2013-07-29 10:39:29 -0500 )edit

Now it seems that you have built nonfree w. opencv2.4 but it tries to link it with the core of 2.3. So, you should fix that. Some further notes: I think it should be -I/usr/include (without /opencv2) . For building your program, please have a look at http://answers.opencv.org/question/14611/example-of-makefile/#14649 .

Guanta gravatar imageGuanta ( 2013-07-29 14:08:58 -0500 )edit
1

Thanks, I'll have a look at it. Sorry for my double posting (now fixed), there seems to be server problems.

[Edit] I just solved my problem in an unexpected way. I changed my build command to "g++ -Wall -o "feature" "feature.cpp" -I /usr/include/ $(pkg-config --cflags --libs opencv)" and it worked. I'm surprised because I had tried it before and it had failed. I guess reinstalling might have fixed the issue.

Thanks a lot for your help! :)

LadyZayin gravatar imageLadyZayin ( 2013-07-29 15:40:11 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-07-26 15:36:08 -0500

Seen: 4,396 times

Last updated: Jul 28 '13