我的Ubuntu 14.04默认安装了OpenCV 2.4.8,我还有cv::fisheye
类所需的手工构建的OpenCV 2.4.11,我使用cmake
生成这些类来生成可执行文件。问题是我使用ROS,默认为2.4.8,但我需要链接2.4.11。我所拥有的黑客是:
find_package(OpenCV REQUIRED)
# Needed to force OpenCV 2.4 to link with 2.4.11
#message("Initial value for ${OpenCV_VERSION}: ${OpenCV_LIBS}")
if(OpenCV_VERSION VERSION_LESS "3.0")
set(OpenCV_VERSIONED_LIBS "")
macro(set_opencv_version version)
foreach( LIB_FILE ${ARGN} )
set(OpenCV_VERSIONED_LIBS ${OpenCV_VERSIONED_LIBS} :lib${LIB_FILE}.so.${version})
endforeach()
endmacro()
set_opencv_version("2.4.11" ${OpenCV_LIBS})
else()
set(OpenCV_VERSIONED_LIBS ${OpenCV_LIBS})
endif()
#message("Updated value: ${OpenCV_VERSIONED_LIBS}")
target_link_libraries(my_fisheye_application
${OpenCV_VERSIONED_LIBS}
${catkin_LIBRARIES}
cv_bridge # This by default pulls in OpenCV 2.4.8 libraries
# ...etc...
)
由于这个脚本需要在不同的机器上运行,并且使用OpenCV 3.0以及2.4.11,我无法对使用中的目录做出任何假设。有更好的方法吗?
答案 0 :(得分:3)
如果要强制CMake(FindOpenCV模块)搜索与安装的软件包/系统不同的OpenCV库,
您需要将OpenCV_ROOT_DIR
变量设置为要使用的OpenCV树的基目录。
另外,因为您至少需要OpenCV库的特定最低版本,所以最好在find_package()函数中声明它,如下所示:
find_package(OpenCV 2.4.11 REQUIRED)