ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

Problems integrating OpenCV with ROS Indigo

asked 2016-01-19 15:43:45 -0600

Raiden gravatar image

updated 2016-01-19 15:53:17 -0600

I am trying to build a simple program to start working with OpenCV with ROS Indigo; however, whenever I try to build the code (catkin_make) the build fails and returns " undefined reference to 'cv::imread(cv::String const&, int)' " and so on for all the other OpenCV functions. This makes it impossible for me to build and run my test program for ROS and I'm at a loss for how to continue. I've quoted the program and CMakeLists.txt below.

OpenCV 3.1 is installed and has been successfully compiled using g++ in the terminal. The OS is LinuxMint 17.3

Program imgloader.cpp:

#include <ros/ros.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv; using namespace std;

int main(int argc, const char** argv){  
Mat img = imread("img.jpeg", CV_LOAD_IMAGE_UNCHANGED);
if(img.empty()){
       cout << "Image cannot be found or opened..." << endl;
       return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);
waitKey(0);
destroyWind("MyWindow");
return 0;
}

The following has been added to the CMakeLists.txt file for the package "opencvtest"

find_package(OpenCV REQUIRED) 
include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}) 
add_executable(imgloader src/imgloader.cpp)
target_link_libraries(imgloader ${catkin_LIBRARIES} ${OpenCV_LIBRARIES}) 
add_dependencies(imgloader opencvtest)

And the following dependency has been added:

<build_depend>opencv2</build_depend>
<run_depend>opencv2</run_depend>

What do I need to add or do to make my package build?

edit retag flag offensive close merge delete

Comments

Please use the "Preformatted Text" button (marked "101010") to format your code sample so that it is readable.

ahendrix gravatar image ahendrix  ( 2016-01-19 15:46:37 -0600 )edit

First post, it's been edited now.

Raiden gravatar image Raiden  ( 2016-01-19 15:49:56 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-01-19 16:08:39 -0600

lucasw gravatar image

updated 2016-01-19 16:14:11 -0600

If you really want opencv 3 see http://answers.ros.org/question/21404...

Otherwise uninstall your opencv 3 and use http://wiki.ros.org/cv_bridge which comes with opencv 2.4- it probably is already on your system. Just have build/run_depends on cv_bridge and catkin will bring in the headers and libraries, you won't need a find_package for opencv.

edit flag offensive delete link more

Comments

If you use OpenCV directly, you should directly find_pacakge() it. Do not rely on transitive dependencies; the upstream package may change.

ahendrix gravatar image ahendrix  ( 2016-01-19 16:23:04 -0600 )edit

I uninstalled my OpenCV 3 and ran catkin_make afterwards (I did not change any of the code/dependencies). The code built and ran. Thank you for your answer.

Raiden gravatar image Raiden  ( 2016-01-19 16:23:58 -0600 )edit

cv_bridge package.xml has <build_depend>libopencv-dev</build_depend> - and a few other image processing packages use it, so that could be used without transitivity and without a find_package.

lucasw gravatar image lucasw  ( 2016-01-19 16:26:35 -0600 )edit
1

I just said that relying on the dependency through cv_bridge is not a good idea. If your package uses a library, you should depend on it directly. (just because it works another way doesn't make it a good idea).

ahendrix gravatar image ahendrix  ( 2016-01-19 16:30:58 -0600 )edit

Looking through the rosdep database, it looks like a <build_depend> on opencv2 is deprecated or wrong. The dependency in the package.xml should be <build_depend>libopencv-dev</build_depend> .

ahendrix gravatar image ahendrix  ( 2016-01-19 16:38:56 -0600 )edit

According to http://answers.ros.org/question/18510... cv_bridge is the the right dependency, though http://wiki.ros.org/vision_opencv doesn't really back that up.

lucasw gravatar image lucasw  ( 2016-01-19 17:05:15 -0600 )edit

Hrm... yeah. It looks like the dependency through cv_bridge is the only option that is backwards-compatible with Hydro.

ahendrix gravatar image ahendrix  ( 2016-01-19 17:52:19 -0600 )edit

Yes, I remember having to do that to maintain common source between Hydro and Indigo.

joq gravatar image joq  ( 2016-01-19 21:13:33 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-19 15:38:24 -0600

Seen: 1,468 times

Last updated: Jan 19 '16