Compilation errors with g++-8 for OpenCV 4.3.0 with opencv_contrib (xfeatures2d namespace conflict)
I initially created an issue here, but it seems it is the good place here:
System information (version) - OpenCV => 4.3.0 - Opencv_contrib => 4.3.0 - Operating System / Platform => Ubuntu 18.04 - Compiler => g++-8
Detailed description
Compilation errors occured when building OpenCV 4.3.0 with opencv_contrib 4.3.0. The problem is a conflict for type SIFT which is defined into two different namespaces. The code was built with the following options: -DWITH_OPENCL=ON -DWITH_V4L=ON -DOPENCV_EXTRA_MODULES_PATH=../../../src/OpenCV4/opencv_contrib/modules -DBUILD_EXAMPLES=ON
Note: I built it using catkin (from ROS) in a catkin isolated workspace as plain C-Make, so the same erros should occur without catkin build (which simply call make command for plain-cmake projects)
Errors occured when compiling generated files:
modules/python_bindings_generator/pyopencv_generated_types_content.h
In file included from /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/python/src2/cv2.cpp:1904: /home/gus/ressac/catkin_isolated_ws/build_isolated/OpenCV4/install/modules/python_bindings_generator/pyopencv_generated_types_content.h: In function ‘PyObject* pyopencv_cv_xfeatures2d_xfeatures2d_SIFT_create_static(PyObject, PyObject, PyObject)’: /home/gus/ressac/catkin_isolated_ws/build_isolated/OpenCV4/install/modules/python_bindings_generator/pyopencv_generated_types_content.h:74083:13: error: template argument 1 is invalid Ptr<sift> retval; ^ /home/gus/ressac/catkin_isolated_ws/build_isolated/OpenCV4/install/modules/python_bindings_generator/pyopencv_generated_types_content.h:74093:56: error: invalid user-defined conversion from ‘cv::Ptr<cv::xfeatures2d::sift>’ to ‘int’ [-fpermissive] ERRWRAP2(retval = cv::xfeatures2d::SIFT::create(nfeatures, nOctaveLayers, contrastThreshold, edgeThreshold, sigma)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/python/src2/cv2.cpp:159:5: note: in definition of macro ‘ERRWRAP2’ expr; \ ^~~~ In file included from /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/core/include/opencv2/core/cvstd.hpp:81, from /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/core/include/opencv2/core/utils/configuration.private.hpp:8, from /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/python/src2/cv2.cpp:35: /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/core/include/opencv2/core/cvstd_wrapper.hpp:129:12: note: candidate is: ‘cv::Ptr<t>::operator T() const [with T = cv::xfeatures2d::SIFT]’ <near match=""> inline operator T* () const { return std::shared_ptr<t>::get(); } ^~~~~~~~ /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/core/include/opencv2/core/cvstd_wrapper.hpp:129:12: note: no known conversion from ‘cv::xfeatures2d::SIFT’ to ‘int’ In file included from /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/python/src2/cv2.cpp:1904: /home/gus/ressac/catkin_isolated_ws/build_isolated/OpenCV4/install/modules/python_bindings_generator/pyopencv_generated_types_content.h: In function ‘PyObject pyopencv_cv_xfeatures2d_xfeatures2d_SIFT_create_static(PyObject, PyObject, PyObject)’: /home/gus/ressac/catkin_isolated_ws/build_isolated/OpenCV4/install/modules/python_bindings_generator/pyopencv_generated_types_content.h:74083:13: error: template argument 1 is invalid Ptr<sift> retval; ^ /home/gus/ressac/catkin_isolated_ws/build_isolated/OpenCV4/install/modules/python_bindings_generator/pyopencv_generated_types_content.h:74093:56: error: invalid user-defined conversion from ‘cv::Ptr<cv::xfeatures2d::sift>’ to ‘int’ [-fpermissive] ERRWRAP2(retval = cv::xfeatures2d::SIFT::create(nfeatures, nOctaveLayers, contrastThreshold, edgeThreshold, sigma)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/python/src2/cv2.cpp:159:5: note: in definition of macro ‘ERRWRAP2’ expr; \ ^~~~ In file included from /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/core/include/opencv2/core/cvstd.hpp:81, from /home/gus/ressac/catkin_isolated_ws/src/OpenCV4/modules/core/include/opencv2/core/utils/configuration.private.hpp ...
SIFT was moved from contrib/xfeatures2d to the main opencv repo with 4.3.0
if you still have the xfeatures2d version, you must have conflicting main/contrib versions, NOT 4.3.0 for both, please check again. also please clean your build folder and start all over with cmake
also, iirc ROS comes with its own (usually outdated) opencv version which will get in the way, so please try to avoid all things ROS for now
also, "patching" machine-generated code like
pyopencv_generated_funcs.h
is quite useless, it may be overwritten at any momentOk thanks.
Patches were just a "readable" way to let you know in the post the change I did to solve the problem
I know ROS uses an outdated version of OpenCV, that's why I wanted to build the 4.3.0 version in order to use of new features/functions in some of my ROS nodes.