OpenCV SURF is there but can't be found
I was able to run OpenCV with ROS. I have run basic things (like loading images, getting video stream ect) but I am trying to run SURF or SIFT and I get this error:
Linking CXX executable /home/jim/ROS/catkin_ws/devel/lib/opencv_ros/open
CMakeFiles/open.dir/src/open.cpp.o: In function `main':
open.cpp:(.text+0x15b): undefined reference to `cv::SURF::SURF(double, int, int, bool, bool)'
CMakeFiles/open.dir/src/open.cpp.o: In function `cv::SURF::~SURF()':
open.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0xe): undefined reference to `vtable for cv::SURF'
open.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x26): undefined reference to `vtable for cv::SURF'
open.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x2e): undefined reference to `vtable for cv::SURF'
open.cpp:(.text._ZN2cv4SURFD1Ev[_ZN2cv4SURFD1Ev]+0x3b): undefined reference to `VTT for cv::SURF'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/jim/ROS/catkin_ws/devel/lib/opencv_ros/open] Error 1
make[1]: *** [opencv_ros/CMakeFiles/open.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
The project name is "opencv_ros" and the code is in "open.cpp". I have include these headers:
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
the thing is that when I run the same code in my c++ IDE (code::blocks) it runs just fine. I even found the header file and saw that it's in the correct place (according to the include I gave).
I am running ubuntu 14.04 64bit on Indigo with OpenCV 2.4.9 .
Why cant it find SURF in ROS?
Asked by Metalzero2 on 2014-08-27 08:57:28 UTC
Answers
Your includes are fine. You need to link against the library which provides the SURF implementation. You probably need an additional target_link_library call in your CMakeLIsts.txt to link in the appropriate library from opencv.
Asked by tfoote on 2014-08-27 15:37:31 UTC
Comments
From what I know "opencv2/nonfree/features2d.hpp" is the file that has it. At the end of the CMakeList I have these two:
include_directories(${catkin_INCLUDE_DIRS})
target_link_libraries(open ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
what else do I need to target for OpenCV 2.4.9 to work?
Asked by Metalzero2 on 2014-08-27 16:41:41 UTC
This is more of an opencv issue. I suggest asking it on their forums. There's already a bunch of similar questions.
- https://stackoverflow.com/questions/9968993/opencv-undefined-reference-surffeaturedetector-and-bruteforcematcher
- https://stackoverflow.com/questions/12871137/undefined-in-opencv-nonfree-features2d-when-using-ndk-to-build
- http://answers.opencv.org/question/445/242-android-missing-nonfree-package/
- http://answers.opencv.org/question/9308/error-descriptor-surf-c-opencv-on-android/\
- http://answers.opencv.org/question/17603/feature-matching-tutorial-compilation-problem/
Asked by tfoote on 2014-08-27 17:05:03 UTC
@tfoote thanks for the links but I have done all that stuff (at least the ones I understood). I think the problem is with ROS (or how I use it) because when I run the same code from my IDE (code::blocks), everything works fine. So the OpenCV library is not the problem I think.
Asked by Metalzero2 on 2014-08-27 17:54:24 UTC
If you don't have the symbol, you need to add something to your link line. My suggestion is that you ask opencv experts what you need to add to the linking for that to work. ROS uses they system version of openCV. If it works in codeblocks you should find out what they are linking against and make sure you are replicating that list.
Asked by tfoote on 2014-08-27 18:16:16 UTC
Comments