不确定如何将opencv库添加到CMakeLists.txt

时间:2011-07-07 09:51:10

标签: c++ cmake ros

我希望有人可以帮助我。

我有一个简单的CMakeLists.txt,以便在Ubuntu上构建我的项目。我正在使用CMake 2.8.1,目前这是代码:

cmake_minimum_required(VERSION 2.4.6)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /home/user/workspace)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug          : w/ debug symbols, w/o optimization
#  Release        : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)

rosbuild_init()
find_package(OpenCV 2) 

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(example examples/example.cpp)
#target_link_libraries(example ${PROJECT_NAME})

include_directories(${CMAKE_SOURCE_DIR}/include
                                  ${OpenCV_INCLUDE_DIRS})

rosbuild_add_executable(RosPub src / paste.cpp) target_link_libraries(RosPub openni_driver usb-1.0 $ {OpenCV_LIBS})

我需要在我的项目中添加opencv库。我添加了它们,但我仍然无法让我的代码工作。它不断向我发布这个错误:

'struct MyOpenNIExample :: ImgContext'没有名为'image'的成员

有一些。

我添加了find_package(OpenCV REQUIRED到CMakeLists.txt,  我收到此错误

Adjust CMAKE_MODULE_PATH to find FindOpenCV.cmake or set OpenCV_DIR to the
   directory containing a CMake configuration file for OpenCV.  The file will
   have one of the following names:

     OpenCVConfig.cmake
     opencv-config.cmake
我该怎么做?我正在使用Apple并使用Ubuntu 10.04。

因为我需要

#include "opencv2\opencv.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"

我添加了

      find_package(OpenCV 2), 
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /home/user/workspace) and 


    include_directories(${CMAKE_SOURCE_DIR}/include
                                      ${OpenCV_INCLUDE_DIRS})
    target_link_libraries (RosPub openni_driver usb-1.0 ${OpenCV_LIBS})

2 个答案:

答案 0 :(得分:1)

#include "opencv2\opencv.hpp"
#include "opencv2\highgui\highgui.hpp" 
#include "opencv2\imgproc\imgproc.hpp" 

上面的include文件包含在ROS的vision_opencv中。所以要包含它,在清单文件中添加opencv依赖项。

那会有所帮助。

答案 1 :(得分:0)

  1. 从上面的链接获取FindOpenCV.cmake并将其放在计算机上的任何位置。
  2. 在cmake_minimum_required之后添加行集(CMAKE_MODULE_PATH $ {CMAKE_MODULE_PATH} [放置FindOpenCV.cmake的文件夹的路径])
  3. 将find_package(OpenCV)添加到您的CMakeLists.txt
  4. 在此步骤中,您可以在CMakeLists.txt中检查OpenCV_FOUND和其他OpenCV变量