Problems integrating OpenCV with ROS Indigo
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?
Please use the "Preformatted Text" button (marked "101010") to format your code sample so that it is readable.
First post, it's been edited now.