ROS: OpenCV SURF is there but can't be found [closed]

asked 2014-09-09 15:20:45 -0600

Metalzero2 gravatar image

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).

In the ROS ask website, they told me that I am doing something wrong with OpenCV and the make file. They said I should ask here for help. Here is my CMakeLists.txt :

cmake_minimum_required(VERSION 2.8.3)
project(opencv_ros)

find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  image_transport
  roscpp
  sensor_msgs
  std_msgs
)

catkin_package(  CATKIN_DEPENDS cv_bridge image_transport roscpp sensor_msgs std_msgs )

include_directories(${catkin_INCLUDE_DIRS})

add_executable(open src/open.cpp)
target_link_libraries(open ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
add_dependencies(open opencv_ros_generate_messages_cpp)

I am running ubuntu 14.04 64bit on Indigo with OpenCV 2.4.9 .

Why cant it find SURF or SIFT in ROS?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-27 18:16:53.116113

Comments

1

your headers look correct, it's a linker problem though. one way or other, you're missing the opencv_nonfree lib. try something like:

target_link_libraries(open ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} opencv_nonfree  )
berak gravatar imageberak ( 2014-09-10 01:12:13 -0600 )edit

@berak I did what you said but now I get new error /usr/bin/ld: cannot find -lopencv_nonfree collect2: error: ld returned 1 exit status now what? why am I missing only opencv_nonfree and not any other lib?

Metalzero2 gravatar imageMetalzero2 ( 2014-09-11 06:15:01 -0600 )edit

tbh, i got no idea about ROS. sorry.

berak gravatar imageberak ( 2014-09-11 06:22:38 -0600 )edit

@berak hey there. I was looking for the OpenCV folder I found something interesting. I have ubuntu 14.04 and went to /usr/include/opencv2 and saw that I am missing two modules (according to the OpenCV 2.4.9 documentation). There where no folders named "nonfree" and "viz". Probably this is my problem. Any idea how to fix this? How can I add them to my system?

I remember that when I build openCV I included in the options the nonfree module, for sure :/ .

Metalzero2 gravatar imageMetalzero2 ( 2014-09-11 16:19:11 -0600 )edit

nonfree is the one, and you can safely rule out the viz module (which is about rendering 3d pointclouds)

maybe it is all about building the ROS package with cmake -DBUILD_opencv_nonfree=ON ? (or similar)

berak gravatar imageberak ( 2014-09-11 17:05:24 -0600 )edit

@berak the thing is I am trying to use the nonfree module in a openCV project (nothing to do with ROS) and I can't now. I reinstalled OpenCV and I guess that made the problem. But now I can see the nonfree module does not exist at all. How can I add it now to my OpenCV library ?

Metalzero2 gravatar imageMetalzero2 ( 2014-09-11 17:10:38 -0600 )edit

again, check what's set for cmake -DBUILD_opencv_nonfree=ON originally, and change it

another thing, you're sure you're on 2.4.9 ? do a git branch to be sure (if the src was from github)

SURF and SIFT got moved to https://github.com/itseez/opencv_contrib in 3.0

berak gravatar imageberak ( 2014-09-11 17:17:49 -0600 )edit

@berak I'm sorry for being annoying but I am really trying to understand what is going on. Not so good with this stuff yet.

I am using the GUI CMake. I download the source and build it. When I build it, the option "BUILD_opencv_nonfree" is selected (it is true). What do you mean to check what is selected and how to change it?

Metalzero2 gravatar imageMetalzero2 ( 2014-09-11 17:31:37 -0600 )edit

it's not you, who is annoying, it's this thing ... ;)

if BUILD_opencv_nonfree is selected there, it should be build.

i'm a bit out of ideas. were there any error messages ? something in the cmake output ?

berak gravatar imageberak ( 2014-09-12 00:42:59 -0600 )edit

@berak I don't remember any error messages or any special output. I am not sure now if there was anything in particular. If I use CMake to build it again and then "make" the library again, will that make any problems or will it just add anything that is not where is should be?

Metalzero2 gravatar imageMetalzero2 ( 2014-09-12 03:23:38 -0600 )edit