George England
George England

Reputation: 11

How to use OpenCV 4 with ROS?

I'm trying to run ROS Melodic with OpenCV 4.2.0 on windows What is wrong with my CMakeLists? I have added OpenCV to my system path, but Catkin_make always gives this error:

Could not find a configuration file for package "OpenCV" that is compatible
  with requested version "4.2.0".
  The following configuration files were considered but not accepted:
    C:/opt/rosdeps/x64/CMake/OpenCVConfig.cmake, version: 3.4.1

The version it finds is the OpenCV shipped with ROS melodic distribution. How do I change where CMake searches?

This is my CMake:

cmake_minimum_required(VERSION 2.8.3)
project(nav_ross)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  message_generation
  cv_bridge
  image_transport
  pcl_ros
  sensor_msgs
  visualization_msgs
  dynamic_reconfigure
  geometry_msgs
)

find_package(OpenCV 4.2.0 REQUIRED)

add_message_files(
   FILES
   nav_msg.msg
 )

 generate_messages(
   DEPENDENCIES
   std_msgs
   visualization_msgs
   geometry_msgs
 )

 generate_dynamic_reconfigure_options(
    cfg/post-process-config.cfg
 )

catkin_package(
  CATKIN_DEPENDS roscpp rospy std_msgs message_runtime cv_bridge image_transport pcl_ros sensor_msgs visualization_msgs geometry_msgs
)

include_directories(
  ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
  ../../cpp
cfg/cpp/nav_ross
)

add_library(iasdk_static STATIC ../../cpp/radarclient.cpp ../../cpp/tcpradarclient.cpp ../../cpp/tcpsocket.cpp ../../cpp/timer.cpp ../../cpp/threadedclass.cpp)

add_executable(Movement-Detector Movement-Detector.cpp)
target_link_libraries(Movement-Detector ${catkin_LIBRARIES} ${OpenCV_LIBS})
add_dependencies(Movement-Detector nav_ross_generate_messages_cpp)

add_executable(talker1 talker1.cpp)
target_link_libraries(talker1 ${catkin_LIBRARIES} ${OpenCV_LIBS} iasdk_static)
add_dependencies(talker1 nav_ross_generate_messages_cpp ${devel2_pkg_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

add_executable(Mobile_Platform Mobile_Platform.cpp)
target_link_libraries(Mobile_Platform ${catkin_LIBRARIES} ${OpenCV_LIBS} iasdk_static)
add_dependencies(Mobile_Platform nav_ross_generate_messages_cpp ${devel2_pkg_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

Upvotes: 1

Views: 1182

Answers (1)

hashtag
hashtag

Reputation: 124

Try to tell CMake where is your OpenCV, maybe it looks for the first one, and if found forces to use.

find_package(OpenCV REQUIRED PATHS Path/to/OpenCV NO_DEFAULT_PATH) 

Upvotes: 1

Related Questions