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

标签 c++ cmake ros

我希望有人能帮助我。

为了在 Ubuntu 上构建我的项目,我有一个简单的 CMakeLists.txt。我正在使用 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 到 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})

最佳答案

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

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

那会有帮助。

关于c++ - 不确定如何将 opencv 库添加到 CMakeLists.txt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6608697/

相关文章:

c++ - 将输入输入到 vector<int> 的优雅解决方案

c++ - 带有 Visual Studio 和 Unicode 源代码的 WxWidgets

boost - 如何在 CMakeLists.txt 中添加 Boost 库?

python - CMAKE 3.9.3 找不到 Boost1.65.1 Boost_Python

c++ - 你能解释一下这个语法吗:ros::Rate loop_rate(10);

c++ - 成对访问 map 中的值

c++ - 用于最小值、最大值、中值、平均值的 OpenMp C++ 算法

c# - Visual Studio 2019 的 CSC 警告 CS1668

c++ - 标识符 "__builtin_expect"未定义(在 win 教程-谈话者示例中的 ROS 期间)

opencv - 使用 imgmsg_to_cv2 [python] 在 ROS 中获取灰度深度图像