[英]How to correctly link opencv3 under ROS Indigo (using CMake)?
Am not being able to link opencv3 that I installed myself separately from ros. 我无法将我自己安装的opencv3与ros分开。 Am getting this error
我收到这个错误
../devel/lib/libirTest.so: undefined reference to `cv::ORB::create(int, float, int, int, int, int, int, int, int)'
../devel/lib/libirTest.so: undefined reference to `cv::calcOpticalFlowPyrLK(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputOutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::Size_<int>, int, cv::TermCriteria, int, double)'
HOWEVER, am able to succefully compile outside ROS; 但是,能够成功编译外部ROS; that is, using the similar package without ROS.... Here is the CMake file am using under ROS (that does not work)
也就是说,使用没有ROS的类似包....这是在ROS下使用的CMake文件(不起作用)
cmake_minimum_required(VERSION 2.8.3)
project(my_test_pkg)
SET(SRC ${CMAKE_CURRENT_SOURCE_DIR}/src)
find_package(catkin REQUIRED COMPONENTS
cv_bridge
image_transport
roscpp
rospy
std_msgs
message_generation
genmsg
)
find_package(nodelet REQUIRED)
################################################
## Declare ROS messages, services and actions ##
################################################
add_message_files(
FILES
velocity_trsl.msg
)
generate_messages(
DEPENDENCIES
std_msgs
)
catkin_package(
CATKIN_DEPENDS message_generation cv_bridge image_transport roscpp rospy std_msgs
)
###########
## Build ##
###########
include_directories(
${catkin_INCLUDE_DIRS}
)
#***********************
#****** GSL
#***********************
find_package( PkgConfig REQUIRED)
pkg_check_modules( gsl REQUIRED gsl )
#***********************
#****** Boost
#***********************
SET (BOOST_DIR "/home/polar/soft/lib/boost/boost_1_61_0")
FIND_PACKAGE(Boost 1.61.0 REQUIRED thread)
if (NOT Boost_FOUND)
message(FATAL_ERROR " Fatal error: Boost (version >= 1.55) required.")
else()
message(STATUS "Setting up BOOST")
message(STATUS " Includes - ${Boost_INCLUDE_DIRS}")
message(STATUS " Library - ${Boost_LIBRARY_DIRS}")
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif (NOT Boost_FOUND)
#***********************
#****** OpenCV
#***********************
find_package( OpenCV 3.1.0 REQUIRED )
find_package( OpenCV 3.1.0 REQUIRED PATHS /home/polar/soft/lib/opencv/opencv-3.1.0/cmake)
if (NOT OpenCV_FOUND)
message(FATAL_ERROR "*****!!!!! opencv NOT found.")
endif (NOT OpenCV_FOUND)
#****************************************
include_directories(${SRC}/calculus)
SET(MY_LIB
irTest
)
# ALL EXEC FILES...
SET(EXE_TESTER
tester1
)
add_executable(tester1 ${CMAKE_CURRENT_SOURCE_DIR}/exe-main-files-stdl/testdir/tester1.cpp )
SET(FILES_2_RUN
${EXE_TESTER}
)
#--------------------------
foreach(file2link ${FILES_2_RUN})
target_link_libraries(${file2link}
${catkin_LIBRARIES}
${Boost_LIBRARIES}
${gsl_LIBRARIES}
${OpenCV_LIBRARIES}
${OpenCV_LIBS}
${MY_LIB}
)
add_dependencies(${file2link} my_test_pkg_generate_messages_cpp)# newlly added for messages!!
endforeach(file2link)
add_subdirectory(src)
Should it be a conflict between the opencv version am using and that (v2.4) used by ROS? 它应该是opencv版本使用和ROS使用的(v2.4)之间的冲突吗? Perhaps cv_bridge or image_transport are creating this problem... (???) I even deleted build/ and devel/ and tried to compile again, but always the same problem..... I never spent such long time than with this problem...
也许cv_bridge或image_transport正在创建这个问题...(???)我甚至删除了build /和devel /并尝试再次编译,但总是同样的问题.....我从来没有花这么长时间比这个问题...
I was able to link a ROS project with opencv 3.1 under ROS indigo. 我能够在ROS indigo下将ROS项目与opencv 3.1链接起来。 Note that opencv 2.4 is still the default version under indigo, so this gets tricky and thus YMMV.
请注意,opencv 2.4仍然是indigo下的默认版本,所以这很棘手,因此YMMV。
First, you need to have ros-indigo-opencv3
package installed. 首先,您需要安装
ros-indigo-opencv3
软件包。 It's possible that a from-source path can work by specifying the path manually as you have done, but I haven't tested it. 通过手动指定路径,源源路径可能会起作用,但我还没有测试过。
In your CMakeLists.txt make sure you include ${OpenCV_INCLUDE_DIRS}
and link with ${OpenCV_LIBRARIES}
: 在您的CMakeLists.txt中,请确保包含
${OpenCV_INCLUDE_DIRS}
并链接到${OpenCV_LIBRARIES}
:
find_package(OpenCV 3 REQUIRED)
include_directories(
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
add_library(your_node src/your_node.cpp)
target_link_libraries(your_node ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} )
Lastly, because the ros opencv bindings are compiled only for opencv 2.4, you need to clone the vision_opencv repository ( https://github.com/ros-perception/vision_opencv ) into your workspace before compiling. 最后,由于ros opencv绑定仅针对opencv 2.4进行编译,因此您需要在编译之前将vision_opencv存储库( https://github.com/ros-perception/vision_opencv )克隆到工作区中。 This will ensure the bindings link with opencv 3.
这将确保绑定链接与opencv 3。
I am using both Opencv2.4.8
and opencv3.1
with ros indigo
. 我正在使用
Opencv2.4.8
和opencv3.1
与ros indigo
。 The opencv3.1
is installed from source under home directory- /home/xxx/opencv3_install
. opencv3.1
从源目录下的源安装 - /home/xxx/opencv3_install
。
The advantage is that my older package using opencv2.4.8
doesn't need to change any code, because the default opencv version is 2.4.8
. 优点是我使用
opencv2.4.8
旧软件包不需要更改任何代码,因为默认的opencv版本是2.4.8
。
When opencv3.1
is needed, the CMAKE_PREFIX_PATH
should be set to find the lib. 当
opencv3.1
需要,在CMAKE_PREFIX_PATH
应设置为找到的lib。
set(CMAKE_PREFIX_PATH "/home/xxx/opencv3_install")
find_package(OpenCV 3.1 REQUIRED)
set(OpenCV_INCLUDE_DIRS "/home/xxx/opencv3_install/include")
Additionally, the cv_bridge
need to be recompiled after installing opencv3.1
. 此外,
cv_bridge
需要在安装后重新编译opencv3.1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.