0

Rosanswers logo

Hi,

I installed today the VS Code ROS extension, in order to try to debug my code for a ROS node for RGB-D Odometry using OpenCV, which is generating segmentation error (core dumped) when running. I made several changes followed by catkin_make yesterday, until I decided to try a debugger. The only change I made today was to config the ROS extension, as per this tutorial.

After some unsuccessful trials to find the issue with the debugger, I tried to make one change in my code, and build again. And I am now having the following error:

-- +++ processing catkin package: 'test_opencv_pkg'
-- ==> add_subdirectory(test_opencv_pkg)
-- Could NOT find OpenCV (missing: OpenCV_DIR)
-- Could not find the required component 'OpenCV'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
  Could not find a package configuration file provided by "OpenCV" with any
  of the following names:
OpenCVConfig.cmake
opencv-config.cmake

Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set "OpenCV_DIR" to a directory containing one of the above files. If "OpenCV" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): test_opencv_pkg/CMakeLists.txt:5 (find_package)

-- Configuring incomplete, errors occurred! ... Makefile:754: recipe for target 'cmake_check_build_system' failed make: *** [cmake_check_build_system] Error 1 Invoking "make cmake_check_build_system" failed

I could not understand very well by the error log what can be done for fixing it. Appreciate if some can help to fix it.

Thanks.

Edit:

Adding CMakeLists.txt from my OpenCV Package. I could also notice that after trying build/debug with the mentioned VS Code stuff, I now have lots of new folders/files inside the package folder, such as "catkin", "catkin_generated", "test_results", "CMakeCache.txt", "CTestConfiguration.ini"...

cmake_minimum_required(VERSION 3.0.2)

project(test_opencv_pkg)

find_package(catkin REQUIRED COMPONENTS cv_bridge rospy roscpp image_transport sensor_msgs std_msgs OpenCV ) if (OpenCV_FOUND) message("Find your opencv succesfully") else() message("Cannot find your opencv, please specifiy your opencv path") set(OpenCV_INCLUDE_DIRS /opt/opencv/release/include) set(OpenCV_LIBS opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_calib3d) link_directories(/opt/opencv/release/lib) endif()

catkin_package()

include_directories(${catkin_INCLUDE_DIRS}

)

add_executable(opencv_node src/cv_test.cpp) add_executable(optflow src/optflow.cpp) add_executable(harris1 src/harris1.cpp) add_executable(harris2 src/harris1.cpp) add_executable(opencv_node2 src/cv_test2.cpp) add_executable(rgbd_odometry src/rgbd_odo.cpp)

target_link_libraries(opencv_node ${catkin_LIBRARIES} ) target_link_libraries(opencv_node2 ${catkin_LIBRARIES} )

target_link_libraries(rgbd_odometry ${catkin_LIBRARIES} ) target_link_libraries(optflow ${catkin_LIBRARIES} ) target_link_libraries(harris1 ${catkin_LIBRARIES} )

target_link_libraries(harris2 ${catkin_LIBRARIES} )


Originally posted by msantos on ROS Answers with karma: 21 on 2021-08-27

Post score: 0

1 Answers1

0

Rosanswers logo

I have done fhe following steps and could manage to solve the issue, but not sure if all were needed at all:

  • Removed the ROS, and CMake extensions from VS Code.
  • Removed and reinstalled CMake form my System.
  • Add the following lines before the find_package() in the CMakeLists.txt:

-set(OpenCV_DIR /opt/opencv/release/).

-set(OpenCV_INCLUDE_DIRS /opt/opencv/release/include).

-set(OpenCV_LIBS opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_calib3d).

Then, I could manage to compile again by using catkin_make.


Originally posted by msantos with karma: 21 on 2021-08-29

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by gvdhoorn on 2021-08-30:
While it's possible to use newer OpenCV versions with a ROS release which originally wasn't paired with it, you have to take care of some things. In essence: you now have to build all packages which (transitively) depend on OpenCV yourself.

See #q289264 for a Q&A which discusses PCL, but the same workflow would be needed for OpenCV.

Setting some OpenCV_* CMake variables will not be sufficient to guarantee a stable system.

Comment by msantos on 2021-09-01:
Is there some how to know the most suitable OpenCV version for ROS Melodic/Ubuntu 18 and fix it? I have installed 3.2.0, as mentioned in the comment, and I understood this one should be suitable... however, I am having kind of the same error message (using a debugging trace in my code) as #q352756.