Robotics StackExchange | Archived questions

opencv2 and opencv3 wrong inclusion with cv_bridge

Hi all, I'm trying to compile a node which uses internally the applyColorMap function, which is defined inside contrib in OpenCV2 and it is defined in core in OpenCV3.

I have both installed, OpenCV2 with the ros package in /usr/include, and OpenCV3 manually installed in /usr/local/include.

To force the use of OpenCV2 set the following CMakeList.txt:

cmake_minimum_required(VERSION 2.8.3)
project(height_publisher)

find_package(catkin REQUIRED COMPONENTS roscpp nav_msgs cv_bridge
                                        image_transport pcl_conversions
                                        sensor_msgs tf tf_conversions)

include_directories(${catkin_INCLUDE_DIRS})

set(CMAKE_BUILD_TYPE "Release")

find_package(OpenCV 2.4 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
message("-- OpenCV version: ${OpenCV_VERSION}")
message("-- OpenCV include dirs: ${OpenCV_INCLUDE_DIRS}")
message("-- catkin include dirs: ${catkin_INCLUDE_DIRS}")


find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})

catkin_package()

include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(height_publisher_node src/HeightPublisher.cpp)
target_link_libraries(height_publisher_node ${OpenCV_LIBS} ${PCL_LIBRARIES}
                                            ${catkin_LIBRARIES})

The message correctly says that we look for OpenCV in /usr/include and there is no reference to /usr/local/include anywhere

The only include that has something to do with OpenCV is the following:

#include <cv_bridge/cv_bridge.h>

If I have installed OpenCV2 only, the compiler complains a missing definition of applyColorMap. I can solve that by adding in the code the following include:

#include <opencv2/contrib/contrib.hpp>

But if I install OpenCV3, it complains about a redefinition of classes and redeclaration of constants. When I remove the line, the project compiles normally. But when I deploy the code on a machine without OpenCV3, it complains about the missing include.

Adding the following:

#if CV_MAJOR_VERSION == 2
#include <opencv2/contrib/contrib.hpp>
#endif

does not help, because the detected major version is 2, although somewhere in cv_bridge I guess, is using the OpenCV3, as indicated by the following error line:

In file included from /usr/local/include/opencv2/core/core.hpp:48:0,
                 from /usr/include/opencv2/contrib/contrib.hpp:46,
                 from /home/mcamurri/git/dls-perception/height_publisher/src/HeightPublisher.h:3,
                 from /home/mcamurri/git/dls-perception/height_publisher/src/HeightPublisher.cpp:1:
/usr/local/include/opencv2/core.hpp:2422:18: error: previous definition of ‘class cv::LDA’
 class CV_EXPORTS LDA

Asked by mark_vision on 2016-07-28 01:57:30 UTC

Comments

Answers