0
votes

I want to build my project (in ROS) using opencv 2.4

I installed ros-kinetic version, and opencv3 package (by default, via libopencv-dev ros-kinetic-opencv3 , only opencv3 is available). For the purpose of my project i need opencv-2.4 version. I try with several ways (via CMakelists.txt of my project etc) to link with my custom built opencv (in usr/local/include) but with no success.

My project always links with the installed ros opencv (/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2)

I got the following errors

    /usr/include/c++/5/bits/stl_vector.h:913:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Eigen::Matrix<double, 3, 1>; _Alloc = Eigen::aligned_allocator_indirection<Eigen::Matrix<double, 3, 1> >; std::vector<_Tp, _Alloc>::value_type = Eigen::Matrix<double, 3, 1>]
       push_back(const value_type& __x)
       ^
/usr/include/c++/5/bits/stl_vector.h:913:7: note:   no known conversion for argument 1 from ‘cv::Point {aka cv::Point_<int>}’ to ‘const value_type& {aka const Eigen::Matrix<double, 3, 1>&}’
/home/user1/user1/catkin_ws/src/rgbd_calibration/src/rgbd_calibration/calibration_test.cpp:1107:79: error: no matching function for call to ‘std::vector<Eigen::Matrix<double, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<double, 3, 1> > >::push_back(cv::Point)’
           points.push_back(cv::Point(tmp_corners[35].x(), tmp_corners[35].y()));
                                                                               ^
In file included from /usr/include/c++/5/vector:64:0,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/base/matrix.h:32,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/base/point_matrix.h:32,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/objects/globals.h:32,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/objects/base_object.h:33,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/objects/sensor.h:21,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/color/sensor.h:32,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/pinhole/sensor.h:32,
                 from /home/user1/user1/catkin_ws/src/rgbd_calibration/include/rgbd_calibration/calibration_test.h:21,
                 from /home/user1/user1/catkin_ws/src/rgbd_calibration/src/rgbd_calibration/calibration_test.cpp:18:
/usr/include/c++/5/bits/stl_vector.h:913:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Eigen::Matrix<double, 3, 1>; _Alloc = Eigen::aligned_allocator_indirection<Eigen::Matrix<double, 3, 1> >; std::vector<_Tp, _Alloc>::value_type = Eigen::Matrix<double, 3, 1>]
       push_back(const value_type& __x)
       ^
/usr/include/c++/5/bits/stl_vector.h:913:7: note:   no known conversion for argument 1 from ‘cv::Point {aka cv::Point_<int>}’ to ‘const value_type& {aka const Eigen::Matrix<double, 3, 1>&}’
/home/user1/user1/catkin_ws/src/rgbd_calibration/src/rgbd_calibration/calibration_test.cpp:1108:79: error: no matching function for call to ‘std::vector<Eigen::Matrix<double, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<double, 3, 1> > >::push_back(cv::Point)’
           points.push_back(cv::Point(tmp_corners[30].x(), tmp_corners[30].y()));
                                                                               ^
In file included from /usr/include/c++/5/vector:64:0,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/base/matrix.h:32,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/base/point_matrix.h:32,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/objects/globals.h:32,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/objects/base_object.h:33,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/objects/sensor.h:21,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/color/sensor.h:32,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/pinhole/sensor.h:32,
                 from /home/user1/user1/catkin_ws/src/rgbd_calibration/include/rgbd_calibration/calibration_test.h:21,
                 from /home/user1/user1/catkin_ws/src/rgbd_calibration/src/rgbd_calibration/calibration_test.cpp:18:
/usr/include/c++/5/bits/stl_vector.h:913:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = Eigen::Matrix<double, 3, 1>; _Alloc = Eigen::aligned_allocator_indirection<Eigen::Matrix<double, 3, 1> >; std::vector<_Tp, _Alloc>::value_type = Eigen::Matrix<double, 3, 1>]
       push_back(const value_type& __x)
       ^
/usr/include/c++/5/bits/stl_vector.h:913:7: note:   no known conversion for argument 1 from ‘cv::Point {aka cv::Point_<int>}’ to ‘const value_type& {aka const Eigen::Matrix<double, 3, 1>&}’
/home/user1/user1/catkin_ws/src/rgbd_calibration/src/rgbd_calibration/calibration_test.cpp:1110:113: error: no matching function for call to ‘fillConvexPoly(cv::Mat&, std::vector<Eigen::Matrix<double, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<double, 3, 1> > >&, cv::Scalar)’
           cv::fillConvexPoly(tmp_image, points, cv::Scalar(c == 0 ? 128 : 0, c == 1 ? 128 : 0, c == 2 ? 128 : 0));
                                                                                                                 ^
In file included from /opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/imgproc/imgproc.hpp:48:0,
                 from /opt/ros/kinetic/include/image_geometry/pinhole_camera_model.h:6,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/pinhole/camera_model.h:32,
                 from /home/user1/user1/catkin_ws/src/calibration_toolkit/calibration_common/include/calibration_common/pinhole/sensor.h:33,
                 from /home/user1/user1/catkin_ws/src/rgbd_calibration/include/rgbd_calibration/calibration_test.h:21,
                 from /home/user1/user1/catkin_ws/src/rgbd_calibration/src/rgbd_calibration/calibration_test.cpp:18:
/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/imgproc.hpp:4452:17: note: candidate: void cv::fillConvexPoly(cv::Mat&, const Point*, int, const Scalar&, int, int)
 CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts,
                 ^
/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/imgproc.hpp:4452:17: note:   candidate expects 6 arguments, 3 provided
/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/imgproc.hpp:4469:19: note: candidate: void cv::fillConvexPoly(cv::InputOutputArray, cv::InputArray, const Scalar&, int, int)
 CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points,
                   ^
/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2/imgproc.hpp:4469:19: note:   no known conversion for argument 2 from ‘std::vector<Eigen::Matrix<double, 3, 1>, Eigen::aligned_allocator<Eigen::Matrix<double, 3, 1> > >’ to ‘cv::InputArray {aka const cv::_InputArray&}’
rgbd_calibration/CMakeFiles/test_calibration.dir/build.make:62: recipe for target 'rgbd_calibration/CMakeFiles/test_calibration.dir/src/rgbd_calibration/test_node.cpp.o' failed
make[2]: *** [rgbd_calibration/CMakeFiles/test_calibration.dir/src/rgbd_calibration/test_node.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
rgbd_calibration/CMakeFiles/test_calibration.dir/build.make:86: recipe for target 'rgbd_calibration/CMakeFiles/test_calibration.dir/src/rgbd_calibration/calibration_test.cpp.o' failed
make[2]: *** [rgbd_calibration/CMakeFiles/test_calibration.dir/src/rgbd_calibration/calibration_test.cpp.o] Error 1
CMakeFiles/Makefile2:3448: recipe for target 'rgbd_calibration/CMakeFiles/test_calibration.dir/all' failed
make[1]: *** [rgbd_calibration/CMakeFiles/test_calibration.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 98%] Linking CXX executable /home/user1/user1/catkin_ws/devel/lib/rgbd_calibration/rgbd_offline_calibration
[ 98%] Built target rgbd_offline_calibration
Makefile:138: recipe for target 'all' failed

I tried several things, like inserting find_package(OpenCV 2.4.12 REQUIRED NO_MODULE #Should be optional, tells CMake to use config mode PATHS /usr/local # Tells CMake to look here NO_DEFAULT_PATH #and don't look anywhere else ) in CMakeLists.txt of the project but still the same issue.

Is there a safe way to explicitly link with my custom built opencv?

1

1 Answers

0
votes

There are a few possible answers to your problem. Firstly, run pkg-config --modversion opencv, to make sure that the version you are asking for exists. Then you could try to do the following:

1) In your CMakeLists.txt: find_package(OpenCV REQUIRED PATHS path/to/opencv/opencv/opencv-2.4.12/cmake)

2) In the beginning of the same file, add the following:

set(OpenCV_INCLUDE_DIRS
  /usr/local/include
  /usr/local/include/opencv2
)

set(OpenCV_LIB_DIR
  /usr/local/lib
)

3) Before running the catkin build, run

export CMAKE_PREFIX_PATH=/usr/local:$CMAKE_PREFIX_PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

4) Beware! Everytime before running catkin build, always perform catkin clean. There is always the chance of not deleting previous configuration and not being able to detect the new OpenCV version that you ask for.

One of them, or a combination of them may work.