我想使用opencv 2.4构建项目(在ROS中)
我安装了ros-kinetic版本和opencv3软件包(默认情况下,通过libopencv-dev ros-kinetic-opencv3,仅opencv3可用)。
对于我的项目,我需要opencv-2.4版本。
我尝试了几种方法(通过项目的CMakelists.txt
等)来链接自定义构建的opencv(在usr/local/include
中),但没有成功。
我的项目始终与已安装的ros opencv (/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv2)
我遇到以下错误
/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
我尝试了几件事,例如插入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
)
在项目的CMakeLists.txt
中,但仍然是同一问题。
有没有一种安全的方法可以显式链接到我自定义的内置opencv?
答案 0 :(得分:0)
对于您的问题,有一些可能的答案。
首先,运行Optional
,以确保所需的版本存在。
然后,您可以尝试执行以下操作:
1)在您的CMakeLists.txt中:pkg-config --modversion opencv
2)在同一文件的开头,添加以下内容:
find_package(OpenCV REQUIRED PATHS path/to/opencv/opencv/opencv-2.4.12/cmake)
3)在运行catkin构建之前,运行
set(OpenCV_INCLUDE_DIRS
/usr/local/include
/usr/local/include/opencv2
)
set(OpenCV_LIB_DIR
/usr/local/lib
)
4)当心!每次在运行export CMAKE_PREFIX_PATH=/usr/local:$CMAKE_PREFIX_PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
之前,请始终执行catkin build
。
总是有可能不删除以前的配置,也无法检测到您要求的新OpenCV版本。
其中一个或它们的组合可能起作用。