开发者

Not sure how to add opencv library to CMakeLists.txt

I hope someone can help me.

I have a simple CMakeLists.txt in order to build my project on Ubuntu. I'm using CMake 2.8.1 and at the moment this is the code:

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
     开发者_Python百科                             ${OpenCV_INCLUDE_DIRS})

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

I need to add opencv libraries on my project. I have added them but i can't still get my code to work. its keeps posting me this error:

‘struct MyOpenNIExample::ImgContext’ has no member named ‘image’

there is a few of them.

after i added find_package(OpenCV REQUIRED to the CMakeLists.txt, i get this error

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

what shld i do? I am using Apple and using Ubuntu 10.04.

Since i need

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

i added

      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" 

the include files above are included in the vision_opencv in ROS. so to include it, add the opencv dependency in the manifest file.

That would help.


  1. Get FindOpenCV.cmake from above link and put it anywhere on your computer.
  2. After cmake_minimum_required add line set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} [path to folder where you put FindOpenCV.cmake])
  3. Add find_package(OpenCV) to your CMakeLists.txt
  4. On this step you can check for OpenCV_FOUND and other OpenCV variables in your CMakeLists.txt
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜