From fa92e061b233d6ec0a5f7fd8d379f48f3ceef19a Mon Sep 17 00:00:00 2001 From: Tobias Fischer Date: Mon, 12 Oct 2026 20:49:52 +1000 Subject: [PATCH 1/5] update-snapshot: never downgrade, stay above per-package build numbers - a repository the previous snapshot has ahead of the sync (taken from rosdistro master, or spliced in from it) keeps all its entries: a newer version of one of its packages, or a package the sync drops that master still releases (EasyNav 0.5.0, roboplan 0.7.0, gtsam 4.3.1 in lyrical's 2026-10-05 sync) - the full-rebuild build number also goes above the per-package build numbers it drops, which needn't be on the channel yet (lyrical: 29 collided with them) Co-Authored-By: Claude Opus 5.5 --- .../lyrical/patch/ros2-foxglove-bridge.patch | 25 +- .../patch/ros2-foxglove-bridge.win.patch | 108 +- .../ros2-microstrain-inertial-driver.patch | 94 +- distros/lyrical/patch/ros2-rtabmap.patch | 2941 +---------------- tools/maintenance.py | 70 +- tools/tests/test_bot_commands.py | 19 + 6 files changed, 106 insertions(+), 3151 deletions(-) diff --git a/distros/lyrical/patch/ros2-foxglove-bridge.patch b/distros/lyrical/patch/ros2-foxglove-bridge.patch index 0f0d55c2..6822948e 100644 --- a/distros/lyrical/patch/ros2-foxglove-bridge.patch +++ b/distros/lyrical/patch/ros2-foxglove-bridge.patch @@ -1,39 +1,26 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 6171894..f285973 100644 +index 64c1274..774140a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,18 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarc elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") set(FOXGLOVE_SDK_PLATFORM "x86_64-unknown-linux-gnu") - set(FOXGLOVE_SDK_SHA "4790dad26adaced1a5f81530ed406bab7b60aa202a868eb78cfc04976b9ce6d7") + set(FOXGLOVE_SDK_SHA "1a0d8e03a885f01ae7cfb08dc9076090ba2cf8a15b7f46dda11451e2e2758978") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") + set(FOXGLOVE_SDK_PLATFORM "aarch64-apple-darwin") -+ set(FOXGLOVE_SDK_SHA "70c6e59cf757ac0480912c13cb2c630a3839de34eba428ef717411dae6b1688e") ++ set(FOXGLOVE_SDK_SHA "7b7a86a659a86544f23bed793b7913ad71c3f6c595233bbdb20d3968a3ce5a3a") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(FOXGLOVE_SDK_PLATFORM "x86_64-apple-darwin") -+ set(FOXGLOVE_SDK_SHA "c6092c615523d462a9d3779313b8c033cf923ce30a43dc5305d48fe4f6d26988") ++ set(FOXGLOVE_SDK_SHA "5bae49cac58fb423217e9214452c22faa95b51f5bda7c04469fb1649f8b74ce5") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64") + set(FOXGLOVE_SDK_PLATFORM "aarch64-pc-windows-msvc") -+ set(FOXGLOVE_SDK_SHA "b88abb1bc2c5e230db65cd3d608174f005b3b4563b1c0b2e33db05bc3a2b528b") ++ set(FOXGLOVE_SDK_SHA "8d067b5af329f808142a750e939799bfccb27926ff72b62da54e5280af002d3b") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") + set(FOXGLOVE_SDK_PLATFORM "x86_64-pc-windows-msvc") -+ set(FOXGLOVE_SDK_SHA "ae4ac0f4ab9eb998542a5626cd7870ba011824499fe33fa86936e82ed6502185") ++ set(FOXGLOVE_SDK_SHA "ea4db36121adb0ee61315442ea43603136c6910b4d82814688f507cd6f7fdd3b") else() message(FATAL_ERROR "Unsupported platform/architecture combination: ${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}") endif() -@@ -201,6 +213,12 @@ target_link_libraries(foxglove_bridge_component - rosx_introspection::rosx_introspection - ) - -+if(APPLE) -+ find_library(COREFOUNDATION_FRAMEWORK CoreFoundation REQUIRED) -+ find_library(SECURITY_FRAMEWORK Security REQUIRED) -+ target_link_libraries(foxglove_bridge_component ${COREFOUNDATION_FRAMEWORK} ${SECURITY_FRAMEWORK}) -+endif() -+ - rclcpp_components_register_nodes(foxglove_bridge_component "foxglove_bridge::FoxgloveBridge") - enable_strict_compiler_warnings(foxglove_bridge_component) - set_target_properties(foxglove_bridge_component PROPERTIES diff --git a/src/message_definition_cache.cpp b/src/message_definition_cache.cpp index cf2864e..9124c80 100644 --- a/src/message_definition_cache.cpp diff --git a/distros/lyrical/patch/ros2-foxglove-bridge.win.patch b/distros/lyrical/patch/ros2-foxglove-bridge.win.patch index 575d47e8..feaf5dfb 100644 --- a/distros/lyrical/patch/ros2-foxglove-bridge.win.patch +++ b/distros/lyrical/patch/ros2-foxglove-bridge.win.patch @@ -1,9 +1,8 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index f285973..28652e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -61,7 +61,7 @@ endif() - +@@ -62,7 +62,7 @@ endif() + macro(enable_strict_compiler_warnings target) if (MSVC) - target_compile_options(${target} PRIVATE /WX /W4) @@ -11,106 +10,3 @@ index f285973..28652e5 100644 elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wold-style-cast -Wfloat-equal -Wmost -Wunused-exception-parameter) else() -@@ -121,6 +121,75 @@ FetchContent_Declare( - URL_HASH SHA256=${FOXGLOVE_SDK_SHA} - ) - FetchContent_MakeAvailable(foxglove_sdk) -+if(MSVC) -+ file(READ -+ "${foxglove_sdk_SOURCE_DIR}/include/foxglove/parameter.hpp" -+ _foxglove_parameter_hpp -+ ) -+ string(REPLACE "\r\n" "\n" _foxglove_parameter_hpp "${_foxglove_parameter_hpp}") -+ string(REPLACE -+[=[ -+ [[nodiscard]] bool isArray() const noexcept { -+ if (!this->isArray()) { -+ return false; -+ } -+ try { -+ const auto& arr = this->get(); -+ return std::all_of(arr.begin(), arr.end(), [](const ParameterValueView& elem) noexcept { -+ return elem.is(); -+ }); -+ } catch (...) { -+ return false; -+ } -+ } -+]=] -+[=[ -+ [[nodiscard]] bool isArray() const noexcept { -+ auto value = this->value(); -+ if (!value.has_value() || !value->is()) { -+ return false; -+ } -+ try { -+ const auto& arr = value->get(); -+ return std::all_of(arr.begin(), arr.end(), [](const ParameterValueView& elem) noexcept { -+ return elem.is(); -+ }); -+ } catch (...) { -+ return false; -+ } -+ } -+]=] -+ _foxglove_parameter_hpp -+ "${_foxglove_parameter_hpp}" -+ ) -+ string(REPLACE -+[=[ -+ [[nodiscard]] bool isDict() const noexcept { -+ if (!this->isDict()) { -+ return false; -+ } -+ try { -+ const auto& dict = this->get(); -+ return std::all_of( -+]=] -+[=[ -+ [[nodiscard]] bool isDict() const noexcept { -+ auto value = this->value(); -+ if (!value.has_value() || !value->is()) { -+ return false; -+ } -+ try { -+ const auto& dict = value->get(); -+ return std::all_of( -+]=] -+ _foxglove_parameter_hpp -+ "${_foxglove_parameter_hpp}" -+ ) -+ file(WRITE -+ "${foxglove_sdk_SOURCE_DIR}/include/foxglove/parameter.hpp" -+ "${_foxglove_parameter_hpp}" -+ ) -+endif() - - # The dist's CMake package config defines IMPORTED targets for the prebuilt C libraries - # (foxglove-static, foxglove-shared) and the foxglove_sdk_add_cpp_library() helper, which -@@ -135,6 +204,16 @@ if (FOXGLOVE_BRIDGE_REMOTE_ACCESS) - else() - foxglove_sdk_add_cpp_library(foxglove_cpp_shared TYPE SHARED REMOTE_ACCESS OFF) - endif() -+if(WIN32) -+ target_link_libraries(foxglove_cpp_shared PRIVATE -+ Ws2_32.lib -+ Userenv.lib -+ Ntdll.lib -+ Crypt32.lib -+ Secur32.lib -+ Ncrypt.lib -+ ) -+endif() - set_target_properties(foxglove_cpp_shared PROPERTIES - BUILD_WITH_INSTALL_RPATH TRUE - ) -diff --git a/src/ros2_foxglove_bridge.cpp b/src/ros2_foxglove_bridge.cpp -index b7fc123..fa78588 100644 ---- a/src/ros2_foxglove_bridge.cpp -+++ b/src/ros2_foxglove_bridge.cpp -@@ -1,3 +1,5 @@ -+#define _CRT_SECURE_NO_WARNINGS -+ - #include - #include - #include diff --git a/distros/lyrical/patch/ros2-microstrain-inertial-driver.patch b/distros/lyrical/patch/ros2-microstrain-inertial-driver.patch index cb5214c3..6da1ef58 100644 --- a/distros/lyrical/patch/ros2-microstrain-inertial-driver.patch +++ b/distros/lyrical/patch/ros2-microstrain-inertial-driver.patch @@ -1,5 +1,5 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 35e036fa..db513f68 100644 +index a98cb77..4d92e1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,14 @@ @@ -17,40 +17,8 @@ index 35e036fa..db513f68 100644 # C++ 14 required set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -@@ -187,6 +195,14 @@ set(COMMON_INC_FILES +@@ -236,7 +244,10 @@ target_link_libraries(${LIFECYCLE_NAME} PUBLIC ) - set(COMMON_FILES ${COMMON_SRC_FILES} ${COMMON_INC_FILES}) - -+# ament_target_dependencies() was removed from ament_cmake_target_dependencies; -+# link against each dependency's exported _TARGETS instead. -+macro(link_ament_dependencies target) -+ foreach(_ament_dep ${ARGN}) -+ target_link_libraries(${target} ${${_ament_dep}_TARGETS}) -+ endforeach() -+endmacro() -+ - set(AMENT_COMMON_DEPENDENCIES - rclcpp - rclcpp_lifecycle -@@ -215,9 +231,7 @@ set(NODE_INC_FILES - ) - set(NODE_FILES ${NODE_SRC_FILES} ${NODE_INC_FILES}) - add_executable(${NODE_NAME} ${NODE_FILES} ${COMMON_FILES}) --ament_target_dependencies(${NODE_NAME} -- ${AMENT_COMMON_DEPENDENCIES} --) -+link_ament_dependencies(${NODE_NAME} ${AMENT_COMMON_DEPENDENCIES}) - - # Lifecycle node - set(LIFECYCLE_NAME ${PROJECT_NAME}_lifecycle_node) -@@ -231,12 +245,13 @@ set(LIFECYCLE_INC_FILES - set(LIFECYCLE_FILES ${LIFECYCLE_SRC_FILES} ${LIFECYCLE_INC_FILES}) - add_executable(${LIFECYCLE_NAME} ${LIFECYCLE_FILES} ${COMMON_FILES}) - target_compile_definitions(${LIFECYCLE_NAME} PUBLIC MICROSTRAIN_LIFECYCLE) --ament_target_dependencies(${LIFECYCLE_NAME} -- ${AMENT_COMMON_DEPENDENCIES} --) -+link_ament_dependencies(${LIFECYCLE_NAME} ${AMENT_COMMON_DEPENDENCIES}) # Annoying, but the ROS types don't match up with the MIP types for floats and doubles, so ignore those warnings for now -set_source_files_properties(${COMMON_SRC_DIR}/services.cpp PROPERTIES COMPILE_OPTIONS "-Wno-narrowing") @@ -61,57 +29,8 @@ index 35e036fa..db513f68 100644 # Tell the code the version of the driver that is being build add_definitions(-DMICROSTRAIN_DRIVER_VERSION="${DRIVER_GIT_VERSION}") - -diff --git a/microstrain_inertial_driver_common/include/microstrain_inertial_driver_common/utils/ros_compat.h b/microstrain_inertial_driver_common/include/microstrain_inertial_driver_common/utils/ros_compat.h -index f1fe0879..5b866134 100644 ---- a/microstrain_inertial_driver_common/include/microstrain_inertial_driver_common/utils/ros_compat.h -+++ b/microstrain_inertial_driver_common/include/microstrain_inertial_driver_common/utils/ros_compat.h -@@ -779,7 +779,7 @@ inline TransformListenerType createTransformListener(TransformBufferType buffer) - */ - inline StaticTransformBroadcasterType createStaticTransformBroadcaster(RosNodeType* node) - { -- return std::make_shared(node); -+ return std::make_shared(*node); - } - - /** -@@ -789,7 +789,7 @@ inline StaticTransformBroadcasterType createStaticTransformBroadcaster(RosNodeTy - */ - inline TransformBroadcasterType createTransformBroadcaster(RosNodeType* node) - { -- return std::make_shared(node); -+ return std::make_shared(*node); - } - - /** -diff --git a/src/microstrain_inertial_driver.cpp b/src/microstrain_inertial_driver.cpp -index e679866b..eaea4f15 100644 ---- a/src/microstrain_inertial_driver.cpp -+++ b/src/microstrain_inertial_driver.cpp -@@ -18,7 +18,7 @@ - #include - #include - --#include -+#include - - #include "lifecycle_msgs/msg/transition.hpp" - -diff --git a/src/microstrain_inertial_driver_lifecycle.cpp b/src/microstrain_inertial_driver_lifecycle.cpp -index 1e2a6757..f77bb1d9 100644 ---- a/src/microstrain_inertial_driver_lifecycle.cpp -+++ b/src/microstrain_inertial_driver_lifecycle.cpp -@@ -18,7 +18,7 @@ - #include - #include - --#include -+#include - - #include "lifecycle_msgs/msg/transition.hpp" - diff --git a/include/microstrain_inertial_driver/microstrain_inertial_driver.h b/include/microstrain_inertial_driver/microstrain_inertial_driver.h -index 8e9c2f0e..63edec08 100644 +index 8e9c2f0..63edec0 100644 --- a/include/microstrain_inertial_driver/microstrain_inertial_driver.h +++ b/include/microstrain_inertial_driver/microstrain_inertial_driver.h @@ -14,7 +14,9 @@ @@ -124,9 +43,8 @@ index 8e9c2f0e..63edec08 100644 #include #include #include - diff --git a/include/microstrain_inertial_driver/microstrain_inertial_driver_lifecycle.h b/include/microstrain_inertial_driver/microstrain_inertial_driver_lifecycle.h -index c8ef84e9..931163c2 100644 +index c8ef84e..931163c 100644 --- a/include/microstrain_inertial_driver/microstrain_inertial_driver_lifecycle.h +++ b/include/microstrain_inertial_driver/microstrain_inertial_driver_lifecycle.h @@ -14,7 +14,9 @@ @@ -139,9 +57,8 @@ index c8ef84e9..931163c2 100644 #include #include #include - diff --git a/microstrain_inertial_driver_common/src/utils/mip/ros_connection.cpp b/microstrain_inertial_driver_common/src/utils/mip/ros_connection.cpp -index e2eae441..826b8c24 100644 +index e2eae44..826b8c2 100644 --- a/microstrain_inertial_driver_common/src/utils/mip/ros_connection.cpp +++ b/microstrain_inertial_driver_common/src/utils/mip/ros_connection.cpp @@ -10,6 +10,14 @@ @@ -159,4 +76,3 @@ index e2eae441..826b8c24 100644 #include #include #include - diff --git a/distros/lyrical/patch/ros2-rtabmap.patch b/distros/lyrical/patch/ros2-rtabmap.patch index 4044071f..938a6087 100644 --- a/distros/lyrical/patch/ros2-rtabmap.patch +++ b/distros/lyrical/patch/ros2-rtabmap.patch @@ -1,8 +1,8 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 3fd1801..934ae3c 100644 +index 8b55e49..6bf425e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -113,6 +113,10 @@ if(MSVC) +@@ -114,6 +114,10 @@ if(MSVC) endif() endif() add_compile_options("/bigobj") @@ -13,31 +13,7 @@ index 3fd1801..934ae3c 100644 endif() # [Eclipse] Automatic Discovery of Include directories (Optional, but handy) -@@ -241,7 +245,22 @@ option(BUILD_WITH_RPATH_NOT_RUNPATH "Explicitly disable usage of RUNPATH for the - set(RTABMAP_QT_VERSION AUTO CACHE STRING "Force a specific Qt version.") - set_property(CACHE RTABMAP_QT_VERSION PROPERTY STRINGS AUTO 4 5 6) - --FIND_PACKAGE(OpenCV REQUIRED QUIET COMPONENTS core calib3d imgproc highgui stitching photo video videoio OPTIONAL_COMPONENTS aruco objdetect xfeatures2d nonfree gpu cudafeatures2d cudaoptflow cudaimgproc) -+# OpenCV components. calib3d was split into "calib" + "geometry" in OpenCV 5. -+# These lists are reused below to generate RTABMapConfig.cmake so downstream -+# find_package(RTABMap) requests the same components this build used. -+SET(RTABMAP_OpenCV_COMPONENTS_5 core imgproc highgui stitching photo video videoio calib geometry) -+SET(RTABMAP_OpenCV_COMPONENTS_4 core imgproc highgui stitching photo video videoio calib3d) -+SET(RTABMAP_OpenCV_OPTIONAL_COMPONENTS_5 objdetect xfeatures2d nonfree gpu cudafeatures2d cudaoptflow cudaimgproc) -+SET(RTABMAP_OpenCV_OPTIONAL_COMPONENTS_4 aruco objdetect xfeatures2d nonfree gpu cudafeatures2d cudaoptflow cudaimgproc) -+ -+# Probe OpenCV without a version constraint first, then request the components -+# matching the detected major version. -+FIND_PACKAGE(OpenCV REQUIRED QUIET COMPONENTS core) -+IF(OpenCV_VERSION_MAJOR GREATER 4) -+ FIND_PACKAGE(OpenCV REQUIRED QUIET COMPONENTS ${RTABMAP_OpenCV_COMPONENTS_5} OPTIONAL_COMPONENTS ${RTABMAP_OpenCV_OPTIONAL_COMPONENTS_5}) -+ELSE() -+ FIND_PACKAGE(OpenCV REQUIRED QUIET COMPONENTS ${RTABMAP_OpenCV_COMPONENTS_4} OPTIONAL_COMPONENTS ${RTABMAP_OpenCV_OPTIONAL_COMPONENTS_4}) -+ENDIF() - - IF(WITH_QT) - FIND_PACKAGE(PCL 1.7 REQUIRED QUIET COMPONENTS common io kdtree search surface filters registration sample_consensus segmentation visualization) -@@ -536,8 +555,12 @@ IF(WITH_G2O) +@@ -617,8 +621,12 @@ IF(WITH_G2O) ENDIF(WITH_G2O) IF(WITH_GTSAM) @@ -49,317 +25,14 @@ index 3fd1801..934ae3c 100644 FIND_PACKAGE(GTSAM CONFIG QUIET) + SET(CMAKE_FIND_PACKAGE_PREFER_CONFIG ${_RTABMAP_CMAKE_FIND_PACKAGE_PREFER_CONFIG}) IF(GTSAM_FOUND) - # For issue https://github.com/introlab/rtabmap/pull/1626 - FIND_FILE(GTSAM_NOISE_MODEL_FACTOR_N_FILE gtsam/nonlinear/NoiseModelFactorN.h -@@ -1318,6 +1341,18 @@ install(EXPORT rtabmapTargets - #### - # Setup RTABMapConfig.cmake - #### -+IF(OpenCV_VERSION_MAJOR GREATER 4) -+ SET(CONF_OPENCV_COMPONENTS ${RTABMAP_OpenCV_COMPONENTS_5}) -+ SET(CONF_OPENCV_OPTIONAL_COMPONENTS ${RTABMAP_OpenCV_OPTIONAL_COMPONENTS_5}) -+ELSE() -+ SET(CONF_OPENCV_COMPONENTS ${RTABMAP_OpenCV_COMPONENTS_4}) -+ SET(CONF_OPENCV_OPTIONAL_COMPONENTS ${RTABMAP_OpenCV_OPTIONAL_COMPONENTS_4}) -+ENDIF() -+STRING(REPLACE ";" " " CONF_OPENCV_COMPONENTS "${CONF_OPENCV_COMPONENTS}") -+STRING(REPLACE ";" " " CONF_OPENCV_OPTIONAL_COMPONENTS "${CONF_OPENCV_OPTIONAL_COMPONENTS}") -+# Pin the OpenCV major version so downstream projects find the same major RTAB-Map was -+# built against -+SET(CONF_OPENCV_VERSION_MAJOR ${OpenCV_VERSION_MAJOR}) - include(CMakePackageConfigHelpers) - write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" -@@ -1484,7 +1519,8 @@ ENDIF(PCL_COMPILE_OPTIONS) - MESSAGE(STATUS "") - MESSAGE(STATUS "Optional dependencies ('*' affects some default parameters) :") - IF(OpenCV_FOUND) -- IF(OPENCV_ARUCO_FOUND) -+ IF((OpenCV_VERSION_MAJOR LESS 4 AND OPENCV_ARUCO_FOUND) OR -+ (OpenCV_VERSION_MAJOR GREATER 4 AND OPENCV_OBJDETECT_FOUND)) - set(ARUCO_STR "YES") - ELSE() - set(ARUCO_STR "NO") -diff --git a/RTABMapConfig.cmake.in b/RTABMapConfig.cmake.in -index 155ef3e..713359b 100644 ---- a/RTABMapConfig.cmake.in -+++ b/RTABMapConfig.cmake.in -@@ -1,7 +1,7 @@ - include(CMakeFindDependencyMacro) - - # Mandatory dependencies --find_dependency(OpenCV COMPONENTS core calib3d imgproc highgui stitching photo video OPTIONAL_COMPONENTS aruco objdetect xfeatures2d nonfree gpu cudafeatures2d) -+find_dependency(OpenCV @CONF_OPENCV_VERSION_MAJOR@ COMPONENTS @CONF_OPENCV_COMPONENTS@ OPTIONAL_COMPONENTS @CONF_OPENCV_OPTIONAL_COMPONENTS@) - - if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/RTABMap_guiTargets.cmake") - find_dependency(PCL 1.7 COMPONENTS common io kdtree search surface filters registration sample_consensus segmentation visualization) -diff --git a/corelib/include/rtabmap/core/DBDriverSqlite3.h b/corelib/include/rtabmap/core/DBDriverSqlite3.h -index a5df8e9..ad7358d 100644 ---- a/corelib/include/rtabmap/core/DBDriverSqlite3.h -+++ b/corelib/include/rtabmap/core/DBDriverSqlite3.h -@@ -30,7 +30,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines - #include "rtabmap/core/DBDriver.h" -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - - typedef struct sqlite3_stmt sqlite3_stmt; - typedef struct sqlite3 sqlite3; -diff --git a/corelib/include/rtabmap/core/EpipolarGeometry.h b/corelib/include/rtabmap/core/EpipolarGeometry.h -index e9408cd..c739d0d 100644 ---- a/corelib/include/rtabmap/core/EpipolarGeometry.h -+++ b/corelib/include/rtabmap/core/EpipolarGeometry.h -@@ -31,7 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/core/Parameters.h" - #include "rtabmap/utilite/UStl.h" - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - #include -diff --git a/corelib/include/rtabmap/core/Features2d.h b/corelib/include/rtabmap/core/Features2d.h -index eec3f57..82a6ddb 100644 ---- a/corelib/include/rtabmap/core/Features2d.h -+++ b/corelib/include/rtabmap/core/Features2d.h -@@ -32,7 +32,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - #include "rtabmap/core/Parameters.h" -@@ -70,6 +74,10 @@ class BriefDescriptorExtractor; - class SIFT; - #endif - class SURF; -+#if (CV_MAJOR_VERSION == 5) -+class BRISK; -+class KAZE; -+#endif - } - namespace cuda { - class FastFeatureDetector; -@@ -89,7 +97,13 @@ typedef cv::xfeatures2d::FREAK CV_FREAK; - typedef cv::xfeatures2d::DAISY CV_DAISY; - typedef cv::GFTTDetector CV_GFTT; - typedef cv::xfeatures2d::BriefDescriptorExtractor CV_BRIEF; -+#if (CV_MAJOR_VERSION < 5) - typedef cv::BRISK CV_BRISK; -+typedef cv::KAZE CV_KAZE; -+#else -+typedef cv::xfeatures2d::BRISK CV_BRISK; -+typedef cv::xfeatures2d::KAZE CV_KAZE; -+#endif - typedef cv::ORB CV_ORB; - typedef cv::cuda::SURF_CUDA CV_SURF_GPU; - typedef cv::cuda::ORB CV_ORB_GPU; -@@ -578,7 +592,7 @@ private: - int diffusivity_; - - #if CV_MAJOR_VERSION > 2 -- cv::Ptr kaze_; -+ cv::Ptr kaze_; - #endif - }; - -diff --git a/corelib/include/rtabmap/core/MarkerDetector.h b/corelib/include/rtabmap/core/MarkerDetector.h -index 630bf87..26b6a73 100644 ---- a/corelib/include/rtabmap/core/MarkerDetector.h -+++ b/corelib/include/rtabmap/core/MarkerDetector.h -@@ -32,7 +32,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - --#ifdef HAVE_OPENCV_ARUCO -+#if (CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT) -+#include -+#elif defined(HAVE_OPENCV_ARUCO) - #include - #endif - -@@ -97,8 +99,11 @@ private: - float maxRange_; - float minRange_; - int dictionaryId_; --#ifdef HAVE_OPENCV_ARUCO -- cv::Ptr detectorParams_; -+#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) -+#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7) -+ cv::Ptr arucoDetector_; -+#endif -+ cv::Ptr detectorParams_; - cv::Ptr dictionary_; - #endif - void * apriltagLibDetector_; -diff --git a/corelib/include/rtabmap/core/Memory.h b/corelib/include/rtabmap/core/Memory.h -index 8c3306a..543b834 100644 ---- a/corelib/include/rtabmap/core/Memory.h -+++ b/corelib/include/rtabmap/core/Memory.h -@@ -41,7 +41,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include "rtabmap/utilite/UStl.h" - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - - namespace rtabmap { -diff --git a/corelib/include/rtabmap/core/OdometryInfo.h b/corelib/include/rtabmap/core/OdometryInfo.h -index 484692b..4f96a59 100644 ---- a/corelib/include/rtabmap/core/OdometryInfo.h -+++ b/corelib/include/rtabmap/core/OdometryInfo.h -@@ -34,7 +34,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/core/RegistrationInfo.h" - #include "rtabmap/core/CameraModel.h" - #include "rtabmap/core/LaserScan.h" -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - - namespace rtabmap { - -diff --git a/corelib/include/rtabmap/core/SensorData.h b/corelib/include/rtabmap/core/SensorData.h -index ea5a5de..a088755 100644 ---- a/corelib/include/rtabmap/core/SensorData.h -+++ b/corelib/include/rtabmap/core/SensorData.h -@@ -34,7 +34,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - #include -diff --git a/corelib/include/rtabmap/core/Signature.h b/corelib/include/rtabmap/core/Signature.h -index 9dbbe53..11f6f9c 100644 ---- a/corelib/include/rtabmap/core/Signature.h -+++ b/corelib/include/rtabmap/core/Signature.h -@@ -31,7 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - #include -diff --git a/corelib/include/rtabmap/core/Statistics.h b/corelib/include/rtabmap/core/Statistics.h -index 1cdaf40..f787d9b 100644 ---- a/corelib/include/rtabmap/core/Statistics.h -+++ b/corelib/include/rtabmap/core/Statistics.h -@@ -31,7 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines - - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - #include -diff --git a/corelib/include/rtabmap/core/VWDictionary.h b/corelib/include/rtabmap/core/VWDictionary.h -index ebfa3a6..3a7e195 100644 ---- a/corelib/include/rtabmap/core/VWDictionary.h -+++ b/corelib/include/rtabmap/core/VWDictionary.h -@@ -31,7 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - #include "rtabmap/core/Parameters.h" -diff --git a/corelib/include/rtabmap/core/stereo/stereoRectifyFisheye.h b/corelib/include/rtabmap/core/stereo/stereoRectifyFisheye.h -index 2fc12a2..60b1d79 100644 ---- a/corelib/include/rtabmap/core/stereo/stereoRectifyFisheye.h -+++ b/corelib/include/rtabmap/core/stereo/stereoRectifyFisheye.h -@@ -32,6 +32,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #ifndef CORELIB_SRC_OPENCV_STEREORECTIFYFISHEYE_H_ - #define CORELIB_SRC_OPENCV_STEREORECTIFYFISHEYE_H_ - -+// This header relies on the OpenCV C API (cvRodrigues2, cvProjectPoints2, ...) -+// which was removed in OpenCV 5. Pull in only the version macros (available in -+// all OpenCV versions) so we can fail early with a clear message rather than -+// with cryptic errors from the includes below. -+#include -+#if CV_MAJOR_VERSION >= 5 -+#error "stereoRectifyFisheye.h is not supported with OpenCV 5 or later (it uses the removed OpenCV C API). Use cv::fisheye::stereoRectify() instead, or guard your include with '#if CV_MAJOR_VERSION < 5'." -+#endif -+ - #include - #if CV_MAJOR_VERSION >= 3 - #include -diff --git a/corelib/include/rtabmap/core/util3d_correspondences.h b/corelib/include/rtabmap/core/util3d_correspondences.h -index 6bbaeb2..d53ece4 100644 ---- a/corelib/include/rtabmap/core/util3d_correspondences.h -+++ b/corelib/include/rtabmap/core/util3d_correspondences.h -@@ -32,7 +32,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include - #include -+#include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - #include -diff --git a/corelib/include/rtabmap/core/util3d_features.h b/corelib/include/rtabmap/core/util3d_features.h -index 2ea95bf..6547e5c 100644 ---- a/corelib/include/rtabmap/core/util3d_features.h -+++ b/corelib/include/rtabmap/core/util3d_features.h -@@ -30,7 +30,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include - -+#include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - #include + INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/CheckGTSAMFeatures.cmake) + ENDIF(GTSAM_FOUND) diff --git a/corelib/src/CMakeLists.txt b/corelib/src/CMakeLists.txt -index e6bf74c..fdfe0fa 100644 +index 892279c..06c7972 100644 --- a/corelib/src/CMakeLists.txt +++ b/corelib/src/CMakeLists.txt -@@ -875,6 +875,12 @@ add_definitions(${PCL_DEFINITIONS}) - # The extension is automatically found. +@@ -912,6 +912,12 @@ configure_file( + ADD_LIBRARY(rtabmap_core ${SRC_FILES} ${RESOURCES_HEADERS}) ADD_LIBRARY(rtabmap::core ALIAS rtabmap_core) +# GTSAM and this target both instantiate an identical inline TBB allocator @@ -371,2601 +44,3 @@ index e6bf74c..fdfe0fa 100644 generate_export_header(rtabmap_core DEPRECATED_MACRO_NAME RTABMAP_DEPRECATED) -diff --git a/corelib/src/EpipolarGeometry.cpp b/corelib/src/EpipolarGeometry.cpp -index 38f1584..758a14a 100644 ---- a/corelib/src/EpipolarGeometry.cpp -+++ b/corelib/src/EpipolarGeometry.cpp -@@ -33,8 +33,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UMath.h" - - #include --#include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - - namespace rtabmap -diff --git a/corelib/src/Features2d.cpp b/corelib/src/Features2d.cpp -index da83db7..184a4d8 100644 ---- a/corelib/src/Features2d.cpp -+++ b/corelib/src/Features2d.cpp -@@ -36,7 +36,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UMath.h" - #include "rtabmap/utilite/ULogger.h" - #include "rtabmap/utilite/UTimer.h" --#include - #include - #include - -@@ -865,7 +864,7 @@ std::vector Feature2D::generateKeypoints(const cv::Mat & image, co - cv::cornerSubPix( image, corners, - cv::Size( _subPixWinSize, _subPixWinSize ), - cv::Size( -1, -1 ), -- cv::TermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, _subPixIterations, _subPixEps ) ); -+ cv::TermCriteria( cv::TermCriteria::MAX_ITER | cv::TermCriteria::EPS, _subPixIterations, _subPixEps ) ); - - for(unsigned int i=0;i 4 -+#ifdef HAVE_OPENCV_XFEATURES2D -+ brisk_ = CV_BRISK::create(thresh_, octaves_, patternScale_); -+#else -+ UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so BRISK cannot be used!"); -+#endif -+#elif CV_MAJOR_VERSION < 3 - brisk_ = cv::Ptr(new CV_BRISK(thresh_, octaves_, patternScale_)); - #else - brisk_ = CV_BRISK::create(thresh_, octaves_, patternScale_); -@@ -2389,6 +2393,7 @@ std::vector BRISK::generateKeypointsImpl(const cv::Mat & image, co - { - UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U); - std::vector keypoints; -+#if CV_MAJOR_VERSION < 5 || (CV_MAJOR_VERSION > 4 && defined(HAVE_OPENCV_XFEATURES2D)) - cv::Mat imgRoi(image, roi); - cv::Mat maskRoi; - if(!mask.empty()) -@@ -2396,6 +2401,9 @@ std::vector BRISK::generateKeypointsImpl(const cv::Mat & image, co - maskRoi = cv::Mat(mask, roi); - } - brisk_->detect(imgRoi, keypoints, maskRoi); // Opencv keypoints -+#else -+ UWARN("RTAB-Map is not built with BRISK feature support!"); -+#endif - return keypoints; - } - -@@ -2403,7 +2411,11 @@ cv::Mat BRISK::generateDescriptorsImpl(const cv::Mat & image, std::vector 4 && defined(HAVE_OPENCV_XFEATURES2D)) - brisk_->compute(image, keypoints, descriptors); -+#else -+ UWARN("RTAB-Map is not built with BRISK feature support!"); -+#endif - return descriptors; - } - -@@ -2436,10 +2448,16 @@ void KAZE::parseParameters(const ParametersMap & parameters) - Parameters::parse(parameters, Parameters::kKAZENOctaveLayers(), nOctaveLayers_); - Parameters::parse(parameters, Parameters::kKAZEDiffusivity(), diffusivity_); - --#if CV_MAJOR_VERSION > 3 -- kaze_ = cv::KAZE::create(extended_, upright_, threshold_, nOctaves_, nOctaveLayers_, (cv::KAZE::DiffusivityType)diffusivity_); -+#if CV_MAJOR_VERSION > 4 -+#ifdef HAVE_OPENCV_XFEATURES2D -+ kaze_ = CV_KAZE::create(extended_, upright_, threshold_, nOctaves_, nOctaveLayers_, (CV_KAZE::DiffusivityType)diffusivity_); -+#else -+ UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so KAZE cannot be used!"); -+#endif -+#elif CV_MAJOR_VERSION > 3 -+ kaze_ = CV_KAZE::create(extended_, upright_, threshold_, nOctaves_, nOctaveLayers_, (CV_KAZE::DiffusivityType)diffusivity_); - #elif CV_MAJOR_VERSION > 2 -- kaze_ = cv::KAZE::create(extended_, upright_, threshold_, nOctaves_, nOctaveLayers_, diffusivity_); -+ kaze_ = CV_KAZE::create(extended_, upright_, threshold_, nOctaves_, nOctaveLayers_, diffusivity_); - #else - UWARN("RTAB-Map is not built with OpenCV3 so Kaze feature cannot be used!"); - #endif -@@ -2449,7 +2467,7 @@ std::vector KAZE::generateKeypointsImpl(const cv::Mat & image, con - { - UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U); - std::vector keypoints; --#if CV_MAJOR_VERSION > 2 -+#if (CV_MAJOR_VERSION > 2 && CV_MAJOR_VERSION < 5) || (CV_MAJOR_VERSION > 4 && defined(HAVE_OPENCV_XFEATURES2D)) - cv::Mat imgRoi(image, roi); - cv::Mat maskRoi; - if (!mask.empty()) -@@ -2458,7 +2476,7 @@ std::vector KAZE::generateKeypointsImpl(const cv::Mat & image, con - } - kaze_->detect(imgRoi, keypoints, maskRoi); // Opencv keypoints - #else -- UWARN("RTAB-Map is not built with OpenCV3 so Kaze feature cannot be used!"); -+ UWARN("RTAB-Map is not built with Kaze feature support!"); - #endif - return keypoints; - } -@@ -2467,10 +2485,10 @@ cv::Mat KAZE::generateDescriptorsImpl(const cv::Mat & image, std::vector 2 -+#if (CV_MAJOR_VERSION > 2 && CV_MAJOR_VERSION < 5) || (CV_MAJOR_VERSION > 4 && defined(HAVE_OPENCV_XFEATURES2D)) - kaze_->compute(image, keypoints, descriptors); - #else -- UWARN("RTAB-Map is not built with OpenCV3 so Kaze feature cannot be used!"); -+ UWARN("RTAB-Map is not built with Kaze feature support!"); - #endif - return descriptors; - } -diff --git a/corelib/src/MarkerDetector.cpp b/corelib/src/MarkerDetector.cpp -index 1484082..0b7acde 100644 ---- a/corelib/src/MarkerDetector.cpp -+++ b/corelib/src/MarkerDetector.cpp -@@ -30,6 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - -+#if CV_MAJOR_VERSION > 4 -+#include -+#endif -+ - #ifdef HAVE_OPENCV_ARUCO - #if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION <8) - namespace cv{ -@@ -72,7 +76,7 @@ extern "C" { - #include "apriltag/tag36h11.h" - } - --#ifndef HAVE_OPENCV_ARUCO -+#if !((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) && !defined(HAVE_OPENCV_ARUCO) - // To match opencv::aruco module, add opencv::aruco dictionary enum - namespace cv{ - namespace aruco { -@@ -200,7 +204,7 @@ MarkerDetector::MarkerDetector(const ParametersMap & parameters) : - apriltagLibDetector_(NULL), - apriltagLibFamily_(NULL) - { --#ifdef HAVE_OPENCV_ARUCO -+#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) - #if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7) - detectorParams_.reset(new cv::aruco::DetectorParameters()); - #elif CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >=2) -@@ -310,7 +314,7 @@ void MarkerDetector::parseParameters(const ParametersMap & parameters) - } - } - --#ifdef HAVE_OPENCV_ARUCO -+#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) - detectorParams_->adaptiveThreshWinSizeMin = 3; - detectorParams_->adaptiveThreshWinSizeMax = 23; - detectorParams_->adaptiveThreshWinSizeStep = 10; -@@ -364,6 +368,7 @@ void MarkerDetector::parseParameters(const ParametersMap & parameters) - dictionaryId_ = Parameters::defaultMarkerDictionary(); - } - #endif -+ - #if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7) - dictionary_.reset(new cv::aruco::Dictionary()); - *dictionary_ = cv::aruco::getPredefinedDictionary(cv::aruco::PredefinedDictionaryType(dictionaryId_)); -@@ -373,6 +378,11 @@ void MarkerDetector::parseParameters(const ParametersMap & parameters) - dictionary_.reset(new cv::aruco::Dictionary()); - *dictionary_ = cv::aruco::getPredefinedDictionary(cv::aruco::PredefinedDictionaryType(dictionaryId_)); - #endif -+ -+#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7) -+ arucoDetector_.reset(new cv::aruco::ArucoDetector(*dictionary_, *detectorParams_)); -+#endif -+ - #else - if(strategy_ == 0) - { -@@ -441,7 +451,7 @@ void MarkerDetector::parseParameters(const ParametersMap & parameters) - #else - if(strategy_ == 1) - { --#ifdef HAVE_OPENCV_ARUCO -+#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) - UERROR("RTAB-Map is not built with apriltag library! Fallback to OpenCV (%s=0).", Parameters::kMarkerStrategy().c_str()); - strategy_ = kStrategyOpencv; - #else -@@ -471,6 +481,34 @@ std::map MarkerDetector::detect(const cv::Mat & image, const Cam - return detections; - } - -+#if (((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO)) && (CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)) -+// Drop-in replacement for cv::aruco::estimatePoseSingleMarkers(), which was deprecated -+// in OpenCV 4.7 and removed in OpenCV 5. It reproduces the legacy default behavior (marker -+// object points ordered as ARUCO_CCW_CENTER + SOLVEPNP_ITERATIVE) using cv::solvePnP() per -+// marker. For OpenCV < 4.7 the native cv::aruco::estimatePoseSingleMarkers() is still used. -+static void estimatePoseSingleMarkers( -+ const std::vector > & corners, -+ float markerLength, -+ const cv::Mat & cameraMatrix, -+ const cv::Mat & distCoeffs, -+ std::vector & rvecs, -+ std::vector & tvecs) -+{ -+ cv::Mat objPoints(4, 1, CV_32FC3); -+ objPoints.ptr(0)[0] = cv::Vec3f(-markerLength/2.f, markerLength/2.f, 0); -+ objPoints.ptr(0)[1] = cv::Vec3f( markerLength/2.f, markerLength/2.f, 0); -+ objPoints.ptr(0)[2] = cv::Vec3f( markerLength/2.f, -markerLength/2.f, 0); -+ objPoints.ptr(0)[3] = cv::Vec3f(-markerLength/2.f, -markerLength/2.f, 0); -+ -+ rvecs.resize(corners.size()); -+ tvecs.resize(corners.size()); -+ for(size_t i=0; i MarkerDetector::detect(const cv::Mat & image, - const std::vector & models, - const cv::Mat & depth, -@@ -482,20 +520,27 @@ std::map MarkerDetector::detect(const cv::Mat & image, - UASSERT(int((depth.cols/models.size())*models.size()) == depth.cols); - int subRGBWidth = image.cols/models.size(); - -+ // Only a real depth map (CV_16UC1/CV_32FC1) can be used for marker length estimation. -+ // Ignore anything else (e.g. a stereo right image passed by mistake) instead of crashing -+ // later in util2d::getDepth(). -+ cv::Mat depthMap = depth; -+ if(!depthMap.empty() && depthMap.type()!=CV_16UC1 && depthMap.type()!=CV_32FC1) -+ { -+ UWARN("Marker detection: ignoring depth image with unsupported type=%d (expected CV_16UC1 or CV_32FC1).", depthMap.type()); -+ depthMap = cv::Mat(); -+ } -+ - float rgbToDepthFactorX = 1.0f; - float rgbToDepthFactorY = 1.0f; -- if(!depth.empty()) -+ if(!depthMap.empty()) - { -- rgbToDepthFactorX = float(depth.cols) / float(image.cols); -- rgbToDepthFactorY = float(depth.rows) / float(image.rows); -+ rgbToDepthFactorX = float(depthMap.cols) / float(image.cols); -+ rgbToDepthFactorY = float(depthMap.rows) / float(image.rows); - } - else if(markerLength_ == 0) - { -- if(depth.empty()) -- { -- UERROR("Depth image is empty, please set %s parameter to non-null.", Parameters::kMarkerLength().c_str()); -- return std::map(); -- } -+ UERROR("Depth image is empty, please set %s parameter to non-null.", Parameters::kMarkerLength().c_str()); -+ return std::map(); - } - - std::vector< int > ids; -@@ -632,8 +677,10 @@ std::map MarkerDetector::detect(const cv::Mat & image, - { - std::vector< int > cvIds; - std::vector< std::vector< cv::Point2f > > cvCorners, cvRejected; --#ifdef HAVE_OPENCV_ARUCO --#if CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >=2) -+#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) -+#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7) -+ arucoDetector_->detectMarkers(image, cvCorners, cvIds, cvRejected); -+#elif CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >=2) - cv::aruco::detectMarkers(image, dictionary_, cvCorners, cvIds, detectorParams_, cvRejected); - #else - cv::aruco::detectMarkers(image, *dictionary_, cvCorners, cvIds, *detectorParams_, cvRejected); -@@ -686,9 +733,15 @@ std::map MarkerDetector::detect(const cv::Mat & image, - - for(size_t cam=0; cam < cvCornersPerCam.size(); ++cam) - { -- std::vector< cv::Vec3d > rvecs, tvecs; - const CameraModel & model = models[cam]; -+ -+ std::vector< cv::Vec3d > rvecs, tvecs; -+#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7) -+ estimatePoseSingleMarkers(cvCornersPerCam[cam], 1.0f, model.K(), model.D(), rvecs, tvecs); -+#else - cv::aruco::estimatePoseSingleMarkers(cvCornersPerCam[cam], 1.0f, model.K(), model.D(), rvecs, tvecs); -+#endif -+ - float offsetX = cam*subRGBWidth; - for(size_t i=0; i MarkerDetector::detect(const cv::Mat & image, - { - float length = 0.0f; - std::map::const_iterator findIter = extraMarkerLengths.find(ids[i]); -- if(markerLengths_.empty() && !depth.empty() && (markerLength_ == 0 || (markerLength_<0 && findIter==extraMarkerLengths.end()))) -+ if(markerLengths_.empty() && !depthMap.empty() && (markerLength_ == 0 || (markerLength_<0 && findIter==extraMarkerLengths.end()))) - { -- float d = util2d::getDepth(depth, (corners[i][0].x + (corners[i][2].x-corners[i][0].x)/2.0f)*rgbToDepthFactorX, (corners[i][0].y + (corners[i][2].y-corners[i][0].y)/2.0f)*rgbToDepthFactorY, true, 0.02f, true); -- float d1 = util2d::getDepth(depth, corners[i][0].x*rgbToDepthFactorX, corners[i][0].y*rgbToDepthFactorY, true, 0.02f, true); -- float d2 = util2d::getDepth(depth, corners[i][1].x*rgbToDepthFactorX, corners[i][1].y*rgbToDepthFactorY, true, 0.02f, true); -- float d3 = util2d::getDepth(depth, corners[i][2].x*rgbToDepthFactorX, corners[i][2].y*rgbToDepthFactorY, true, 0.02f, true); -- float d4 = util2d::getDepth(depth, corners[i][3].x*rgbToDepthFactorX, corners[i][3].y*rgbToDepthFactorY, true, 0.02f, true); -+ float d = util2d::getDepth(depthMap, (corners[i][0].x + (corners[i][2].x-corners[i][0].x)/2.0f)*rgbToDepthFactorX, (corners[i][0].y + (corners[i][2].y-corners[i][0].y)/2.0f)*rgbToDepthFactorY, true, 0.02f, true); -+ float d1 = util2d::getDepth(depthMap, corners[i][0].x*rgbToDepthFactorX, corners[i][0].y*rgbToDepthFactorY, true, 0.02f, true); -+ float d2 = util2d::getDepth(depthMap, corners[i][1].x*rgbToDepthFactorX, corners[i][1].y*rgbToDepthFactorY, true, 0.02f, true); -+ float d3 = util2d::getDepth(depthMap, corners[i][2].x*rgbToDepthFactorX, corners[i][2].y*rgbToDepthFactorY, true, 0.02f, true); -+ float d4 = util2d::getDepth(depthMap, corners[i][3].x*rgbToDepthFactorX, corners[i][3].y*rgbToDepthFactorY, true, 0.02f, true); - // Accept measurement only if all 4 depth values are valid and - // they are at the same depth (camera should be perpendicular to marker for - // best depth estimation) -@@ -887,7 +940,7 @@ std::map MarkerDetector::detect(const cv::Mat & image, - - if(!ids.empty()) - { --#ifdef HAVE_OPENCV_ARUCO -+#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) - cv::aruco::drawDetectedMarkers(*imageWithDetections, corners, ids); - #else - UWARN("RTAB-Map is not built with \"aruco\" module from OpenCV. Cannot draw markers on image."); -diff --git a/corelib/src/Memory.cpp b/corelib/src/Memory.cpp -index 37afdbf..c88304c 100644 ---- a/corelib/src/Memory.cpp -+++ b/corelib/src/Memory.cpp -@@ -62,8 +62,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - #include -+#if CV_MAJOR_VERSION >=5 -+#include -+#endif - - namespace rtabmap { - -@@ -5373,7 +5375,7 @@ Signature * Memory::createSignature(const SensorData & inputData, const Transfor - cv::Mat imageMono; - if(decimatedData.imageRaw().channels() == 3) - { -- cv::cvtColor(decimatedData.imageRaw(), imageMono, CV_BGR2GRAY); -+ cv::cvtColor(decimatedData.imageRaw(), imageMono, cv::COLOR_BGR2GRAY); - } - else - { -@@ -5681,7 +5683,7 @@ Signature * Memory::createSignature(const SensorData & inputData, const Transfor - cv::Mat imageMono; - if(data.imageRaw().channels() == 3) - { -- cv::cvtColor(data.imageRaw(), imageMono, CV_BGR2GRAY); -+ cv::cvtColor(data.imageRaw(), imageMono, cv::COLOR_BGR2GRAY); - } - else - { -diff --git a/corelib/src/RegistrationVis.cpp b/corelib/src/RegistrationVis.cpp -index 738e72b..3e5cee3 100644 ---- a/corelib/src/RegistrationVis.cpp -+++ b/corelib/src/RegistrationVis.cpp -@@ -43,7 +43,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include -+#if CV_MAJOR_VERSION > 4 -+#include -+#endif - - #if defined(HAVE_OPENCV_XFEATURES2D) && (CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION==3 && CV_MINOR_VERSION >=4 && CV_SUBMINOR_VERSION >= 1)) - #include // For GMS matcher -@@ -2172,7 +2174,7 @@ Transform RegistrationVis::computeTransformationImpl( - if(!transform.isNull() && !pcaData.empty()) - { - cv::Mat pcaEigenVectors, pcaEigenValues; -- cv::PCA pca_analysis(pcaData, cv::Mat(), CV_PCA_DATA_AS_ROW); -+ cv::PCA pca_analysis(pcaData, cv::Mat(), cv::PCA::DATA_AS_ROW); - // We take the second eigen value - info.inliersDistribution = pca_analysis.eigenvalues.at(0, 1); - -diff --git a/corelib/src/SensorCaptureThread.cpp b/corelib/src/SensorCaptureThread.cpp -index 6414fb9..07858d5 100644 ---- a/corelib/src/SensorCaptureThread.cpp -+++ b/corelib/src/SensorCaptureThread.cpp -@@ -39,7 +39,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/core/IMUFilter.h" - #include "rtabmap/core/Features2d.h" - #include "rtabmap/core/clams/discrete_depth_distortion_model.h" --#include - #include - #include - #include -@@ -742,11 +741,11 @@ void SensorCaptureThread::postUpdate(SensorData * dataPtr, SensorCaptureInfo * i - else if(data.imageRaw().type() == CV_8UC3) - { - cv::Mat channels[3]; -- cv::cvtColor(data.imageRaw(), image, CV_BGR2YCrCb); -+ cv::cvtColor(data.imageRaw(), image, cv::COLOR_BGR2YCrCb); - cv::split(image, channels); - cv::equalizeHist(channels[0], channels[0]); - cv::merge(channels, 3, image); -- cv::cvtColor(image, image, CV_YCrCb2BGR); -+ cv::cvtColor(image, image, cv::COLOR_YCrCb2BGR); - } - if(!data.depthRaw().empty()) - { -@@ -762,11 +761,11 @@ void SensorCaptureThread::postUpdate(SensorData * dataPtr, SensorCaptureInfo * i - else if(data.rightRaw().type() == CV_8UC3) - { - cv::Mat channels[3]; -- cv::cvtColor(data.rightRaw(), right, CV_BGR2YCrCb); -+ cv::cvtColor(data.rightRaw(), right, cv::COLOR_BGR2YCrCb); - cv::split(right, channels); - cv::equalizeHist(channels[0], channels[0]); - cv::merge(channels, 3, right); -- cv::cvtColor(right, right, CV_YCrCb2BGR); -+ cv::cvtColor(right, right, cv::COLOR_YCrCb2BGR); - } - data.setStereoImage(image, right, data.stereoCameraModels()[0]); - } -@@ -781,11 +780,11 @@ void SensorCaptureThread::postUpdate(SensorData * dataPtr, SensorCaptureInfo * i - else if(data.imageRaw().type() == CV_8UC3) - { - cv::Mat channels[3]; -- cv::cvtColor(data.imageRaw(), image, CV_BGR2YCrCb); -+ cv::cvtColor(data.imageRaw(), image, cv::COLOR_BGR2YCrCb); - cv::split(image, channels); - clahe->apply(channels[0], channels[0]); - cv::merge(channels, 3, image); -- cv::cvtColor(image, image, CV_YCrCb2BGR); -+ cv::cvtColor(image, image, cv::COLOR_YCrCb2BGR); - } - if(!data.depthRaw().empty()) - { -@@ -801,11 +800,11 @@ void SensorCaptureThread::postUpdate(SensorData * dataPtr, SensorCaptureInfo * i - else if(data.rightRaw().type() == CV_8UC3) - { - cv::Mat channels[3]; -- cv::cvtColor(data.rightRaw(), right, CV_BGR2YCrCb); -+ cv::cvtColor(data.rightRaw(), right, cv::COLOR_BGR2YCrCb); - cv::split(right, channels); - clahe->apply(channels[0], channels[0]); - cv::merge(channels, 3, right); -- cv::cvtColor(right, right, CV_YCrCb2BGR); -+ cv::cvtColor(right, right, cv::COLOR_YCrCb2BGR); - } - data.setStereoImage(image, right, data.stereoCameraModels()[0]); - } -diff --git a/corelib/src/StereoCameraModel.cpp b/corelib/src/StereoCameraModel.cpp -index 421d3f4..8830c37 100644 ---- a/corelib/src/StereoCameraModel.cpp -+++ b/corelib/src/StereoCameraModel.cpp -@@ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - --#if CV_MAJOR_VERSION > 2 or (CV_MAJOR_VERSION == 2 and (CV_MINOR_VERSION >4 or (CV_MINOR_VERSION == 4 and CV_SUBMINOR_VERSION >=10))) -+#if (CV_MAJOR_VERSION > 2 and CV_MAJOR_VERSION < 5) or (CV_MAJOR_VERSION == 2 and (CV_MINOR_VERSION >4 or (CV_MINOR_VERSION == 4 and CV_SUBMINOR_VERSION >=10))) - #include - #endif - -@@ -179,12 +179,20 @@ void StereoCameraModel::updateStereoRectification() - { - cv::Vec4d D_left(left_.D_raw().at(0,0), left_.D_raw().at(0,1), left_.D_raw().at(0,4), left_.D_raw().at(0,5)); - cv::Vec4d D_right(right_.D_raw().at(0,0), right_.D_raw().at(0,1), right_.D_raw().at(0,4), right_.D_raw().at(0,5)); -- -+#if CV_MAJOR_VERSION < 5 - stereoRectifyFisheye( - left_.K_raw(), D_left, - right_.K_raw(), D_right, - left_.imageSize(), R_, T_, R1, R2, P1, P2, Q, - cv::CALIB_ZERO_DISPARITY, 0, left_.imageSize()); -+#else -+ double balance = 0.0, fov_scale = 1.0; -+ cv::fisheye::stereoRectify( -+ left_.K_raw(), D_left, -+ right_.K_raw(), D_right, -+ left_.imageSize(), R_, T_, R1, R2, P1, P2, Q, -+ cv::CALIB_ZERO_DISPARITY, left_.imageSize(), balance, fov_scale); -+#endif - - // Re-zoom to original focal distance - if(P1.at(0,0) < 0) -diff --git a/corelib/src/camera/CameraDepthAI.cpp b/corelib/src/camera/CameraDepthAI.cpp -index beaca87..326d5bd 100644 ---- a/corelib/src/camera/CameraDepthAI.cpp -+++ b/corelib/src/camera/CameraDepthAI.cpp -@@ -32,7 +32,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include -- -+#if CV_MAJOR_VERSION < 5 -+#include -+#else -+#include -+#endif - - namespace rtabmap { - -diff --git a/corelib/src/camera/CameraFreenect.cpp b/corelib/src/camera/CameraFreenect.cpp -index 9d48215..a402c7b 100644 ---- a/corelib/src/camera/CameraFreenect.cpp -+++ b/corelib/src/camera/CameraFreenect.cpp -@@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - - #ifdef RTABMAP_FREENECT - #include -@@ -183,7 +182,7 @@ private: - - if(color_) - { -- cv::cvtColor(rgbIrBuffer_, rgbIrLastFrame_, CV_RGB2BGR); -+ cv::cvtColor(rgbIrBuffer_, rgbIrLastFrame_, cv::COLOR_RGB2BGR); - } - else // IrDepth - { -diff --git a/corelib/src/camera/CameraFreenect2.cpp b/corelib/src/camera/CameraFreenect2.cpp -index 85f7bdf..1514311 100644 ---- a/corelib/src/camera/CameraFreenect2.cpp -+++ b/corelib/src/camera/CameraFreenect2.cpp -@@ -29,7 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - - #ifdef RTABMAP_FREENECT2 - #include -@@ -430,11 +429,11 @@ SensorData CameraFreenect2::captureImage(SensorCaptureInfo * info) - cv::Mat rgbMat; // rtabmap uses 3 channels RGB - #ifdef LIBFREENECT2_WITH_TEGRAJPEG_SUPPORT - -- cv::cvtColor(rgbMatC4, rgbMat, CV_RGBA2BGR); -+ cv::cvtColor(rgbMatC4, rgbMat, cv::COLOR_RGBA2BGR); - - #else - -- cv::cvtColor(rgbMatC4, rgbMat, CV_BGRA2BGR); -+ cv::cvtColor(rgbMatC4, rgbMat, cv::COLOR_BGRA2BGR); - - #endif - cv::flip(rgbMat, rgb, 1); -@@ -490,11 +489,11 @@ SensorData CameraFreenect2::captureImage(SensorCaptureInfo * info) - cv::Mat rgbMat; // rtabmap uses 3 channels RGB - #ifdef LIBFREENECT2_WITH_TEGRAJPEG_SUPPORT - -- cv::cvtColor(rgbMatC4, rgbMat, CV_RGB2BGR); -+ cv::cvtColor(rgbMatC4, rgbMat, cv::COLOR_RGB2BGR); - - #else - -- cv::cvtColor(rgbMatC4, rgbMat, CV_BGRA2BGR); -+ cv::cvtColor(rgbMatC4, rgbMat, cv::COLOR_BGRA2BGR); - - #endif - cv::flip(rgbMat, rgb, 1); -@@ -607,11 +606,11 @@ SensorData CameraFreenect2::captureImage(SensorCaptureInfo * info) - // rtabmap uses 3 channels RGB - #ifdef LIBFREENECT2_WITH_TEGRAJPEG_SUPPORT - -- cv::cvtColor(rgbMatBGRA, rgb, CV_RGBA2BGR); -+ cv::cvtColor(rgbMatBGRA, rgb, cv::COLOR_RGBA2BGR); - - #else - -- cv::cvtColor(rgbMatBGRA, rgb, CV_BGRA2BGR); -+ cv::cvtColor(rgbMatBGRA, rgb, cv::COLOR_BGRA2BGR); - - #endif - cv::flip(rgb, rgb, 1); -@@ -629,11 +628,11 @@ SensorData CameraFreenect2::captureImage(SensorCaptureInfo * info) - // rtabmap uses 3 channels RGB - #ifdef LIBFREENECT2_WITH_TEGRAJPEG_SUPPORT - -- cv::cvtColor(rgbMatBGRA, rgb, CV_RGBA2BGR); -+ cv::cvtColor(rgbMatBGRA, rgb, cv::COLOR_RGBA2BGR); - - #else - -- cv::cvtColor(rgbMatBGRA, rgb, CV_BGRA2BGR); -+ cv::cvtColor(rgbMatBGRA, rgb, cv::COLOR_BGRA2BGR); - - #endif - cv::flip(rgb, rgb, 1); -diff --git a/corelib/src/camera/CameraImages.cpp b/corelib/src/camera/CameraImages.cpp -index 9767412..824c9be 100644 ---- a/corelib/src/camera/CameraImages.cpp -+++ b/corelib/src/camera/CameraImages.cpp -@@ -34,7 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include -+#include - #include - - namespace rtabmap -@@ -933,7 +933,7 @@ SensorData CameraImages::captureImage(SensorCaptureInfo * info) - { - UWARN("Conversion from 4 channels to 3 channels (file=%s)", imageFilePath.c_str()); - cv::Mat out; -- cv::cvtColor(img, out, CV_BGRA2BGR); -+ cv::cvtColor(img, out, cv::COLOR_BGRA2BGR); - img = out; - } - else if(!img.empty() && _bayerMode >= 0 && _bayerMode <=3) -@@ -941,7 +941,7 @@ SensorData CameraImages::captureImage(SensorCaptureInfo * info) - cv::Mat debayeredImg; - try - { -- cv::cvtColor(img, debayeredImg, CV_BayerBG2BGR + _bayerMode); -+ cv::cvtColor(img, debayeredImg, cv::COLOR_BayerBG2BGR + _bayerMode); - img = debayeredImg; - } - catch(const cv::Exception & e) -diff --git a/corelib/src/camera/CameraK4A.cpp b/corelib/src/camera/CameraK4A.cpp -index ad5714d..caf659b 100644 ---- a/corelib/src/camera/CameraK4A.cpp -+++ b/corelib/src/camera/CameraK4A.cpp -@@ -29,7 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - - #ifdef RTABMAP_K4A - #include -@@ -508,7 +507,7 @@ SensorData CameraK4A::captureImage(SensorCaptureInfo * info) - CV_8UC4, - (void*)k4a_image_get_buffer(rgb_image_)); - -- cv::cvtColor(bgra, bgrCV, CV_BGRA2BGR); -+ cv::cvtColor(bgra, bgrCV, cv::COLOR_BGRA2BGR); - } - bgrCV = model_.rectifyImage(bgrCV); - -diff --git a/corelib/src/camera/CameraK4W2.cpp b/corelib/src/camera/CameraK4W2.cpp -index e289029..9a96251 100644 ---- a/corelib/src/camera/CameraK4W2.cpp -+++ b/corelib/src/camera/CameraK4W2.cpp -@@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - - #ifdef RTABMAP_K4W2 - #include -@@ -486,11 +485,11 @@ SensorData CameraK4W2::captureImage(SensorCaptureInfo * info) - { - cv::Mat tmp; - cv::resize(cv::Mat(nColorHeight, nColorWidth, CV_8UC4, pColorBuffer), tmp, cv::Size(), 0.5, 0.5, cv::INTER_AREA); -- cv::cvtColor(tmp, imageColor, CV_BGRA2BGR); -+ cv::cvtColor(tmp, imageColor, cv::COLOR_BGRA2BGR); - } - else - { -- cv::cvtColor(cv::Mat(nColorHeight, nColorWidth, CV_8UC4, pColorBuffer), imageColor, CV_BGRA2BGR); -+ cv::cvtColor(cv::Mat(nColorHeight, nColorWidth, CV_8UC4, pColorBuffer), imageColor, cv::COLOR_BGRA2BGR); - } - // loop over output pixels - for (int depthIndex = 0; depthIndex < (nDepthWidth*nDepthHeight); ++depthIndex) -diff --git a/corelib/src/camera/CameraOpenNI2.cpp b/corelib/src/camera/CameraOpenNI2.cpp -index 8be86b7..4d2ff1a 100644 ---- a/corelib/src/camera/CameraOpenNI2.cpp -+++ b/corelib/src/camera/CameraOpenNI2.cpp -@@ -29,7 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - - #ifdef RTABMAP_OPENNI2 - #include -@@ -514,7 +513,7 @@ SensorData CameraOpenNI2::captureImage(SensorCaptureInfo * info) - cv::Mat tmp(h, w, CV_8UC3, (void *)colorFrame.getData()); - if(_type==kTypeColorDepth) - { -- cv::cvtColor(tmp, rgb, CV_RGB2BGR); -+ cv::cvtColor(tmp, rgb, cv::COLOR_RGB2BGR); - } - else // IR - { -diff --git a/corelib/src/camera/CameraOpenNICV.cpp b/corelib/src/camera/CameraOpenNICV.cpp -index 13536d6..1359561 100644 ---- a/corelib/src/camera/CameraOpenNICV.cpp -+++ b/corelib/src/camera/CameraOpenNICV.cpp -@@ -26,9 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include - #include --#if CV_MAJOR_VERSION > 3 --#include --#endif -+#include - - namespace rtabmap - { -@@ -59,30 +57,34 @@ bool CameraOpenNICV::init(const std::string & calibrationFolder, const std::stri - } - - ULOGGER_DEBUG("Camera::init()"); -- _capture.open( _asus?CV_CAP_OPENNI_ASUS:CV_CAP_OPENNI ); -+#if CV_MAJOR_VERSION < 5 -+ _capture.open( _asus?cv::CAP_OPENNI_ASUS:cv::CAP_OPENNI ); -+#else -+ _capture.open( _asus?cv::CAP_OPENNI2_ASUS:cv::CAP_OPENNI2 ); -+#endif - if(_capture.isOpened()) - { -- _capture.set( CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, CV_CAP_OPENNI_VGA_30HZ ); -- _depthFocal = _capture.get( CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH ); -+ _capture.set( cv::CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, cv::CAP_OPENNI_VGA_30HZ ); -+ _depthFocal = _capture.get( cv::CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH ); - // Print some avalible device settings. - UINFO("Depth generator output mode:"); -- UINFO("FRAME_WIDTH %f", _capture.get( CV_CAP_PROP_FRAME_WIDTH )); -- UINFO("FRAME_HEIGHT %f", _capture.get( CV_CAP_PROP_FRAME_HEIGHT )); -- UINFO("FRAME_MAX_DEPTH %f mm", _capture.get( CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH )); -- UINFO("BASELINE %f mm", _capture.get( CV_CAP_PROP_OPENNI_BASELINE )); -- UINFO("FPS %f", _capture.get( CV_CAP_PROP_FPS )); -- UINFO("Focal %f", _capture.get( CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH )); -- UINFO("REGISTRATION %f", _capture.get( CV_CAP_PROP_OPENNI_REGISTRATION )); -- if(_capture.get( CV_CAP_PROP_OPENNI_REGISTRATION ) == 0.0) -+ UINFO("FRAME_WIDTH %f", _capture.get( cv::CAP_PROP_FRAME_WIDTH )); -+ UINFO("FRAME_HEIGHT %f", _capture.get( cv::CAP_PROP_FRAME_HEIGHT )); -+ UINFO("FRAME_MAX_DEPTH %f mm", _capture.get( cv::CAP_PROP_OPENNI_FRAME_MAX_DEPTH )); -+ UINFO("BASELINE %f mm", _capture.get( cv::CAP_PROP_OPENNI_BASELINE )); -+ UINFO("FPS %f", _capture.get( cv::CAP_PROP_FPS )); -+ UINFO("Focal %f", _capture.get( cv::CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH )); -+ UINFO("REGISTRATION %f", _capture.get( cv::CAP_PROP_OPENNI_REGISTRATION )); -+ if(_capture.get( cv::CAP_PROP_OPENNI_REGISTRATION ) == 0.0) - { - UERROR("Depth registration is not activated on this device!"); - } -- if( _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT ) ) -+ if( _capture.get( cv::CAP_OPENNI_IMAGE_GENERATOR_PRESENT ) ) - { - UINFO("Image generator output mode:"); -- UINFO("FRAME_WIDTH %f", _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_WIDTH )); -- UINFO("FRAME_HEIGHT %f", _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_HEIGHT )); -- UINFO("FPS %f", _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FPS )); -+ UINFO("FRAME_WIDTH %f", _capture.get( cv::CAP_OPENNI_IMAGE_GENERATOR+cv::CAP_PROP_FRAME_WIDTH )); -+ UINFO("FRAME_HEIGHT %f", _capture.get( cv::CAP_OPENNI_IMAGE_GENERATOR+cv::CAP_PROP_FRAME_HEIGHT )); -+ UINFO("FPS %f", _capture.get( cv::CAP_OPENNI_IMAGE_GENERATOR+cv::CAP_PROP_FPS )); - } - else - { -@@ -112,8 +114,8 @@ SensorData CameraOpenNICV::captureImage(SensorCaptureInfo * info) - { - _capture.grab(); - cv::Mat depth, rgb; -- _capture.retrieve(depth, CV_CAP_OPENNI_DEPTH_MAP ); -- _capture.retrieve(rgb, CV_CAP_OPENNI_BGR_IMAGE ); -+ _capture.retrieve(depth, cv::CAP_OPENNI_DEPTH_MAP ); -+ _capture.retrieve(rgb, cv::CAP_OPENNI_BGR_IMAGE ); - - depth = depth.clone(); - rgb = rgb.clone(); -diff --git a/corelib/src/camera/CameraOpenni.cpp b/corelib/src/camera/CameraOpenni.cpp -index 9fb8dc7..68cba16 100644 ---- a/corelib/src/camera/CameraOpenni.cpp -+++ b/corelib/src/camera/CameraOpenni.cpp -@@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - - #ifdef RTABMAP_OPENNI - #include -@@ -94,7 +93,7 @@ void CameraOpenni::image_cb ( - - cv::Mat rgbFrame(rgb->getHeight(), rgb->getWidth(), CV_8UC3); - rgb->fillRGB(rgb->getWidth(), rgb->getHeight(), rgbFrame.data); -- cv::cvtColor(rgbFrame, rgb_, CV_RGB2BGR); -+ cv::cvtColor(rgbFrame, rgb_, cv::COLOR_RGB2BGR); - - depth_ = cv::Mat(rgb->getHeight(), rgb->getWidth(), CV_16UC1); - depth->fillDepthImageRaw(rgb->getWidth(), rgb->getHeight(), (unsigned short*)depth_.data); -diff --git a/corelib/src/camera/CameraRealSense.cpp b/corelib/src/camera/CameraRealSense.cpp -index 3f545bb..0136238 100644 ---- a/corelib/src/camera/CameraRealSense.cpp -+++ b/corelib/src/camera/CameraRealSense.cpp -@@ -29,7 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - - #ifdef RTABMAP_REALSENSE - #include -@@ -938,7 +937,7 @@ SensorData CameraRealSense::captureImage(SensorCaptureInfo * info) - } - else - { -- cv::cvtColor(rgb, bgr, CV_RGB2BGR); -+ cv::cvtColor(rgb, bgr, cv::COLOR_RGB2BGR); - } - - bool rectified = false; -diff --git a/corelib/src/camera/CameraRealSense2.cpp b/corelib/src/camera/CameraRealSense2.cpp -index fb15b0c..aad8e2c 100644 ---- a/corelib/src/camera/CameraRealSense2.cpp -+++ b/corelib/src/camera/CameraRealSense2.cpp -@@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - - #ifdef RTABMAP_REALSENSE2 - #include -@@ -1421,7 +1420,7 @@ SensorData CameraRealSense2::captureImage(SensorCaptureInfo * info) - cv::Mat bgr; - if(rgb.channels() == 3) - { -- cv::cvtColor(rgb, bgr, CV_RGB2BGR); -+ cv::cvtColor(rgb, bgr, cv::COLOR_RGB2BGR); - } - else - { -diff --git a/corelib/src/camera/CameraStereoDC1394.cpp b/corelib/src/camera/CameraStereoDC1394.cpp -index 691516b..2c21108 100644 ---- a/corelib/src/camera/CameraStereoDC1394.cpp -+++ b/corelib/src/camera/CameraStereoDC1394.cpp -@@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - - #ifdef RTABMAP_DC1394 - #include -@@ -295,8 +294,8 @@ public: - - //DC1394_COLOR_CODING_RAW16: - //DC1394_COLOR_FILTER_BGGR -- cv::cvtColor(cv::Mat(frame->size[1], frame->size[0], CV_8UC1, capture_buffer), left, CV_BayerRG2BGR); -- cv::cvtColor(cv::Mat(frame->size[1], frame->size[0], CV_8UC1, capture_buffer+image.total()), right, CV_BayerRG2GRAY); -+ cv::cvtColor(cv::Mat(frame->size[1], frame->size[0], CV_8UC1, capture_buffer), left, cv::COLOR_BayerRG2BGR); -+ cv::cvtColor(cv::Mat(frame->size[1], frame->size[0], CV_8UC1, capture_buffer+image.total()), right, cv::COLOR_BayerRG2GRAY); - - dc1394_capture_enqueue(camera_, frame); - -diff --git a/corelib/src/camera/CameraStereoImages.cpp b/corelib/src/camera/CameraStereoImages.cpp -index c50a3b8..e0dd643 100644 ---- a/corelib/src/camera/CameraStereoImages.cpp -+++ b/corelib/src/camera/CameraStereoImages.cpp -@@ -27,7 +27,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include - #include --#include - - namespace rtabmap - { -@@ -184,7 +183,7 @@ SensorData CameraStereoImages::captureImage(SensorCaptureInfo * info) - if(rightImage.type() != CV_8UC1 && rightGrayScale_) - { - cv::Mat tmp; -- cv::cvtColor(rightImage, tmp, CV_BGR2GRAY); -+ cv::cvtColor(rightImage, tmp, cv::COLOR_BGR2GRAY); - rightImage = tmp; - } - if(this->isImagesRectified() && stereoModel_.isValidForRectification()) -diff --git a/corelib/src/camera/CameraStereoTara.cpp b/corelib/src/camera/CameraStereoTara.cpp -index e4ea3cd..f4ec60a 100644 ---- a/corelib/src/camera/CameraStereoTara.cpp -+++ b/corelib/src/camera/CameraStereoTara.cpp -@@ -34,9 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#if CV_MAJOR_VERSION > 3 --#include --#endif -+#include - - namespace rtabmap - { -@@ -81,18 +79,18 @@ bool CameraStereoTara::init(const std::string & calibrationFolder, const std::st - - capture_.open(usbDevice_); - -- capture_.set(CV_CAP_PROP_FOURCC, CV_FOURCC('Y', '1', '6', ' ')); -- capture_.set(CV_CAP_PROP_FPS, 60); -- capture_.set(CV_CAP_PROP_FRAME_WIDTH, 752); -- capture_.set(CV_CAP_PROP_FRAME_HEIGHT, 480); -- capture_.set(CV_CAP_PROP_CONVERT_RGB,false); -+ capture_.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('Y', '1', '6', ' ')); -+ capture_.set(cv::CAP_PROP_FPS, 60); -+ capture_.set(cv::CAP_PROP_FRAME_WIDTH, 752); -+ capture_.set(cv::CAP_PROP_FRAME_HEIGHT, 480); -+ capture_.set(cv::CAP_PROP_CONVERT_RGB,false); - - ULOGGER_DEBUG("CameraStereoTara: Usb device initialization on device %d", usbDevice_); - - - if (cameraName_.empty()) - { -- unsigned int guid = (unsigned int)capture_.get(CV_CAP_PROP_GUID); -+ unsigned int guid = (unsigned int)capture_.get(cv::CAP_PROP_GUID); - if (guid != 0 && guid != 0xffffffff) - { - cameraName_ = uFormat("%08x", guid); -diff --git a/corelib/src/camera/CameraStereoVideo.cpp b/corelib/src/camera/CameraStereoVideo.cpp -index f31f40b..5de23a6 100644 ---- a/corelib/src/camera/CameraStereoVideo.cpp -+++ b/corelib/src/camera/CameraStereoVideo.cpp -@@ -28,13 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include --#if CV_MAJOR_VERSION > 3 --#include --#if CV_MAJOR_VERSION > 4 --#include --#endif --#endif -+#include - - namespace rtabmap - { -@@ -172,7 +166,7 @@ bool CameraStereoVideo::init(const std::string & calibrationFolder, const std::s - - if (cameraName_.empty()) - { -- unsigned int guid = (unsigned int)capture_.get(CV_CAP_PROP_GUID); -+ unsigned int guid = (unsigned int)capture_.get(cv::CAP_PROP_GUID); - if (guid != 0 && guid != 0xffffffff) - { - cameraName_ = uFormat("%08x", guid); -@@ -214,17 +208,17 @@ bool CameraStereoVideo::init(const std::string & calibrationFolder, const std::s - if(capture_.isOpened()) - { - bool resolutionSet = false; -- resolutionSet = capture_.set(CV_CAP_PROP_FRAME_WIDTH, stereoModel_.left().imageWidth()*(capture2_.isOpened()?1:2)); -- resolutionSet = resolutionSet && capture_.set(CV_CAP_PROP_FRAME_HEIGHT, stereoModel_.left().imageHeight()); -+ resolutionSet = capture_.set(cv::CAP_PROP_FRAME_WIDTH, stereoModel_.left().imageWidth()*(capture2_.isOpened()?1:2)); -+ resolutionSet = resolutionSet && capture_.set(cv::CAP_PROP_FRAME_HEIGHT, stereoModel_.left().imageHeight()); - if(capture2_.isOpened()) - { -- resolutionSet = resolutionSet && capture2_.set(CV_CAP_PROP_FRAME_WIDTH, stereoModel_.right().imageWidth()); -- resolutionSet = resolutionSet && capture2_.set(CV_CAP_PROP_FRAME_HEIGHT, stereoModel_.right().imageHeight()); -+ resolutionSet = resolutionSet && capture2_.set(cv::CAP_PROP_FRAME_WIDTH, stereoModel_.right().imageWidth()); -+ resolutionSet = resolutionSet && capture2_.set(cv::CAP_PROP_FRAME_HEIGHT, stereoModel_.right().imageHeight()); - } - - // Check if the resolution was set successfully -- int actualWidth = int(capture_.get(CV_CAP_PROP_FRAME_WIDTH)); -- int actualHeight = int(capture_.get(CV_CAP_PROP_FRAME_HEIGHT)); -+ int actualWidth = int(capture_.get(cv::CAP_PROP_FRAME_WIDTH)); -+ int actualHeight = int(capture_.get(cv::CAP_PROP_FRAME_HEIGHT)); - if(!resolutionSet || - actualWidth != stereoModel_.left().imageWidth()*(capture2_.isOpened()?1:2) || - actualHeight != stereoModel_.left().imageHeight()) -@@ -244,17 +238,17 @@ bool CameraStereoVideo::init(const std::string & calibrationFolder, const std::s - if(capture_.isOpened()) - { - bool resolutionSet = false; -- resolutionSet = capture_.set(CV_CAP_PROP_FRAME_WIDTH, _width*(capture2_.isOpened()?1:2)); -- resolutionSet = resolutionSet && capture_.set(CV_CAP_PROP_FRAME_HEIGHT, _height); -+ resolutionSet = capture_.set(cv::CAP_PROP_FRAME_WIDTH, _width*(capture2_.isOpened()?1:2)); -+ resolutionSet = resolutionSet && capture_.set(cv::CAP_PROP_FRAME_HEIGHT, _height); - if(capture2_.isOpened()) - { -- resolutionSet = resolutionSet && capture2_.set(CV_CAP_PROP_FRAME_WIDTH, _width); -- resolutionSet = resolutionSet && capture2_.set(CV_CAP_PROP_FRAME_HEIGHT, _height); -+ resolutionSet = resolutionSet && capture2_.set(cv::CAP_PROP_FRAME_WIDTH, _width); -+ resolutionSet = resolutionSet && capture2_.set(cv::CAP_PROP_FRAME_HEIGHT, _height); - } - - // Check if the resolution was set successfully -- int actualWidth = int(capture_.get(CV_CAP_PROP_FRAME_WIDTH)); -- int actualHeight = int(capture_.get(CV_CAP_PROP_FRAME_HEIGHT)); -+ int actualWidth = int(capture_.get(cv::CAP_PROP_FRAME_WIDTH)); -+ int actualHeight = int(capture_.get(cv::CAP_PROP_FRAME_HEIGHT)); - if(!resolutionSet || - actualWidth != _width*(capture2_.isOpened()?1:2) || - actualHeight != _height) -@@ -273,10 +267,10 @@ bool CameraStereoVideo::init(const std::string & calibrationFolder, const std::s - if (this->getFrameRate() > 0) - { - bool fpsSupported = false; -- fpsSupported = capture_.set(CV_CAP_PROP_FPS, this->getFrameRate()); -+ fpsSupported = capture_.set(cv::CAP_PROP_FPS, this->getFrameRate()); - if (capture2_.isOpened()) - { -- fpsSupported = fpsSupported && capture2_.set(CV_CAP_PROP_FPS, this->getFrameRate()); -+ fpsSupported = fpsSupported && capture2_.set(cv::CAP_PROP_FPS, this->getFrameRate()); - } - if(fpsSupported) - { -@@ -310,14 +304,14 @@ bool CameraStereoVideo::init(const std::string & calibrationFolder, const std::s - std::string fourccUpperCase = uToUpperCase(_fourcc); - int fourcc = cv::VideoWriter::fourcc(fourccUpperCase.at(0), fourccUpperCase.at(1), fourccUpperCase.at(2), fourccUpperCase.at(3)); - bool fourccSupported = false; -- fourccSupported = capture_.set(CV_CAP_PROP_FOURCC, fourcc); -+ fourccSupported = capture_.set(cv::CAP_PROP_FOURCC, fourcc); - if (capture2_.isOpened()) - { -- fourccSupported = fourccSupported && capture2_.set(CV_CAP_PROP_FOURCC, fourcc); -+ fourccSupported = fourccSupported && capture2_.set(cv::CAP_PROP_FOURCC, fourcc); - } - - // Check if the FOURCC was set successfully -- int actualFourcc = int(capture_.get(CV_CAP_PROP_FOURCC)); -+ int actualFourcc = int(capture_.get(cv::CAP_PROP_FOURCC)); - - if(!fourccSupported || actualFourcc != fourcc) - { -@@ -386,7 +380,7 @@ SensorData CameraStereoVideo::captureImage(SensorCaptureInfo * info) - if(rightImage.type() != CV_8UC1 && rightGrayScale_) - { - cv::Mat tmp; -- cv::cvtColor(rightImage, tmp, CV_BGR2GRAY); -+ cv::cvtColor(rightImage, tmp, cv::COLOR_BGR2GRAY); - rightImage = tmp; - rightCvt = true; - } -diff --git a/corelib/src/camera/CameraStereoZedOC.cpp b/corelib/src/camera/CameraStereoZedOC.cpp -index 014976a..e3ba6d4 100644 ---- a/corelib/src/camera/CameraStereoZedOC.cpp -+++ b/corelib/src/camera/CameraStereoZedOC.cpp -@@ -38,6 +38,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include "SimpleIni.h" - -+#if CV_MAJOR_VERSION >= 5 -+#include -+#endif -+ - /////////////////////////////////////////////////////////////////////////// - // - // Copyright (c) 2018, STEREOLABS. -diff --git a/corelib/src/camera/CameraVideo.cpp b/corelib/src/camera/CameraVideo.cpp -index 9a0a70d..1776bca 100644 ---- a/corelib/src/camera/CameraVideo.cpp -+++ b/corelib/src/camera/CameraVideo.cpp -@@ -28,12 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#if CV_MAJOR_VERSION > 3 --#include --#if CV_MAJOR_VERSION > 4 --#include --#endif --#endif -+#include - - namespace rtabmap - { -@@ -105,7 +100,7 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string - { - if (_guid.empty()) - { -- unsigned int guid = (unsigned int)_capture.get(CV_CAP_PROP_GUID); -+ unsigned int guid = (unsigned int)_capture.get(cv::CAP_PROP_GUID); - if (guid != 0 && guid != 0xffffffff) - { - _guid = uFormat("%08x", guid); -@@ -143,12 +138,12 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string - } - - bool resolutionSet = false; -- resolutionSet = _capture.set(CV_CAP_PROP_FRAME_WIDTH, _model.imageWidth()); -- resolutionSet = resolutionSet && _capture.set(CV_CAP_PROP_FRAME_HEIGHT, _model.imageHeight()); -+ resolutionSet = _capture.set(cv::CAP_PROP_FRAME_WIDTH, _model.imageWidth()); -+ resolutionSet = resolutionSet && _capture.set(cv::CAP_PROP_FRAME_HEIGHT, _model.imageHeight()); - - // Check if the resolution was set successfully -- int actualWidth = int(_capture.get(CV_CAP_PROP_FRAME_WIDTH)); -- int actualHeight = int(_capture.get(CV_CAP_PROP_FRAME_HEIGHT)); -+ int actualWidth = int(_capture.get(cv::CAP_PROP_FRAME_WIDTH)); -+ int actualHeight = int(_capture.get(cv::CAP_PROP_FRAME_HEIGHT)); - if(!resolutionSet || - actualWidth != _model.imageWidth() || - actualHeight != _model.imageHeight()) -@@ -165,12 +160,12 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string - else if(_width > 0 && _height > 0) - { - int resolutionSet = false; -- resolutionSet = _capture.set(CV_CAP_PROP_FRAME_WIDTH, _width); -- resolutionSet = resolutionSet && _capture.set(CV_CAP_PROP_FRAME_HEIGHT, _height); -+ resolutionSet = _capture.set(cv::CAP_PROP_FRAME_WIDTH, _width); -+ resolutionSet = resolutionSet && _capture.set(cv::CAP_PROP_FRAME_HEIGHT, _height); - - // Check if the resolution was set successfully -- int actualWidth = int(_capture.get(CV_CAP_PROP_FRAME_WIDTH)); -- int actualHeight = int(_capture.get(CV_CAP_PROP_FRAME_HEIGHT)); -+ int actualWidth = int(_capture.get(cv::CAP_PROP_FRAME_WIDTH)); -+ int actualHeight = int(_capture.get(cv::CAP_PROP_FRAME_HEIGHT)); - if(!resolutionSet || actualWidth != _width || actualHeight != _height) - { - UWARN("Desired resolution (%dx%d) cannot be set to camera driver, " -@@ -182,7 +177,7 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string - } - - // Set FPS -- if (this->getFrameRate() > 0 && _capture.set(CV_CAP_PROP_FPS, this->getFrameRate())) -+ if (this->getFrameRate() > 0 && _capture.set(cv::CAP_PROP_FPS, this->getFrameRate())) - { - // Check if the FPS was set successfully - double actualFPS = _capture.get(cv::CAP_PROP_FPS); -@@ -213,10 +208,10 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string - std::string fourccUpperCase = uToUpperCase(_fourcc); - int fourcc = cv::VideoWriter::fourcc(fourccUpperCase.at(0), fourccUpperCase.at(1), fourccUpperCase.at(2), fourccUpperCase.at(3)); - -- bool fourccSupported = _capture.set(CV_CAP_PROP_FOURCC, fourcc); -+ bool fourccSupported = _capture.set(cv::CAP_PROP_FOURCC, fourcc); - - // Check if the FOURCC was set successfully -- int actualFourcc = int(_capture.get(CV_CAP_PROP_FOURCC)); -+ int actualFourcc = int(_capture.get(cv::CAP_PROP_FOURCC)); - - if(!fourccSupported || actualFourcc != fourcc) - { -diff --git a/corelib/src/odometry/OdometryDVO.cpp b/corelib/src/odometry/OdometryDVO.cpp -index 2f7190d..a1e425d 100644 ---- a/corelib/src/odometry/OdometryDVO.cpp -+++ b/corelib/src/odometry/OdometryDVO.cpp -@@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/ULogger.h" - #include "rtabmap/utilite/UTimer.h" - #include "rtabmap/utilite/UStl.h" --#include - - #ifdef RTABMAP_DVO - #include -@@ -124,7 +123,7 @@ Transform OdometryDVO::computeTransform( - { - if(data.imageRaw().type() == CV_8UC3) - { -- cv::cvtColor(data.imageRaw(), grey, CV_BGR2GRAY); -+ cv::cvtColor(data.imageRaw(), grey, cv::COLOR_BGR2GRAY); - } - else - { -diff --git a/corelib/src/odometry/OdometryF2M.cpp b/corelib/src/odometry/OdometryF2M.cpp -index 58d0e3a..63b096d 100644 ---- a/corelib/src/odometry/OdometryF2M.cpp -+++ b/corelib/src/odometry/OdometryF2M.cpp -@@ -42,7 +42,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UTimer.h" - #include "rtabmap/utilite/UMath.h" - #include "rtabmap/utilite/UConversion.h" -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - -diff --git a/corelib/src/odometry/OdometryFovis.cpp b/corelib/src/odometry/OdometryFovis.cpp -index 673639a..c1f5a99 100644 ---- a/corelib/src/odometry/OdometryFovis.cpp -+++ b/corelib/src/odometry/OdometryFovis.cpp -@@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/ULogger.h" - #include "rtabmap/utilite/UTimer.h" - #include "rtabmap/utilite/UStl.h" --#include - - #ifdef RTABMAP_FOVIS - #include -@@ -137,7 +136,7 @@ Transform OdometryFovis::computeTransform( - cv::Mat gray; - if(data.imageRaw().type() == CV_8UC3) - { -- cv::cvtColor(data.imageRaw(), gray, CV_BGR2GRAY); -+ cv::cvtColor(data.imageRaw(), gray, cv::COLOR_BGR2GRAY); - } - else if(data.imageRaw().type() == CV_8UC1) - { -@@ -302,7 +301,7 @@ Transform OdometryFovis::computeTransform( - } - if(data.rightRaw().type() == CV_8UC3) - { -- cv::cvtColor(data.rightRaw(), right, CV_BGR2GRAY); -+ cv::cvtColor(data.rightRaw(), right, cv::COLOR_BGR2GRAY); - } - else if(data.rightRaw().type() == CV_8UC1) - { -diff --git a/corelib/src/odometry/OdometryMSCKF.cpp b/corelib/src/odometry/OdometryMSCKF.cpp -index ac62c25..709f9d1 100644 ---- a/corelib/src/odometry/OdometryMSCKF.cpp -+++ b/corelib/src/odometry/OdometryMSCKF.cpp -@@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UTimer.h" - #include "rtabmap/utilite/UStl.h" - #include "rtabmap/utilite/UThread.h" --#include - - #ifdef RTABMAP_MSCKF_VIO - #include -@@ -867,7 +866,7 @@ Transform OdometryMSCKF::computeTransform( - - if(data.imageRaw().type() == CV_8UC3) - { -- cv::cvtColor(data.imageRaw(), cam0.image, CV_BGR2GRAY); -+ cv::cvtColor(data.imageRaw(), cam0.image, cv::COLOR_BGR2GRAY); - } - else - { -@@ -875,7 +874,7 @@ Transform OdometryMSCKF::computeTransform( - } - if(data.rightRaw().type() == CV_8UC3) - { -- cv::cvtColor(data.rightRaw(), cam1.image, CV_BGR2GRAY); -+ cv::cvtColor(data.rightRaw(), cam1.image, cv::COLOR_BGR2GRAY); - } - else - { -diff --git a/corelib/src/odometry/OdometryMono.cpp b/corelib/src/odometry/OdometryMono.cpp -index b942aa8..e29e2e2 100644 ---- a/corelib/src/odometry/OdometryMono.cpp -+++ b/corelib/src/odometry/OdometryMono.cpp -@@ -43,7 +43,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UStl.h" - #include "rtabmap/utilite/UMath.h" - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - -diff --git a/corelib/src/odometry/OdometryORBSLAM2.cpp b/corelib/src/odometry/OdometryORBSLAM2.cpp -index 1ae10bc..616678c 100644 ---- a/corelib/src/odometry/OdometryORBSLAM2.cpp -+++ b/corelib/src/odometry/OdometryORBSLAM2.cpp -@@ -33,7 +33,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UStl.h" - #include "rtabmap/utilite/UDirectory.h" - #include --#include - #include - - #if defined(RTABMAP_ORB_SLAM) and RTABMAP_ORB_SLAM == 2 -@@ -426,7 +425,7 @@ public: - } - else - { -- cvtColor(mImGray,mImGray,CV_BGR2GRAY); -+ cvtColor(mImGray,mImGray,cv::COLOR_BGR2GRAY); - } - } - else if(mImGray.channels()==4) -@@ -437,7 +436,7 @@ public: - } - else - { -- cvtColor(mImGray,mImGray,CV_BGRA2GRAY); -+ cvtColor(mImGray,mImGray,cv::COLOR_BGRA2GRAY); - } - } - if(imGrayRight.channels()==3) -@@ -448,7 +447,7 @@ public: - } - else - { -- cvtColor(imGrayRight,imGrayRight,CV_BGR2GRAY); -+ cvtColor(imGrayRight,imGrayRight,cv::COLOR_BGR2GRAY); - } - } - else if(imGrayRight.channels()==4) -@@ -459,7 +458,7 @@ public: - } - else - { -- cvtColor(imGrayRight,imGrayRight,CV_BGRA2GRAY); -+ cvtColor(imGrayRight,imGrayRight,cv::COLOR_BGRA2GRAY); - } - } - -@@ -480,14 +479,14 @@ public: - if(mbRGB) - cvtColor(mImGray,mImGray,CV_RGB2GRAY); - else -- cvtColor(mImGray,mImGray,CV_BGR2GRAY); -+ cvtColor(mImGray,mImGray,cv::COLOR_BGR2GRAY); - } - else if(mImGray.channels()==4) - { - if(mbRGB) - cvtColor(mImGray,mImGray,CV_RGBA2GRAY); - else -- cvtColor(mImGray,mImGray,CV_BGRA2GRAY); -+ cvtColor(mImGray,mImGray,cv::COLOR_BGRA2GRAY); - } - - UASSERT(imDepth.type()==CV_32F); -diff --git a/corelib/src/odometry/OdometryORBSLAM3.cpp b/corelib/src/odometry/OdometryORBSLAM3.cpp -index f0e5d64..77e7d45 100644 ---- a/corelib/src/odometry/OdometryORBSLAM3.cpp -+++ b/corelib/src/odometry/OdometryORBSLAM3.cpp -@@ -34,7 +34,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UDirectory.h" - #include "rtabmap/utilite/UFile.h" - #include --#include - #include - - #if defined(RTABMAP_ORB_SLAM) and RTABMAP_ORB_SLAM == 3 -@@ -469,12 +468,12 @@ Transform OdometryORBSLAM3::computeTransform( - cv::Mat leftMono = data.imageRaw(); - if(data.imageRaw().channels() == 3) { - leftMono = cv::Mat(); -- cv::cvtColor(data.imageRaw(), leftMono, CV_BGR2GRAY); -+ cv::cvtColor(data.imageRaw(), leftMono, cv::COLOR_BGR2GRAY); - } - cv::Mat rightMono = data.rightRaw(); - if(data.rightRaw().channels() == 3) { - rightMono = cv::Mat(); -- cv::cvtColor(data.imageRaw(), rightMono, CV_BGR2GRAY); -+ cv::cvtColor(data.imageRaw(), rightMono, cv::COLOR_BGR2GRAY); - } - UDEBUG("Adding Stereo Frame %f", data.stamp()); - Tcw = orbslam_->TrackStereo(leftMono, rightMono, data.stamp(), orbslamImus_); -diff --git a/corelib/src/odometry/OdometryOkvis.cpp b/corelib/src/odometry/OdometryOkvis.cpp -index 10497b9..7c97e27 100644 ---- a/corelib/src/odometry/OdometryOkvis.cpp -+++ b/corelib/src/odometry/OdometryOkvis.cpp -@@ -34,7 +34,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UThread.h" - #include "rtabmap/utilite/UFile.h" - #include "rtabmap/utilite/UDirectory.h" --#include - - #ifdef RTABMAP_OKVIS - #include -@@ -427,7 +426,7 @@ Transform OdometryOkvis::computeTransform( - cv::Mat gray; - if(images[i].type() == CV_8UC3) - { -- cv::cvtColor(images[i], gray, CV_BGR2GRAY); -+ cv::cvtColor(images[i], gray, cv::COLOR_BGR2GRAY); - } - else if(images[i].type() == CV_8UC1) - { -diff --git a/corelib/src/odometry/OdometryOpenVINS.cpp b/corelib/src/odometry/OdometryOpenVINS.cpp -index e953968..4c9dcc4 100644 ---- a/corelib/src/odometry/OdometryOpenVINS.cpp -+++ b/corelib/src/odometry/OdometryOpenVINS.cpp -@@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/ULogger.h" - #include "rtabmap/utilite/UTimer.h" - #include --#include - - #ifdef RTABMAP_OPENVINS - #include "core/VioManager.h" -@@ -419,7 +418,7 @@ Transform OdometryOpenVINS::computeTransform( - - cv::Mat image; - if(data.imageRaw().type() == CV_8UC3) -- cv::cvtColor(data.imageRaw(), image, CV_BGR2GRAY); -+ cv::cvtColor(data.imageRaw(), image, cv::COLOR_BGR2GRAY); - else if(data.imageRaw().type() == CV_8UC1) - image = data.imageRaw().clone(); - else -@@ -450,7 +449,7 @@ Transform OdometryOpenVINS::computeTransform( - if(!data.rightRaw().empty()) - { - if(data.rightRaw().type() == CV_8UC3) -- cv::cvtColor(data.rightRaw(), image, CV_BGR2GRAY); -+ cv::cvtColor(data.rightRaw(), image, cv::COLOR_BGR2GRAY); - else if(data.rightRaw().type() == CV_8UC1) - image = data.rightRaw().clone(); - else -diff --git a/corelib/src/odometry/OdometryVINSFusion.cpp b/corelib/src/odometry/OdometryVINSFusion.cpp -index 9c63360..9677940 100644 ---- a/corelib/src/odometry/OdometryVINSFusion.cpp -+++ b/corelib/src/odometry/OdometryVINSFusion.cpp -@@ -33,7 +33,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UStl.h" - #include "rtabmap/utilite/UThread.h" - #include "rtabmap/utilite/UDirectory.h" --#include - - #ifdef RTABMAP_VINS_FUSION - #include -@@ -444,7 +443,7 @@ Transform OdometryVINSFusion::computeTransform( - cv::Mat right; - if(data.imageRaw().type() == CV_8UC3) - { -- cv::cvtColor(data.imageRaw(), left, CV_BGR2GRAY); -+ cv::cvtColor(data.imageRaw(), left, cv::COLOR_BGR2GRAY); - } - else if(data.imageRaw().type() == CV_8UC1) - { -@@ -456,7 +455,7 @@ Transform OdometryVINSFusion::computeTransform( - } - if(data.rightRaw().type() == CV_8UC3) - { -- cv::cvtColor(data.rightRaw(), right, CV_BGR2GRAY); -+ cv::cvtColor(data.rightRaw(), right, cv::COLOR_BGR2GRAY); - } - else if(data.rightRaw().type() == CV_8UC1) - { -diff --git a/corelib/src/odometry/OdometryViso2.cpp b/corelib/src/odometry/OdometryViso2.cpp -index 808e763..dc6192b 100644 ---- a/corelib/src/odometry/OdometryViso2.cpp -+++ b/corelib/src/odometry/OdometryViso2.cpp -@@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/ULogger.h" - #include "rtabmap/utilite/UTimer.h" - #include "rtabmap/utilite/UStl.h" --#include - - #ifdef RTABMAP_VISO2 - #include -@@ -131,7 +130,7 @@ Transform OdometryViso2::computeTransform( - cv::Mat leftGray; - if(data.imageRaw().type() == CV_8UC3) - { -- cv::cvtColor(data.imageRaw(), leftGray, CV_BGR2GRAY); -+ cv::cvtColor(data.imageRaw(), leftGray, cv::COLOR_BGR2GRAY); - } - else if(data.imageRaw().type() == CV_8UC1) - { -@@ -144,7 +143,7 @@ Transform OdometryViso2::computeTransform( - cv::Mat rightGray; - if(data.rightRaw().type() == CV_8UC3) - { -- cv::cvtColor(data.rightRaw(), rightGray, CV_BGR2GRAY); -+ cv::cvtColor(data.rightRaw(), rightGray, cv::COLOR_BGR2GRAY); - } - else if(data.rightRaw().type() == CV_8UC1) - { -diff --git a/corelib/src/opencv/ORBextractor.cc b/corelib/src/opencv/ORBextractor.cc -index 2d3cd7c..542e169 100644 ---- a/corelib/src/opencv/ORBextractor.cc -+++ b/corelib/src/opencv/ORBextractor.cc -@@ -64,7 +64,11 @@ - - #include - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - #include -diff --git a/corelib/src/opencv/ORBextractor.h b/corelib/src/opencv/ORBextractor.h -index 861ca05..82ede5b 100644 ---- a/corelib/src/opencv/ORBextractor.h -+++ b/corelib/src/opencv/ORBextractor.h -@@ -31,8 +31,6 @@ - - #include - #include --#include -- - - namespace rtabmap - { -diff --git a/corelib/src/opencv/Orb.cpp b/corelib/src/opencv/Orb.cpp -index f56874e..c5034a7 100644 ---- a/corelib/src/opencv/Orb.cpp -+++ b/corelib/src/opencv/Orb.cpp -@@ -40,7 +40,6 @@ - - #include "opencv2/features2d/features2d.hpp" - #include "opencv2/imgproc/imgproc.hpp" --#include "opencv2/imgproc/imgproc_c.h" - #include - #include - -@@ -252,7 +251,7 @@ static void computeOrbDescriptor(const KeyPoint& kpt, - } - } - else -- CV_Error( CV_StsBadSize, "Wrong WTA_K. It can be only 2, 3 or 4." ); -+ CV_Error( cv::Error::StsBadSize, "Wrong WTA_K. It can be only 2, 3 or 4." ); - - #undef GET_VALUE - } -@@ -752,7 +751,7 @@ void CV_ORB::operator()( InputArray _image, InputArray _mask, std::vectornlevels; - -diff --git a/corelib/src/opencv/five-point.h b/corelib/src/opencv/five-point.h -index 1a5b778..f1aa8c7 100644 ---- a/corelib/src/opencv/five-point.h -+++ b/corelib/src/opencv/five-point.h -@@ -8,6 +8,10 @@ - #ifndef CORELIB_SRC_OPENCV_FIVE_POINT_H_ - #define CORELIB_SRC_OPENCV_FIVE_POINT_H_ - -+#if CV_MAJOR_VERSION > 4 -+#include -+#endif -+ - namespace cv3 - { - -diff --git a/corelib/src/opencv/solvepnp.cpp b/corelib/src/opencv/solvepnp.cpp -index f5b3a07..ecd2be9 100644 ---- a/corelib/src/opencv/solvepnp.cpp -+++ b/corelib/src/opencv/solvepnp.cpp -@@ -53,7 +53,7 @@ class PnPRansacCallback : public PointSetRegistrator::Callback - - public: - -- PnPRansacCallback(Mat _cameraMatrix=Mat(3,3,CV_64F), Mat _distCoeffs=Mat(4,1,CV_64F), int _flags=CV_ITERATIVE, -+ PnPRansacCallback(Mat _cameraMatrix=Mat(3,3,CV_64F), Mat _distCoeffs=Mat(4,1,CV_64F), int _flags=cv::SOLVEPNP_ITERATIVE, - bool _useExtrinsicGuess=false, Mat _rvec=Mat(), Mat _tvec=Mat() ) - : cameraMatrix(_cameraMatrix), distCoeffs(_distCoeffs), flags(_flags), useExtrinsicGuess(_useExtrinsicGuess), - rvec(_rvec), tvec(_tvec) {} -@@ -142,12 +142,12 @@ bool solvePnPRansac(InputArray _opoints, InputArray _ipoints, - Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat(); - - int model_points = 6; -- int ransac_kernel_method = CV_EPNP; -+ int ransac_kernel_method = cv::SOLVEPNP_EPNP; - - if( npoints == 4 ) - { - model_points = 4; -- ransac_kernel_method = CV_P3P; -+ ransac_kernel_method = cv::SOLVEPNP_P3P; - } - - Ptr cb; // pointer to callback -@@ -178,7 +178,7 @@ bool solvePnPRansac(InputArray _opoints, InputArray _ipoints, - opoints_inliers.resize(npoints1); - ipoints_inliers.resize(npoints1); - result = solvePnP(opoints_inliers, ipoints_inliers, cameraMatrix, -- distCoeffs, rvec, tvec, useExtrinsicGuess, flags == CV_P3P ? CV_EPNP : flags) ? 1 : -1; -+ distCoeffs, rvec, tvec, useExtrinsicGuess, flags == cv::SOLVEPNP_P3P ? cv::SOLVEPNP_EPNP : flags) ? 1 : -1; - } - - if( result <= 0 || _local_model.rows <= 0) -@@ -213,7 +213,7 @@ bool solvePnPRansac(InputArray _opoints, InputArray _ipoints, - int RANSACUpdateNumIters( double p, double ep, int modelPoints, int maxIters ) - { - if( modelPoints <= 0 ) -- CV_Error( 0, "the number of model points should be positive" ); -+ CV_Error( cv::Error::Code::StsBadArg, "the number of model points should be positive" ); - - p = MAX(p, 0.); - p = MIN(p, 1.); -diff --git a/corelib/src/opencv/solvepnp.h b/corelib/src/opencv/solvepnp.h -index e88b570..382f9db 100644 ---- a/corelib/src/opencv/solvepnp.h -+++ b/corelib/src/opencv/solvepnp.h -@@ -45,9 +45,10 @@ - #define RTABMAP_CORELIB_SRC_OPENCV_SOLVEPNP_H_ - - #include -+#if CV_MAJOR_VERSION >= 5 -+#include -+#else - #include --#if CV_MAJOR_VERSION >= 3 --#include - #endif - - namespace cv3 { -@@ -95,7 +96,7 @@ bool solvePnPRansac( cv::InputArray objectPoints, cv::InputArray imagePoints, - cv::OutputArray rvec, cv::OutputArray tvec, - bool useExtrinsicGuess = false, int iterationsCount = 100, - float reprojectionError = 8.0, double confidence = 0.99, -- cv::OutputArray inliers = cv::noArray(), int flags = CV_ITERATIVE ); -+ cv::OutputArray inliers = cv::noArray(), int flags = cv::SOLVEPNP_ITERATIVE ); - - int RANSACUpdateNumIters( double p, double ep, int modelPoints, int maxIters ); - -diff --git a/corelib/src/optimizer/OptimizerCeres.cpp b/corelib/src/optimizer/OptimizerCeres.cpp -index 046d401..d2d64c3 100644 ---- a/corelib/src/optimizer/OptimizerCeres.cpp -+++ b/corelib/src/optimizer/OptimizerCeres.cpp -@@ -26,6 +26,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - #include "rtabmap/core/Graph.h" - -+#if CV_MAJOR_VERSION < 5 -+#include -+#else -+#include -+#endif -+ - #include - #include - #include -diff --git a/corelib/src/stereo/StereoBM.cpp b/corelib/src/stereo/StereoBM.cpp -index 1b390c6..57f6b7d 100644 ---- a/corelib/src/stereo/StereoBM.cpp -+++ b/corelib/src/stereo/StereoBM.cpp -@@ -27,9 +27,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#include -+#endif - #include --#include - - namespace rtabmap { - -@@ -88,7 +92,7 @@ cv::Mat StereoBM::computeDisparity( - cv::Mat leftMono; - if(leftImage.channels() == 3) - { -- cv::cvtColor(leftImage, leftMono, CV_BGR2GRAY); -+ cv::cvtColor(leftImage, leftMono, cv::COLOR_BGR2GRAY); - } - else - { -@@ -98,7 +102,7 @@ cv::Mat StereoBM::computeDisparity( - cv::Mat rightMono; - if(rightImage.channels() == 3) - { -- cv::cvtColor(rightImage, rightMono, CV_BGR2GRAY); -+ cv::cvtColor(rightImage, rightMono, cv::COLOR_BGR2GRAY); - } - else - { -diff --git a/corelib/src/stereo/StereoSGBM.cpp b/corelib/src/stereo/StereoSGBM.cpp -index 6763aeb..d8e651a 100644 ---- a/corelib/src/stereo/StereoSGBM.cpp -+++ b/corelib/src/stereo/StereoSGBM.cpp -@@ -27,9 +27,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#include -+#endif - #include --#include - - namespace rtabmap { - -@@ -77,7 +81,7 @@ cv::Mat StereoSGBM::computeDisparity( - cv::Mat leftMono; - if(leftImage.channels() == 3) - { -- cv::cvtColor(leftImage, leftMono, CV_BGR2GRAY); -+ cv::cvtColor(leftImage, leftMono, cv::COLOR_BGR2GRAY); - } - else - { -@@ -87,7 +91,7 @@ cv::Mat StereoSGBM::computeDisparity( - cv::Mat rightMono; - if(rightImage.channels() == 3) - { -- cv::cvtColor(rightImage, rightMono, CV_BGR2GRAY); -+ cv::cvtColor(rightImage, rightMono, cv::COLOR_BGR2GRAY); - } - else - { -diff --git a/corelib/src/util2d.cpp b/corelib/src/util2d.cpp -index 0251d0f..0c9318f 100644 ---- a/corelib/src/util2d.cpp -+++ b/corelib/src/util2d.cpp -@@ -34,11 +34,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - #include - #include - #include --#include - #include - #include - -@@ -46,6 +44,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #endif - -+#if CV_MAJOR_VERSION < 5 -+#include -+#else -+#include -+#endif -+ - namespace rtabmap - { - -@@ -747,7 +751,7 @@ cv::Mat disparityFromStereoImages( - cv::Mat leftMono; - if(leftImage.channels() == 3) - { -- cv::cvtColor(leftImage, leftMono, CV_BGR2GRAY); -+ cv::cvtColor(leftImage, leftMono, cv::COLOR_BGR2GRAY); - } - else - { -@@ -2042,8 +2046,8 @@ cv::Mat brightnessAndContrastAuto(const cv::Mat &src, const cv::Mat & mask, floa - //to calculate grayscale histogram - cv::Mat gray; - if (src.type() == CV_8UC1) gray = src; -- else if (src.type() == CV_8UC3) cvtColor(src, gray, CV_BGR2GRAY); -- else if (src.type() == CV_8UC4) cvtColor(src, gray, CV_BGRA2GRAY); -+ else if (src.type() == CV_8UC3) cvtColor(src, gray, cv::COLOR_BGR2GRAY); -+ else if (src.type() == CV_8UC4) cvtColor(src, gray, cv::COLOR_BGRA2GRAY); - if (clipLowHistPercent == 0 && clipHighHistPercent == 0) - { - // keep full available range -diff --git a/corelib/src/util3d.cpp b/corelib/src/util3d.cpp -index facb0d6..dfad02a 100644 ---- a/corelib/src/util3d.cpp -+++ b/corelib/src/util3d.cpp -@@ -41,7 +41,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - - namespace rtabmap - { -@@ -892,7 +891,7 @@ pcl::PointCloud::Ptr cloudFromStereoImages( - cv::Mat leftMono; - if(leftColor.channels() == 3) - { -- cv::cvtColor(leftColor, leftMono, CV_BGR2GRAY); -+ cv::cvtColor(leftColor, leftMono, cv::COLOR_BGR2GRAY); - } - else - { -@@ -902,7 +901,7 @@ pcl::PointCloud::Ptr cloudFromStereoImages( - cv::Mat rightMono; - if(rightColor.channels() == 3) - { -- cv::cvtColor(rightColor, rightMono, CV_BGR2GRAY); -+ cv::cvtColor(rightColor, rightMono, cv::COLOR_BGR2GRAY); - } - else - { -@@ -1038,7 +1037,7 @@ std::vector::Ptr> cloudsFromSensorData( - cv::Mat leftMono; - if(sensorData.imageRaw().channels() == 3) - { -- cv::cvtColor(sensorData.imageRaw(), leftMono, CV_BGR2GRAY); -+ cv::cvtColor(sensorData.imageRaw(), leftMono, cv::COLOR_BGR2GRAY); - } - else - { -@@ -1048,7 +1047,7 @@ std::vector::Ptr> cloudsFromSensorData( - cv::Mat rightMono; - if(sensorData.rightRaw().channels() == 3) - { -- cv::cvtColor(sensorData.rightRaw(), rightMono, CV_BGR2GRAY); -+ cv::cvtColor(sensorData.rightRaw(), rightMono, cv::COLOR_BGR2GRAY); - } - else - { -diff --git a/corelib/src/util3d_correspondences.cpp b/corelib/src/util3d_correspondences.cpp -index 5a81869..41cc1e6 100644 ---- a/corelib/src/util3d_correspondences.cpp -+++ b/corelib/src/util3d_correspondences.cpp -@@ -30,7 +30,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - #include - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - -diff --git a/corelib/src/util3d_surface.cpp b/corelib/src/util3d_surface.cpp -index bccae36..3625426 100644 ---- a/corelib/src/util3d_surface.cpp -+++ b/corelib/src/util3d_surface.cpp -@@ -39,8 +39,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UConversion.h" - #include "rtabmap/utilite/UMath.h" - #include "rtabmap/utilite/UTimer.h" --#include --#include - #include - #include - #include -@@ -1745,7 +1743,7 @@ cv::Mat mergeTextures( - if(resizedImage.type() == CV_8UC1) - { - cv::Mat resizedImageColor; -- cv::cvtColor(resizedImage, resizedImageColor, CV_GRAY2BGR); -+ cv::cvtColor(resizedImage, resizedImageColor, cv::COLOR_GRAY2BGR); - resizedImage = resizedImageColor; - } - UASSERT(resizedImage.type() == globalTextures.type()); -@@ -2609,7 +2607,7 @@ bool multiBandTexturing( - if(imageRoi.channels() == 1) - { - cv::Mat imageRoiColor; -- cv::cvtColor(imageRoi, imageRoiColor, CV_GRAY2BGR); -+ cv::cvtColor(imageRoi, imageRoiColor, cv::COLOR_GRAY2BGR); - imageRoi = imageRoiColor; - } - -@@ -3218,7 +3216,7 @@ float computeNormalsComplexity( - } - if(oi>1) - { -- cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), CV_PCA_DATA_AS_ROW); -+ cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), cv::PCA::DATA_AS_ROW); - - if(pcaEigenVectors) - { -@@ -3279,7 +3277,7 @@ float computeNormalsComplexity( - } - if(oi>1) - { -- cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), CV_PCA_DATA_AS_ROW); -+ cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), cv::PCA::DATA_AS_ROW); - - if(pcaEigenVectors) - { -@@ -3335,7 +3333,7 @@ float computeNormalsComplexity( - } - if(oi>1) - { -- cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), CV_PCA_DATA_AS_ROW); -+ cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), cv::PCA::DATA_AS_ROW); - - if(pcaEigenVectors) - { -@@ -3391,7 +3389,7 @@ float computeNormalsComplexity( - } - if(oi>1) - { -- cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), CV_PCA_DATA_AS_ROW); -+ cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), cv::PCA::DATA_AS_ROW); - - if(pcaEigenVectors) - { -@@ -3447,7 +3445,7 @@ float computeNormalsComplexity( - } - if(oi>1) - { -- cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), CV_PCA_DATA_AS_ROW); -+ cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), cv::PCA::DATA_AS_ROW); - - if(pcaEigenVectors) - { -diff --git a/guilib/include/rtabmap/gui/DatabaseViewer.h b/guilib/include/rtabmap/gui/DatabaseViewer.h -index 07f9494..bcd6735 100644 ---- a/guilib/include/rtabmap/gui/DatabaseViewer.h -+++ b/guilib/include/rtabmap/gui/DatabaseViewer.h -@@ -36,7 +36,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include - #include -diff --git a/guilib/include/rtabmap/gui/ImageView.h b/guilib/include/rtabmap/gui/ImageView.h -index 8e8df85..95e4ff8 100644 ---- a/guilib/include/rtabmap/gui/ImageView.h -+++ b/guilib/include/rtabmap/gui/ImageView.h -@@ -34,7 +34,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include -+#include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include - #include "rtabmap/utilite/UCv2Qt.h" - #include -diff --git a/guilib/include/rtabmap/gui/KeypointItem.h b/guilib/include/rtabmap/gui/KeypointItem.h -index 7f4f9f6..30db5c3 100644 ---- a/guilib/include/rtabmap/gui/KeypointItem.h -+++ b/guilib/include/rtabmap/gui/KeypointItem.h -@@ -34,7 +34,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include -+#include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - - namespace rtabmap { - -diff --git a/guilib/src/CalibrationDialog.cpp b/guilib/src/CalibrationDialog.cpp -index f6b27fe..3fd4530 100644 ---- a/guilib/src/CalibrationDialog.cpp -+++ b/guilib/src/CalibrationDialog.cpp -@@ -28,15 +28,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/gui/CalibrationDialog.h" - #include "ui_calibrationDialog.h" - -+#include - #include - #include --#include -+#if CV_MAJOR_VERSION >= 5 -+#include -+#include -+#else - #include --#if CV_MAJOR_VERSION >= 3 --#include - #endif - #include --#if CV_MAJOR_VERSION > 2 or (CV_MAJOR_VERSION == 2 and (CV_MINOR_VERSION >4 or (CV_MINOR_VERSION == 4 and CV_SUBMINOR_VERSION >=10))) -+#if (CV_MAJOR_VERSION > 2 and CV_MAJOR_VERSION < 5) or (CV_MAJOR_VERSION == 2 and (CV_MINOR_VERSION >4 or (CV_MINOR_VERSION == 4 and CV_SUBMINOR_VERSION >=10))) - #include - #endif - -@@ -276,18 +278,23 @@ void CalibrationDialog::generateBoard() - if(ui_->comboBox_board_type->currentIndex() >= 1 ) - { - try { -+ const int marginInPixels = squareSizeInPixels/4; -+ cv::Size size( -+ squareSizeInPixels*ui_->spinBox_boardWidth->value() + 2*marginInPixels, -+ squareSizeInPixels*ui_->spinBox_boardHeight->value() + 2*marginInPixels); -+ UINFO("Creating board image of %dx%d pixels (%dx%d squares)", -+ size.width, size.height, -+ ui_->spinBox_boardWidth->value(), ui_->spinBox_boardHeight->value()); - #if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7) - charucoBoard_->generateImage( -- cv::Size(squareSizeInPixels*ui_->spinBox_boardWidth->value(), -- squareSizeInPixels*ui_->spinBox_boardHeight->value()), -+ size, - image, -- squareSizeInPixels/4, 1); -+ marginInPixels, 1); - #else - charucoBoard_->draw( -- cv::Size(squareSizeInPixels*ui_->spinBox_boardWidth->value(), -- squareSizeInPixels*ui_->spinBox_boardHeight->value()), -+ size, - image, -- squareSizeInPixels/4, 1); -+ marginInPixels, 1); - #endif - - int arucoDict = ui_->comboBox_marker_dictionary->currentIndex(); -@@ -297,7 +304,7 @@ void CalibrationDialog::generateBoard() - } - catch(const cv::Exception & e) - { -- UERROR("%f", e.what()); -+ UERROR("%s", e.what()); - QMessageBox::critical(this, tr("Generating Board"), - tr("Cannot generate the board. Make sure the dictionary " - "selected is big enough for the board size. Error:\"%1\"").arg(e.what())); -@@ -737,7 +744,7 @@ void CalibrationDialog::processImages(const cv::Mat & imageLeft, const cv::Mat & - cv::Size boardSize(ui_->spinBox_boardWidth->value(), ui_->spinBox_boardHeight->value()); - if(!viewGray.empty()) - { -- int flags = CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE; -+ int flags = cv::CALIB_CB_ADAPTIVE_THRESH | cv::CALIB_CB_NORMALIZE_IMAGE; - - if(!viewGray.empty()) - { -@@ -748,7 +755,7 @@ void CalibrationDialog::processImages(const cv::Mat & imageLeft, const cv::Mat & - if( scale == 1 ) - timg = viewGray; - else -- cv::resize(viewGray, timg, cv::Size(), scale, scale, CV_INTER_CUBIC); -+ cv::resize(viewGray, timg, cv::Size(), scale, scale, cv::INTER_CUBIC); - - #ifdef HAVE_CHARUCO - if(ui_->comboBox_board_type->currentIndex() >= 1 ) -@@ -833,7 +840,7 @@ void CalibrationDialog::processImages(const cv::Mat & imageLeft, const cv::Mat & - float ratio = ui_->comboBox_board_type->currentIndex() >= 1 ?6.0f:2.0f; - float radius = minSquareDistance==-1.0f?5.0f:(minSquareDistance/ratio); - cv::cornerSubPix( viewGray, pointBuf[id], cv::Size(radius, radius), cv::Size(-1,-1), -- cv::TermCriteria( CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1 )); -+ cv::TermCriteria( cv::TermCriteria::EPS + cv::TermCriteria::MAX_ITER, 30, 0.1 )); - - // Filter points that drifted to far (caused by reflection or bad subpixel gradient) - float threshold = ui_->doubleSpinBox_subpixel_error->value(); -@@ -1388,6 +1395,13 @@ void CalibrationDialog::calibrate() - UINFO("Calibrating camera %d (samples=%d)", id, (int)imagePoints_[id].size()); - logStream << "Calibrating camera " << id << " (samples=" << imagePoints_[id].size() << ")" << ENDL; - -+ // Work on local copies: the fisheye auto-prune below removes ill-conditioned views, -+ // and we must NOT mutate the persistent buffers, otherwise clicking Calibrate again -+ // would run on a smaller (already-pruned) sample set and give different results. -+ std::vector > objectPoints = objectPoints_[id]; -+ std::vector > imagePoints = imagePoints_[id]; -+ std::vector imageIds = imageIds_[id]; -+ - //calibrate - std::vector rvecs, tvecs; - std::vector reprojErrs; -@@ -1401,26 +1415,78 @@ void CalibrationDialog::calibrate() - - if(fishEye) - { -- try -- { -- rms = cv::fisheye::calibrate( -- objectPoints_[id], -- imagePoints_[id], -- imageSize_[id], -- K, -- D, -- rvecs, -- tvecs, -- cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC | -- cv::fisheye::CALIB_CHECK_COND | -- cv::fisheye::CALIB_FIX_SKEW); -- } -- catch(const cv::Exception & e) -+ // cv::fisheye::calibrate() with CALIB_CHECK_COND throws as soon as a single -+ // view is ill-conditioned (e.g. too few / poorly spread ChArUco corners), -+ // aborting the whole calibration. Auto-prune the offending view (its index is -+ // reported in the exception message) and retry until it succeeds, keeping the -+ // CHECK_COND safety without discarding every good view. -+ const int minFisheyeViews = COUNT_MIN/2; -+ bool calibrated = false; -+ while(!calibrated) - { -- UERROR("Error: %s (try restarting the calibration)", e.what()); -- QMessageBox::warning(this, tr("Calibration failed!"), tr("Error: %1 (try restarting the calibration)").arg(e.what())); -- processingData_ = false; -- return; -+ try -+ { -+ rms = cv::fisheye::calibrate( -+ objectPoints, -+ imagePoints, -+ imageSize_[id], -+ K, -+ D, -+ rvecs, -+ tvecs, -+ cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC | -+ cv::fisheye::CALIB_CHECK_COND | -+ cv::fisheye::CALIB_FIX_SKEW); -+ calibrated = true; -+ } -+ catch(const cv::Exception & e) -+ { -+ // Parse the ill-conditioned view index, e.g. -+ // "CALIB_CHECK_COND - Ill-conditioned matrix for input array 43" -+ int badIndex = -1; -+ const QString token = "input array "; -+ QString msg = e.what(); -+ int tokenPos = msg.indexOf(token); -+ if(tokenPos >= 0) -+ { -+ bool ok = false; -+ int v = msg.mid(tokenPos + token.length()).section(' ', 0, 0).toInt(&ok); -+ if(ok) -+ { -+ badIndex = v; -+ } -+ } -+ -+ if(badIndex >= 0 && badIndex < (int)objectPoints.size() && -+ (int)objectPoints.size() > minFisheyeViews) -+ { -+ int removedImageId = badIndex < (int)imageIds.size() ? imageIds[badIndex] : -1; -+ UWARN("Fisheye calibration: view %d (image %d) is ill-conditioned, " -+ "removing it and retrying (%d views left).", -+ badIndex, removedImageId, (int)objectPoints.size()-1); -+ logStream << "Fisheye calibration: removed ill-conditioned view " << badIndex -+ << " (image " << removedImageId << "), " -+ << (int)objectPoints.size()-1 << " views left" << ENDL; -+ -+ // Prune the local copies only (never the persistent buffers). Keep them -+ // aligned: the per-view reprojection loop below indexes them together -+ // with rvecs/tvecs. -+ objectPoints.erase(objectPoints.begin()+badIndex); -+ imagePoints.erase(imagePoints.begin()+badIndex); -+ if(badIndex < (int)imageIds.size()) -+ { -+ imageIds.erase(imageIds.begin()+badIndex); -+ } -+ // loop and retry with the pruned set -+ } -+ else -+ { -+ UERROR("Error: %s (try restarting the calibration)", e.what()); -+ QMessageBox::warning(this, tr("Calibration failed!"), tr("Error: %1 (try restarting the calibration)").arg(e.what())); -+ processingData_ = false; -+ return; -+ } -+ } - } - } - else -@@ -1429,8 +1495,8 @@ void CalibrationDialog::calibrate() - cv::Mat stdDevsMatInt, stdDevsMatExt; - cv::Mat perViewErrorsMat; - rms = cv::calibrateCamera( -- objectPoints_[id], -- imagePoints_[id], -+ objectPoints, -+ imagePoints, - imageSize_[id], - K, - D, -@@ -1440,14 +1506,14 @@ void CalibrationDialog::calibrate() - stdDevsMatExt, - perViewErrorsMat, - ui_->comboBox_calib_model->currentIndex()==2?cv::CALIB_RATIONAL_MODEL:0); -- if((int)imageIds_[id].size() == perViewErrorsMat.rows) -+ if((int)imageIds.size() == perViewErrorsMat.rows) - { - UINFO("Per view errors:"); - logStream << "Per view errors:" << ENDL; - for(int i=0; i(i,0)); -- logStream << "Image " << imageIds_[id][i] << ": " << perViewErrorsMat.at(i,0) << ENDL; -+ UINFO("Image %d: %f", imageIds[i], perViewErrorsMat.at(i,0)); -+ logStream << "Image " << imageIds[i] << ": " << perViewErrorsMat.at(i,0) << ENDL; - } - } - } -@@ -1459,23 +1525,23 @@ void CalibrationDialog::calibrate() - std::vector imagePoints2; - int i, totalPoints = 0; - double totalErr = 0, err; -- reprojErrs.resize(objectPoints_[id].size()); -+ reprojErrs.resize(objectPoints.size()); - -- for( i = 0; i < (int)objectPoints_[id].size(); ++i ) -+ for( i = 0; i < (int)objectPoints.size(); ++i ) - { - #if CV_MAJOR_VERSION > 2 or (CV_MAJOR_VERSION == 2 and (CV_MINOR_VERSION >4 or (CV_MINOR_VERSION == 4 and CV_SUBMINOR_VERSION >=10))) - if(fishEye) - { -- cv::fisheye::projectPoints( cv::Mat(objectPoints_[id][i]), imagePoints2, rvecs[i], tvecs[i], K, D); -+ cv::fisheye::projectPoints( cv::Mat(objectPoints[i]), imagePoints2, rvecs[i], tvecs[i], K, D); - } - else - #endif - { -- cv::projectPoints( cv::Mat(objectPoints_[id][i]), rvecs[i], tvecs[i], K, D, imagePoints2); -+ cv::projectPoints( cv::Mat(objectPoints[i]), rvecs[i], tvecs[i], K, D, imagePoints2); - } -- err = cv::norm(cv::Mat(imagePoints_[id][i]), cv::Mat(imagePoints2), CV_L2); -+ err = cv::norm(cv::Mat(imagePoints[i]), cv::Mat(imagePoints2), cv::NORM_L2); - -- int n = (int)objectPoints_[id][i].size(); -+ int n = (int)objectPoints[i].size(); - reprojErrs[i] = (float) std::sqrt(err*err/n); - totalErr += err*err; - totalPoints += n; -@@ -1576,9 +1642,14 @@ void CalibrationDialog::calibrate() - cv::Mat P = stereoModel_.right().P().clone(); - P.at(0,3) = -P.at(0,0)*ui_->doubleSpinBox_stereoBaseline->value(); - double scale = ui_->doubleSpinBox_stereoBaseline->value() / stereoModel_.baseline(); -- UWARN("Scale %f (setting square size from %f to %f)", scale, ui_->doubleSpinBox_squareSize->value(), ui_->doubleSpinBox_squareSize->value()*scale); -- logStream << "Baseline rescaled from " << stereoModel_.baseline() << " to " << ui_->doubleSpinBox_stereoBaseline->value() << " scale=" << scale << ENDL; -- ui_->doubleSpinBox_squareSize->setValue(ui_->doubleSpinBox_squareSize->value()*scale); -+ UWARN("Scale %f applied to stereo baseline (computed %f m -> expected %f m). " -+ "If the mismatch is caused by the measured square size, it would be %f m instead of %f m.", -+ scale, stereoModel_.baseline(), ui_->doubleSpinBox_stereoBaseline->value(), -+ ui_->doubleSpinBox_squareSize->value()*scale, ui_->doubleSpinBox_squareSize->value()); -+ logStream << "Baseline rescaled from " << stereoModel_.baseline() << " to " << ui_->doubleSpinBox_stereoBaseline->value() -+ << " scale=" << scale << " (implied square size " << ui_->doubleSpinBox_squareSize->value()*scale -+ << " m instead of " << ui_->doubleSpinBox_squareSize->value() << " m)" << ENDL; -+ UASSERT(!stereoModel_.T().empty()); - stereoModel_ = StereoCameraModel( - stereoModel_.name(), - stereoModel_.left().imageSize(),stereoModel_.left().K_raw(), stereoModel_.left().D_raw(), stereoModel_.left().R(), stereoModel_.left().P(), -@@ -1708,26 +1779,58 @@ StereoCameraModel CalibrationDialog::stereoCalibration(const CameraModel & left, - cv::Vec4d D_right(right.D_raw().at(0,0), right.D_raw().at(0,1), right.D_raw().at(0,4), right.D_raw().at(0,5)); - - UASSERT(stereoImagePoints_[0].size() == stereoImagePoints_[1].size()); -+ UASSERT(stereoObjectPoints_.size() == stereoImagePoints_[0].size()); -+ // cv::fisheye::stereoCalibrate() reads the number of points from the first view and -+ // lays out its Jacobian assuming EVERY view has that same count (fisheye.cpp -+ // "reshape(1, n_points*2)"). ChArUco detects a variable number of corners per view, -+ // so we make the counts uniform by evenly subsampling every view down to the common -+ // minimum count (kept spatially spread, not just the first N). -+ size_t minPoints = stereoImagePoints_[0][0].size(); -+ for(unsigned int i =0; i > objectPoints(stereoObjectPoints_.size()); - std::vector > leftPoints(stereoImagePoints_[0].size()); - std::vector > rightPoints(stereoImagePoints_[1].size()); -+ bool subsampled = false; - for(unsigned int i =0; i1 ? (size_t)((k*(n-1))/(minPoints-1)) : 0; -+ objectPoints[i][k].x = stereoObjectPoints_[i][j].x; -+ objectPoints[i][k].y = stereoObjectPoints_[i][j].y; -+ objectPoints[i][k].z = stereoObjectPoints_[i][j].z; -+ leftPoints[i][k].x = stereoImagePoints_[0][i][j].x; -+ leftPoints[i][k].y = stereoImagePoints_[0][i][j].y; -+ rightPoints[i][k].x = stereoImagePoints_[1][i][j].x; -+ rightPoints[i][k].y = stereoImagePoints_[1][i][j].y; - } - } -+ if(subsampled) -+ { -+ UWARN("Fisheye stereo calibration requires the same number of points in every " -+ "view; sub-sampled all %d views to the common minimum of %d points.", -+ (int)stereoImagePoints_[0].size(), (int)minPoints); -+ if(logStream) (*logStream) << "Fisheye stereo: sub-sampled all views to " << (int)minPoints << " points" << ENDL; -+ } - - try - { - rms = cv::fisheye::stereoCalibrate( -- stereoObjectPoints_, -+ objectPoints, - leftPoints, - rightPoints, - left.K_raw(), D_left, right.K_raw(), D_right, -@@ -1739,30 +1842,41 @@ StereoCameraModel CalibrationDialog::stereoCalibration(const CameraModel & left, - catch(const cv::Exception & e) - { - UERROR("Error: %s (try restarting the calibration)", e.what()); -+ QMessageBox::warning(const_cast(this), tr("Calibration failed!"), tr("Error: %1 (try restarting the calibration)").arg(e.what())); - return output; - } - - std::cout << "R = " << R << std::endl; - std::cout << "T = " << Tvec << std::endl; - -+ // cv::fisheye::stereoCalibrate() returns the translation as a Vec3d (Tvec) and does -+ // not fill the cv::Mat T; populate it here so the returned model always carries a -+ // valid 3x1 extrinsic translation (used e.g. by the baseline rescaling below). -+ T = cv::Mat(3, 1, CV_64FC1); -+ T.at(0,0) = Tvec[0]; -+ T.at(1,0) = Tvec[1]; -+ T.at(2,0) = Tvec[2]; -+ - if(imageSize_[0] == imageSize_[1] && !ignoreStereoRectification) - { - UINFO("Compute stereo rectification"); - - cv::Mat R1, R2, P1, P2, Q; -+#if CV_MAJOR_VERSION < 5 - stereoRectifyFisheye( - left.K_raw(), D_left, - right.K_raw(), D_right, - imageSize, R, Tvec, R1, R2, P1, P2, Q, - cv::CALIB_ZERO_DISPARITY, 0, imageSize); -- -- // Very hard to get good results with this one: -- /*double balance = 0.0, fov_scale = 1.0; -+#else -+ // Very hard to get good results with this one, however we cannot use the previous one anymore in opencv5 -+ double balance = 0.0, fov_scale = 1.0; - cv::fisheye::stereoRectify( - left.K_raw(), D_left, - right.K_raw(), D_right, - imageSize, R, Tvec, R1, R2, P1, P2, Q, -- cv::CALIB_ZERO_DISPARITY, imageSize, balance, fov_scale);*/ -+ cv::CALIB_ZERO_DISPARITY, imageSize, balance, fov_scale); -+#endif - - std::cout << "R1 = " << R1 << std::endl; - std::cout << "R2 = " << R2 << std::endl; -@@ -1791,11 +1905,6 @@ StereoCameraModel CalibrationDialog::stereoCalibration(const CameraModel & left, - std::cout << "P1n = " << P1 << std::endl; - std::cout << "P2n = " << P2 << std::endl; - -- -- cv::Mat T(3,1,CV_64FC1); -- T.at (0,0) = Tvec[0]; -- T.at (1,0) = Tvec[1]; -- T.at (2,0) = Tvec[2]; - output = StereoCameraModel( - cameraName_.toStdString(), - imageSize_[0], left.K_raw(), left.D_raw(), R1, P1, -@@ -1915,8 +2024,8 @@ StereoCameraModel CalibrationDialog::stereoCalibration(const CameraModel & left, - { - int npt = (int)stereoImagePoints_[0][i].size(); - -- cv::Mat imgpt0 = cv::Mat(stereoImagePoints_[0][i]); -- cv::Mat imgpt1 = cv::Mat(stereoImagePoints_[1][i]); -+ std::vector imgpt0 = stereoImagePoints_[0][i]; -+ std::vector imgpt1 = stereoImagePoints_[1][i]; - cv::undistortPoints(imgpt0, imgpt0, left.K_raw(), left.D_raw(), R1, P1); - cv::undistortPoints(imgpt1, imgpt1, right.K_raw(), right.D_raw(), R2, P2); - computeCorrespondEpilines(imgpt0, 1, F, lines[0]); -@@ -1925,10 +2034,10 @@ StereoCameraModel CalibrationDialog::stereoCalibration(const CameraModel & left, - double sampleErr = 0.0; - for(int j = 0; j < npt; j++ ) - { -- double errij = fabs(stereoImagePoints_[0][i][j].x*lines[1][j][0] + -- stereoImagePoints_[0][i][j].y*lines[1][j][1] + lines[1][j][2]) + -- fabs(stereoImagePoints_[1][i][j].x*lines[0][j][0] + -- stereoImagePoints_[1][i][j].y*lines[0][j][1] + lines[0][j][2]); -+ double errij = fabs(imgpt0[j].x*lines[1][j][0] + -+ imgpt0[j].y*lines[1][j][1] + lines[1][j][2]) + -+ fabs(imgpt1[j].x*lines[0][j][0] + -+ imgpt1[j].y*lines[0][j][1] + lines[0][j][2]); - sampleErr += errij; - } - UINFO("Stereo image %d: %f", stereoImageIds_[i], sampleErr/npt); -diff --git a/guilib/src/CameraViewer.cpp b/guilib/src/CameraViewer.cpp -index 6588d51..3d7bbab 100644 ---- a/guilib/src/CameraViewer.cpp -+++ b/guilib/src/CameraViewer.cpp -@@ -85,7 +85,7 @@ CameraViewer::CameraViewer(QWidget * parent, const ParametersMap & parameters) : - showScanCheckbox_->setChecked(true); - - markerCheckbox_ = new QCheckBox("Detect markers", this); --#if defined(HAVE_OPENCV_ARUCO) || defined(RTABMAP_APRILTAG) -+#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) || defined(RTABMAP_APRILTAG) - markerCheckbox_->setEnabled(true); - markerDetector_ = new MarkerDetector(parameters); - #else -@@ -175,7 +175,8 @@ void CameraViewer::showImage(const rtabmap::SensorData & data) - if(!models.empty() && models[0].isValidForProjection()) - { - cv::Mat imageWithDetections; -- detections = markerDetector_->detect(left, models, depthOrRight, _landmarksSize, &imageWithDetections); -+ cv::Mat depth = (depthOrRight.type()==CV_16UC1 || depthOrRight.type()==CV_32FC1) ? depthOrRight : cv::Mat(); -+ detections = markerDetector_->detect(left, models, depth, _landmarksSize, &imageWithDetections); - imageView_->setImage(uCvMat2QImage(imageWithDetections)); - for(std::map::iterator iter=detections.begin(); iter!=detections.end(); ++iter) - { -diff --git a/guilib/src/DatabaseViewer.cpp b/guilib/src/DatabaseViewer.cpp -index 8951266..a133cb3 100644 ---- a/guilib/src/DatabaseViewer.cpp -+++ b/guilib/src/DatabaseViewer.cpp -@@ -43,8 +43,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include --#include - #include - #include - #include -@@ -5956,7 +5954,7 @@ void DatabaseViewer::updateStereo(const SensorData * data) - cv::Mat leftMono; - if(data->imageRaw().channels() == 3) - { -- cv::cvtColor(data->imageRaw(), leftMono, CV_BGR2GRAY); -+ cv::cvtColor(data->imageRaw(), leftMono, cv::COLOR_BGR2GRAY); - } - else - { -@@ -5965,7 +5963,7 @@ void DatabaseViewer::updateStereo(const SensorData * data) - cv::Mat rightMono; - if(data->rightRaw().channels() == 3) - { -- cv::cvtColor(data->rightRaw(), rightMono, CV_BGR2GRAY); -+ cv::cvtColor(data->rightRaw(), rightMono, cv::COLOR_BGR2GRAY); - } - else - { -diff --git a/guilib/src/MainWindow.cpp b/guilib/src/MainWindow.cpp -index 8daf26b..363d9cf 100644 ---- a/guilib/src/MainWindow.cpp -+++ b/guilib/src/MainWindow.cpp -@@ -91,6 +91,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - -+#if CV_MAJOR_VERSION >= 5 -+#include -+#endif -+ - //RGB-D stuff - #include "rtabmap/core/CameraRGBD.h" - #include "rtabmap/core/Odometry.h" -@@ -123,10 +127,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #endif - --#ifdef HAVE_OPENCV_ARUCO --#include --#endif -- - #define LOG_FILE_NAME "LogRtabmap.txt" - #define SHARE_SHOW_LOG_FILE "share/rtabmap/showlogs.m" - #define SHARE_GET_PRECISION_RECALL_FILE "share/rtabmap/getPrecisionRecall.m" -diff --git a/guilib/src/PreferencesDialog.cpp b/guilib/src/PreferencesDialog.cpp -index 2ccdd09..f42667d 100644 ---- a/guilib/src/PreferencesDialog.cpp -+++ b/guilib/src/PreferencesDialog.cpp -@@ -475,10 +475,10 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) : - _ui->checkBox_showOdomFrustums->setChecked(false); - #endif - --#if !defined(HAVE_OPENCV_ARUCO) && !defined(RTABMAP_APRILTAG) -+#if !((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) && !defined(HAVE_OPENCV_ARUCO) && !defined(RTABMAP_APRILTAG) - _ui->label_markerDetection->setText(_ui->label_markerDetection->text()+" This option works only if OpenCV has been built with \"aruco\" module and/or RTAB-Map has been built with AprilTag library support."); - #endif --#ifndef HAVE_OPENCV_ARUCO -+#if !(((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO)) - _ui->MarkerStrategy->setItemData(0, 0, Qt::UserRole - 1); - #endif - #ifndef RTABMAP_APRILTAG -diff --git a/guilib/src/ui/calibrationDialog.ui b/guilib/src/ui/calibrationDialog.ui -index d429252..96a5d27 100644 ---- a/guilib/src/ui/calibrationDialog.ui -+++ b/guilib/src/ui/calibrationDialog.ui -@@ -345,10 +345,10 @@ - - - -- -+ Number of inner squares on the board - - -- Square Size -+ Board Size - - - -@@ -385,10 +385,10 @@ - - - -- Number of inner squares on the board -+ - - -- Board Size -+ Square Size - - - -diff --git a/tools/Camera/main.cpp b/tools/Camera/main.cpp -index e337030..3bf320c 100644 ---- a/tools/Camera/main.cpp -+++ b/tools/Camera/main.cpp -@@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UDirectory.h" - #include "rtabmap/utilite/UConversion.h" - #include --#include - #include - - void showUsage() -@@ -178,7 +177,7 @@ int main(int argc, char * argv[]) - - cv::Mat rgb; - rgb = camera->takeImage().imageRaw(); -- cv::namedWindow("Video", CV_WINDOW_AUTOSIZE); // create window -+ cv::namedWindow("Video", cv::WINDOW_AUTOSIZE); // create window - while(!rgb.empty()) - { - cv::imshow("Video", rgb); // show frame -diff --git a/tools/CameraRGBD/main.cpp b/tools/CameraRGBD/main.cpp -index b8342e6..ff40f3c 100644 ---- a/tools/CameraRGBD/main.cpp -+++ b/tools/CameraRGBD/main.cpp -@@ -40,10 +40,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include "rtabmap/utilite/UEventsManager.h" - #include - #include --#include --#if CV_MAJOR_VERSION >= 3 --#include --#endif - #include - #include - #include -@@ -454,7 +450,7 @@ int main(int argc, char * argv[]) - { - if(right.channels() == 3) - { -- cv::cvtColor(right, right, CV_BGR2GRAY); -+ cv::cvtColor(right, right, cv::COLOR_BGR2GRAY); - } - pcl::PointCloud::Ptr cloud = rtabmap::util3d::cloudFromStereoImages( - rgb, right, -diff --git a/tools/EpipolarGeometry/main.cpp b/tools/EpipolarGeometry/main.cpp -index aa309fa..22e6016 100644 ---- a/tools/EpipolarGeometry/main.cpp -+++ b/tools/EpipolarGeometry/main.cpp -@@ -26,7 +26,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - #include --#include - #include - #include - #include -@@ -36,7 +35,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include -+#if CV_MAJOR_VERSION < 5 - #include -+#else -+#include -+#endif - #include "rtabmap/core/Features2d.h" - #include "rtabmap/core/EpipolarGeometry.h" - #include "rtabmap/core/VWDictionary.h" -diff --git a/tools/StereoEval/main.cpp b/tools/StereoEval/main.cpp -index bd3313f..9c15e34 100644 ---- a/tools/StereoEval/main.cpp -+++ b/tools/StereoEval/main.cpp -@@ -37,7 +37,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - #include - #include - #include --#include - #include - #include - -@@ -222,7 +221,7 @@ int main(int argc, char * argv[]) - cv::Mat leftMono; - if(left.channels() == 3) - { -- cv::cvtColor(left, leftMono, CV_BGR2GRAY); -+ cv::cvtColor(left, leftMono, cv::COLOR_BGR2GRAY); - } - else - { -@@ -231,7 +230,7 @@ int main(int argc, char * argv[]) - cv::Mat rightMono; - if(right.channels() == 3) - { -- cv::cvtColor(right, rightMono, CV_BGR2GRAY); -+ cv::cvtColor(right, rightMono, cv::COLOR_BGR2GRAY); - } - else - { -@@ -266,7 +265,7 @@ int main(int argc, char * argv[]) - cv::cornerSubPix(leftMono, leftCorners, - cv::Size( subPixWinSize, subPixWinSize ), - cv::Size( -1, -1 ), -- cv::TermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, subPixIterations, subPixEps ) ); -+ cv::TermCriteria( cv::TermCriteria::MAX_ITER | cv::TermCriteria::EPS, subPixIterations, subPixEps ) ); - UDEBUG("cv::cornerSubPix() end"); - } - diff --git a/tools/maintenance.py b/tools/maintenance.py index d8c9eda2..d1b3eccc 100644 --- a/tools/maintenance.py +++ b/tools/maintenance.py @@ -148,7 +148,12 @@ def bump_rebuild(distro: str) -> list[str]: text = path.read_text() current = int(re.search(r"(?m)^build_number:\s*(\d+)", text).group(1)) released = released_build_number(distro) - number = current + 1 if released is None else released + 1 + # per-package build numbers (dropped below) may not be on the channel yet, but + # their builds can be in CI caches: stay above them as well + info = rs.DISTROS / distro / "pkg_additional_info.yaml" + overrides = [e["build_number"] for e in ((yaml.safe_load(info.read_text()) if info.is_file() else None) or {}).values() + if isinstance(e, dict) and isinstance(e.get("build_number"), int)] + number = max([current if released is None else released, *overrides]) + 1 text = re.sub(r"(?m)^(build_number:\s*)\d+", rf"\g<1>{number}", text, count=1) m = re.search(r"(?m)^mutex_package:\n(?:[ \t]+.*\n|\n)*?[ \t]+version:[ \t]*[\"']?(\d+)\.(\d+)\.(\d+)", text) if not m: @@ -157,10 +162,11 @@ def bump_rebuild(distro: str) -> list[str]: new_mutex = f"{m.group(1)}.{int(m.group(2)) + 1}.0" text = text[:m.start(1)] + new_mutex + text[m.end(3):] path.write_text(text) - source = "channel unreadable, current + 1" if released is None else f"highest released build {released} + 1" - lines = [f"`build_number` {current} → {number} ({source}), mutex {old_mutex} → {new_mutex} (rebuilds every package)"] + source = "channel unreadable, current" if released is None else f"highest released build {released}" + if overrides and max(overrides) >= (current if released is None else released): + source = f"highest per-package build number {max(overrides)}" + lines = [f"`build_number` {current} → {number} ({source} + 1), mutex {old_mutex} → {new_mutex} (rebuilds every package)"] - info = rs.DISTROS / distro / "pkg_additional_info.yaml" if info.is_file(): ry = _ruamel() data = ry.load(info.read_text()) or {} @@ -323,15 +329,68 @@ def rosdistro_syncs() -> list[dict]: return jobs +def _newer(a: str, b: str) -> bool: + from packaging.version import InvalidVersion, Version + + try: + return Version(a) > Version(b) + except InvalidVersion: + return False + + +def released_on_master(distro: str) -> set[str] | None: + """Packages released in the distribution on rosdistro master (None if unreadable).""" + import urllib.request + + try: + with urllib.request.urlopen(f"https://raw.githubusercontent.com/ros/rosdistro/master/{distro}/distribution.yaml", + timeout=60) as resp: + repos = (yaml.safe_load(resp.read()) or {}).get("repositories") or {} + except OSError: + return None + released = set() + for name, repo in repos.items(): + release = (repo or {}).get("release") or {} + if release.get("version"): + released.update(release.get("packages") or [name]) + return released + + +def keep_newer(old: dict, new: dict, on_master: set[str] = frozenset()) -> tuple[dict, list[str]]: + """The new snapshot, except that repositories the old one has ahead of it keep all + their old entries, including packages the new one drops or adds: a sync never + downgrades. A repository is ahead when one of its packages has a newer version, or + when the sync drops a package that rosdistro master (`on_master`) still releases + (the old snapshot was taken from master, or entries were spliced in from it).""" + def repo(entry) -> str | None: + return entry.get("repository") or entry.get("url") if isinstance(entry, dict) else None + + ahead = sorted({repo(old[k]) for k in set(old) & set(new) + if repo(old[k]) and _newer(str(old[k].get("version")), str(new[k].get("version")))} + | {repo(old[k]) for k in set(old) - set(new) if k in on_master and repo(old[k])}) + if not ahead: + return new, [] + merged = {k: v for k, v in new.items() if repo(v) not in ahead} + merged.update({k: v for k, v in old.items() if repo(v) in ahead}) + return dict(sorted(merged.items())), ahead + + def update_snapshot(distro: str) -> Result: """Snapshot the distribution's latest rosdistro sync (rosdistro master with `rosdistro_sync: manual`), then bump for a full rebuild.""" snapshot = rs.DISTROS / distro / "rosdistro_snapshot.yaml" recorded = rs.settings(distro).get("rosdistro_sync") ref = None if recorded == "manual" else latest_sync(distro) + old_text = snapshot.read_text() if snapshot.is_file() else "" old = _versions(snapshot) if rs.task(distro, "create-snapshot", ["--rosdistro-ref", ref] if ref else []): return Result(f"{distro}: snapshot update failed", "`vinca-snapshot` failed, see the log.", ok=False) + text = snapshot.read_text() + data, ahead = keep_newer(yaml.safe_load(old_text) or {}, yaml.safe_load(text) or {}, + (released_on_master(distro) or set()) if ref else set()) + if ahead: + header = "".join(l for l in text.splitlines(True) if l.startswith("#")) + snapshot.write_text(header + yaml.safe_dump(data, sort_keys=True, default_flow_style=False)) new = _versions(snapshot) if ref: _set_setting(distro, "rosdistro_sync", ref) @@ -343,6 +402,9 @@ def update_snapshot(distro: str) -> Result: "", ] title = f"{distro}: rosdistro sync {date}" + if ahead: + source[-1:] = ["", "Kept at their newer versions (the previous snapshot is ahead of the sync for these " + "repositories): " + ", ".join(f"<{r}>" for r in ahead) + ".", ""] else: source, title = ["rosdistro master (this distribution doesn't follow syncs).", ""], f"{distro}: update rosdistro snapshot" if old == new: diff --git a/tools/tests/test_bot_commands.py b/tools/tests/test_bot_commands.py index 6b3652bb..5429aa02 100644 --- a/tools/tests/test_bot_commands.py +++ b/tools/tests/test_bot_commands.py @@ -204,3 +204,22 @@ def gh(args): {"number": 7, "state": "open", "html_url": "https://7"}] assert maintenance.publish_report("o/r", "jazzy", "body", conflicts=False) == "https://7" assert calls[-1][:4] == ["api", "-X", "PATCH", "repos/o/r/issues/7"] and "state=closed" in calls[-1] + + +def test_sync_keeps_repositories_ahead_of_it(): + def entry(repo, version): + return {"repository": f"https://github.com/x/{repo}", "version": version} + + old = {"easynav": entry("easynav", "0.5.0"), "easynav_tiago": entry("easynav", "0.5.0"), + "rclcpp": entry("rclcpp", "30.1.0"), "dropped": entry("other", "1.0.0")} + new = {"easynav": entry("easynav", "0.4.2"), "easynav_gps": entry("easynav", "0.4.2"), + "rclcpp": entry("rclcpp", "30.2.0"), "added": entry("added", "0.1.0")} + merged, ahead = maintenance.keep_newer(old, new) + # the whole easynav repository stays at 0.5.0 (gps is gone there, tiago kept); the rest follows the sync + assert ahead == ["https://github.com/x/easynav"] + assert merged == {"added": new["added"], "easynav": old["easynav"], "easynav_tiago": old["easynav_tiago"], + "rclcpp": new["rclcpp"]} + assert maintenance.keep_newer(new, new) == (new, []) + # dropped by the sync but still released on master: released after the sync, kept + merged, ahead = maintenance.keep_newer(old, new, {"dropped"}) + assert "https://github.com/x/other" in ahead and merged["dropped"] == old["dropped"] From f6b8766d3dc00b90df7d745af34f72ba9ae5ee0a Mon Sep 17 00:00:00 2001 From: Tobias Fischer Date: Mon, 12 Oct 2026 20:52:10 +1000 Subject: [PATCH 2/5] update-snapshot: blank line after the kept repositories Co-Authored-By: Claude Opus 5.5 --- tools/maintenance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/maintenance.py b/tools/maintenance.py index d1b3eccc..6f555e06 100644 --- a/tools/maintenance.py +++ b/tools/maintenance.py @@ -404,7 +404,7 @@ def update_snapshot(distro: str) -> Result: title = f"{distro}: rosdistro sync {date}" if ahead: source[-1:] = ["", "Kept at their newer versions (the previous snapshot is ahead of the sync for these " - "repositories): " + ", ".join(f"<{r}>" for r in ahead) + ".", ""] + "repositories): " + ", ".join(f"<{r}>" for r in ahead) + ".", "", ""] else: source, title = ["rosdistro master (this distribution doesn't follow syncs).", ""], f"{distro}: update rosdistro snapshot" if old == new: From fd014a1938f63634bb5a275dea105667b7ca892d Mon Sep 17 00:00:00 2001 From: Tobias Fischer Date: Mon, 12 Oct 2026 21:06:02 +1000 Subject: [PATCH 3/5] latest_sync: list the sync tags with git ls-remote The unauthenticated GitHub API ran into its rate limit (two local syncs in a row); git ls-remote needs no token and has no limit. Co-Authored-By: Claude Opus 5.5 --- tools/maintenance.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tools/maintenance.py b/tools/maintenance.py index 6f555e06..9c5a1c82 100644 --- a/tools/maintenance.py +++ b/tools/maintenance.py @@ -255,15 +255,10 @@ def _details(summary: str, lines: list[str]) -> list[str]: def latest_sync(distro: str) -> str | None: """Newest sync tag of the distribution in ros/rosdistro, e.g. jazzy/2026-10-05. The ROS release team tags every sync from ros-testing to the main repositories.""" - import urllib.request - - headers = {"User-Agent": "robostack-bot", "Accept": "application/vnd.github+json"} - if token := os.environ.get("GITHUB_TOKEN"): - headers["Authorization"] = f"Bearer {token}" - url = f"https://api.github.com/repos/ros/rosdistro/git/matching-refs/tags/{distro}/" - with urllib.request.urlopen(urllib.request.Request(url, headers=headers), timeout=60) as response: - refs = json.load(response) - tags = [r["ref"].removeprefix("refs/tags/") for r in refs] + # git, not the GitHub API: no rate limit without a token + out = subprocess.run(["git", "ls-remote", "--tags", ROSDISTRO, f"refs/tags/{distro}/*"], + capture_output=True, text=True, check=True).stdout + tags = [line.split("\t")[1].removeprefix("refs/tags/") for line in out.splitlines() if "\t" in line] tags = [t for t in tags if (m := SYNC_TAG.match(t)) and m["distro"] == distro] return max(tags, key=lambda t: t.split("/")[1], default=None) From d94870723eb291269c866b8b7e0c47a04cb298c7 Mon Sep 17 00:00:00 2001 From: Tobias Fischer Date: Mon, 12 Oct 2026 21:13:37 +1000 Subject: [PATCH 4/5] bump_rebuild: keep pkg_additional_info.yaml sorted Co-Authored-By: Claude Opus 5.5 --- tools/maintenance.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/maintenance.py b/tools/maintenance.py index 9c5a1c82..bb8059c3 100644 --- a/tools/maintenance.py +++ b/tools/maintenance.py @@ -181,6 +181,9 @@ def bump_rebuild(distro: str) -> list[str]: if dropped: with info.open("w") as fh: ry.dump(data, fh) + from vinca.sort_yaml_keys import sort_mapping_keys + + sort_mapping_keys(info) # `pixi run sort` order, or rs check fails lines.append(f"removed {len(dropped)} per-package build numbers: " + ", ".join(dropped)) return lines From 163957d596731bfdc841feca21524e9f318a77ef Mon Sep 17 00:00:00 2001 From: Tobias Fischer Date: Tue, 13 Oct 2026 05:15:26 +1000 Subject: [PATCH 5/5] Drop the lyrical patch refreshes picked up by accident They belong to the lyrical sync (#60), not to the tooling fix. Co-Authored-By: Claude Opus 5.5 --- .../lyrical/patch/ros2-foxglove-bridge.patch | 25 +- .../patch/ros2-foxglove-bridge.win.patch | 108 +- .../ros2-microstrain-inertial-driver.patch | 94 +- distros/lyrical/patch/ros2-rtabmap.patch | 2941 ++++++++++++++++- 4 files changed, 3147 insertions(+), 21 deletions(-) diff --git a/distros/lyrical/patch/ros2-foxglove-bridge.patch b/distros/lyrical/patch/ros2-foxglove-bridge.patch index 6822948e..0f0d55c2 100644 --- a/distros/lyrical/patch/ros2-foxglove-bridge.patch +++ b/distros/lyrical/patch/ros2-foxglove-bridge.patch @@ -1,26 +1,39 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 64c1274..774140a 100644 +index 6171894..f285973 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,18 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarc elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") set(FOXGLOVE_SDK_PLATFORM "x86_64-unknown-linux-gnu") - set(FOXGLOVE_SDK_SHA "1a0d8e03a885f01ae7cfb08dc9076090ba2cf8a15b7f46dda11451e2e2758978") + set(FOXGLOVE_SDK_SHA "4790dad26adaced1a5f81530ed406bab7b60aa202a868eb78cfc04976b9ce6d7") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") + set(FOXGLOVE_SDK_PLATFORM "aarch64-apple-darwin") -+ set(FOXGLOVE_SDK_SHA "7b7a86a659a86544f23bed793b7913ad71c3f6c595233bbdb20d3968a3ce5a3a") ++ set(FOXGLOVE_SDK_SHA "70c6e59cf757ac0480912c13cb2c630a3839de34eba428ef717411dae6b1688e") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(FOXGLOVE_SDK_PLATFORM "x86_64-apple-darwin") -+ set(FOXGLOVE_SDK_SHA "5bae49cac58fb423217e9214452c22faa95b51f5bda7c04469fb1649f8b74ce5") ++ set(FOXGLOVE_SDK_SHA "c6092c615523d462a9d3779313b8c033cf923ce30a43dc5305d48fe4f6d26988") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64") + set(FOXGLOVE_SDK_PLATFORM "aarch64-pc-windows-msvc") -+ set(FOXGLOVE_SDK_SHA "8d067b5af329f808142a750e939799bfccb27926ff72b62da54e5280af002d3b") ++ set(FOXGLOVE_SDK_SHA "b88abb1bc2c5e230db65cd3d608174f005b3b4563b1c0b2e33db05bc3a2b528b") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") + set(FOXGLOVE_SDK_PLATFORM "x86_64-pc-windows-msvc") -+ set(FOXGLOVE_SDK_SHA "ea4db36121adb0ee61315442ea43603136c6910b4d82814688f507cd6f7fdd3b") ++ set(FOXGLOVE_SDK_SHA "ae4ac0f4ab9eb998542a5626cd7870ba011824499fe33fa86936e82ed6502185") else() message(FATAL_ERROR "Unsupported platform/architecture combination: ${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}") endif() +@@ -201,6 +213,12 @@ target_link_libraries(foxglove_bridge_component + rosx_introspection::rosx_introspection + ) + ++if(APPLE) ++ find_library(COREFOUNDATION_FRAMEWORK CoreFoundation REQUIRED) ++ find_library(SECURITY_FRAMEWORK Security REQUIRED) ++ target_link_libraries(foxglove_bridge_component ${COREFOUNDATION_FRAMEWORK} ${SECURITY_FRAMEWORK}) ++endif() ++ + rclcpp_components_register_nodes(foxglove_bridge_component "foxglove_bridge::FoxgloveBridge") + enable_strict_compiler_warnings(foxglove_bridge_component) + set_target_properties(foxglove_bridge_component PROPERTIES diff --git a/src/message_definition_cache.cpp b/src/message_definition_cache.cpp index cf2864e..9124c80 100644 --- a/src/message_definition_cache.cpp diff --git a/distros/lyrical/patch/ros2-foxglove-bridge.win.patch b/distros/lyrical/patch/ros2-foxglove-bridge.win.patch index feaf5dfb..575d47e8 100644 --- a/distros/lyrical/patch/ros2-foxglove-bridge.win.patch +++ b/distros/lyrical/patch/ros2-foxglove-bridge.win.patch @@ -1,8 +1,9 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt +index f285973..28652e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -62,7 +62,7 @@ endif() - +@@ -61,7 +61,7 @@ endif() + macro(enable_strict_compiler_warnings target) if (MSVC) - target_compile_options(${target} PRIVATE /WX /W4) @@ -10,3 +11,106 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wold-style-cast -Wfloat-equal -Wmost -Wunused-exception-parameter) else() +@@ -121,6 +121,75 @@ FetchContent_Declare( + URL_HASH SHA256=${FOXGLOVE_SDK_SHA} + ) + FetchContent_MakeAvailable(foxglove_sdk) ++if(MSVC) ++ file(READ ++ "${foxglove_sdk_SOURCE_DIR}/include/foxglove/parameter.hpp" ++ _foxglove_parameter_hpp ++ ) ++ string(REPLACE "\r\n" "\n" _foxglove_parameter_hpp "${_foxglove_parameter_hpp}") ++ string(REPLACE ++[=[ ++ [[nodiscard]] bool isArray() const noexcept { ++ if (!this->isArray()) { ++ return false; ++ } ++ try { ++ const auto& arr = this->get(); ++ return std::all_of(arr.begin(), arr.end(), [](const ParameterValueView& elem) noexcept { ++ return elem.is(); ++ }); ++ } catch (...) { ++ return false; ++ } ++ } ++]=] ++[=[ ++ [[nodiscard]] bool isArray() const noexcept { ++ auto value = this->value(); ++ if (!value.has_value() || !value->is()) { ++ return false; ++ } ++ try { ++ const auto& arr = value->get(); ++ return std::all_of(arr.begin(), arr.end(), [](const ParameterValueView& elem) noexcept { ++ return elem.is(); ++ }); ++ } catch (...) { ++ return false; ++ } ++ } ++]=] ++ _foxglove_parameter_hpp ++ "${_foxglove_parameter_hpp}" ++ ) ++ string(REPLACE ++[=[ ++ [[nodiscard]] bool isDict() const noexcept { ++ if (!this->isDict()) { ++ return false; ++ } ++ try { ++ const auto& dict = this->get(); ++ return std::all_of( ++]=] ++[=[ ++ [[nodiscard]] bool isDict() const noexcept { ++ auto value = this->value(); ++ if (!value.has_value() || !value->is()) { ++ return false; ++ } ++ try { ++ const auto& dict = value->get(); ++ return std::all_of( ++]=] ++ _foxglove_parameter_hpp ++ "${_foxglove_parameter_hpp}" ++ ) ++ file(WRITE ++ "${foxglove_sdk_SOURCE_DIR}/include/foxglove/parameter.hpp" ++ "${_foxglove_parameter_hpp}" ++ ) ++endif() + + # The dist's CMake package config defines IMPORTED targets for the prebuilt C libraries + # (foxglove-static, foxglove-shared) and the foxglove_sdk_add_cpp_library() helper, which +@@ -135,6 +204,16 @@ if (FOXGLOVE_BRIDGE_REMOTE_ACCESS) + else() + foxglove_sdk_add_cpp_library(foxglove_cpp_shared TYPE SHARED REMOTE_ACCESS OFF) + endif() ++if(WIN32) ++ target_link_libraries(foxglove_cpp_shared PRIVATE ++ Ws2_32.lib ++ Userenv.lib ++ Ntdll.lib ++ Crypt32.lib ++ Secur32.lib ++ Ncrypt.lib ++ ) ++endif() + set_target_properties(foxglove_cpp_shared PROPERTIES + BUILD_WITH_INSTALL_RPATH TRUE + ) +diff --git a/src/ros2_foxglove_bridge.cpp b/src/ros2_foxglove_bridge.cpp +index b7fc123..fa78588 100644 +--- a/src/ros2_foxglove_bridge.cpp ++++ b/src/ros2_foxglove_bridge.cpp +@@ -1,3 +1,5 @@ ++#define _CRT_SECURE_NO_WARNINGS ++ + #include + #include + #include diff --git a/distros/lyrical/patch/ros2-microstrain-inertial-driver.patch b/distros/lyrical/patch/ros2-microstrain-inertial-driver.patch index 6da1ef58..cb5214c3 100644 --- a/distros/lyrical/patch/ros2-microstrain-inertial-driver.patch +++ b/distros/lyrical/patch/ros2-microstrain-inertial-driver.patch @@ -1,5 +1,5 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index a98cb77..4d92e1b 100644 +index 35e036fa..db513f68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,14 @@ @@ -17,8 +17,40 @@ index a98cb77..4d92e1b 100644 # C++ 14 required set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -@@ -236,7 +244,10 @@ target_link_libraries(${LIFECYCLE_NAME} PUBLIC +@@ -187,6 +195,14 @@ set(COMMON_INC_FILES ) + set(COMMON_FILES ${COMMON_SRC_FILES} ${COMMON_INC_FILES}) + ++# ament_target_dependencies() was removed from ament_cmake_target_dependencies; ++# link against each dependency's exported _TARGETS instead. ++macro(link_ament_dependencies target) ++ foreach(_ament_dep ${ARGN}) ++ target_link_libraries(${target} ${${_ament_dep}_TARGETS}) ++ endforeach() ++endmacro() ++ + set(AMENT_COMMON_DEPENDENCIES + rclcpp + rclcpp_lifecycle +@@ -215,9 +231,7 @@ set(NODE_INC_FILES + ) + set(NODE_FILES ${NODE_SRC_FILES} ${NODE_INC_FILES}) + add_executable(${NODE_NAME} ${NODE_FILES} ${COMMON_FILES}) +-ament_target_dependencies(${NODE_NAME} +- ${AMENT_COMMON_DEPENDENCIES} +-) ++link_ament_dependencies(${NODE_NAME} ${AMENT_COMMON_DEPENDENCIES}) + + # Lifecycle node + set(LIFECYCLE_NAME ${PROJECT_NAME}_lifecycle_node) +@@ -231,12 +245,13 @@ set(LIFECYCLE_INC_FILES + set(LIFECYCLE_FILES ${LIFECYCLE_SRC_FILES} ${LIFECYCLE_INC_FILES}) + add_executable(${LIFECYCLE_NAME} ${LIFECYCLE_FILES} ${COMMON_FILES}) + target_compile_definitions(${LIFECYCLE_NAME} PUBLIC MICROSTRAIN_LIFECYCLE) +-ament_target_dependencies(${LIFECYCLE_NAME} +- ${AMENT_COMMON_DEPENDENCIES} +-) ++link_ament_dependencies(${LIFECYCLE_NAME} ${AMENT_COMMON_DEPENDENCIES}) # Annoying, but the ROS types don't match up with the MIP types for floats and doubles, so ignore those warnings for now -set_source_files_properties(${COMMON_SRC_DIR}/services.cpp PROPERTIES COMPILE_OPTIONS "-Wno-narrowing") @@ -29,8 +61,57 @@ index a98cb77..4d92e1b 100644 # Tell the code the version of the driver that is being build add_definitions(-DMICROSTRAIN_DRIVER_VERSION="${DRIVER_GIT_VERSION}") + +diff --git a/microstrain_inertial_driver_common/include/microstrain_inertial_driver_common/utils/ros_compat.h b/microstrain_inertial_driver_common/include/microstrain_inertial_driver_common/utils/ros_compat.h +index f1fe0879..5b866134 100644 +--- a/microstrain_inertial_driver_common/include/microstrain_inertial_driver_common/utils/ros_compat.h ++++ b/microstrain_inertial_driver_common/include/microstrain_inertial_driver_common/utils/ros_compat.h +@@ -779,7 +779,7 @@ inline TransformListenerType createTransformListener(TransformBufferType buffer) + */ + inline StaticTransformBroadcasterType createStaticTransformBroadcaster(RosNodeType* node) + { +- return std::make_shared(node); ++ return std::make_shared(*node); + } + + /** +@@ -789,7 +789,7 @@ inline StaticTransformBroadcasterType createStaticTransformBroadcaster(RosNodeTy + */ + inline TransformBroadcasterType createTransformBroadcaster(RosNodeType* node) + { +- return std::make_shared(node); ++ return std::make_shared(*node); + } + + /** +diff --git a/src/microstrain_inertial_driver.cpp b/src/microstrain_inertial_driver.cpp +index e679866b..eaea4f15 100644 +--- a/src/microstrain_inertial_driver.cpp ++++ b/src/microstrain_inertial_driver.cpp +@@ -18,7 +18,7 @@ + #include + #include + +-#include ++#include + + #include "lifecycle_msgs/msg/transition.hpp" + +diff --git a/src/microstrain_inertial_driver_lifecycle.cpp b/src/microstrain_inertial_driver_lifecycle.cpp +index 1e2a6757..f77bb1d9 100644 +--- a/src/microstrain_inertial_driver_lifecycle.cpp ++++ b/src/microstrain_inertial_driver_lifecycle.cpp +@@ -18,7 +18,7 @@ + #include + #include + +-#include ++#include + + #include "lifecycle_msgs/msg/transition.hpp" + diff --git a/include/microstrain_inertial_driver/microstrain_inertial_driver.h b/include/microstrain_inertial_driver/microstrain_inertial_driver.h -index 8e9c2f0..63edec0 100644 +index 8e9c2f0e..63edec08 100644 --- a/include/microstrain_inertial_driver/microstrain_inertial_driver.h +++ b/include/microstrain_inertial_driver/microstrain_inertial_driver.h @@ -14,7 +14,9 @@ @@ -43,8 +124,9 @@ index 8e9c2f0..63edec0 100644 #include #include #include + diff --git a/include/microstrain_inertial_driver/microstrain_inertial_driver_lifecycle.h b/include/microstrain_inertial_driver/microstrain_inertial_driver_lifecycle.h -index c8ef84e..931163c 100644 +index c8ef84e9..931163c2 100644 --- a/include/microstrain_inertial_driver/microstrain_inertial_driver_lifecycle.h +++ b/include/microstrain_inertial_driver/microstrain_inertial_driver_lifecycle.h @@ -14,7 +14,9 @@ @@ -57,8 +139,9 @@ index c8ef84e..931163c 100644 #include #include #include + diff --git a/microstrain_inertial_driver_common/src/utils/mip/ros_connection.cpp b/microstrain_inertial_driver_common/src/utils/mip/ros_connection.cpp -index e2eae44..826b8c2 100644 +index e2eae441..826b8c24 100644 --- a/microstrain_inertial_driver_common/src/utils/mip/ros_connection.cpp +++ b/microstrain_inertial_driver_common/src/utils/mip/ros_connection.cpp @@ -10,6 +10,14 @@ @@ -76,3 +159,4 @@ index e2eae44..826b8c2 100644 #include #include #include + diff --git a/distros/lyrical/patch/ros2-rtabmap.patch b/distros/lyrical/patch/ros2-rtabmap.patch index 938a6087..4044071f 100644 --- a/distros/lyrical/patch/ros2-rtabmap.patch +++ b/distros/lyrical/patch/ros2-rtabmap.patch @@ -1,8 +1,8 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 8b55e49..6bf425e 100644 +index 3fd1801..934ae3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -114,6 +114,10 @@ if(MSVC) +@@ -113,6 +113,10 @@ if(MSVC) endif() endif() add_compile_options("/bigobj") @@ -13,7 +13,31 @@ index 8b55e49..6bf425e 100644 endif() # [Eclipse] Automatic Discovery of Include directories (Optional, but handy) -@@ -617,8 +621,12 @@ IF(WITH_G2O) +@@ -241,7 +245,22 @@ option(BUILD_WITH_RPATH_NOT_RUNPATH "Explicitly disable usage of RUNPATH for the + set(RTABMAP_QT_VERSION AUTO CACHE STRING "Force a specific Qt version.") + set_property(CACHE RTABMAP_QT_VERSION PROPERTY STRINGS AUTO 4 5 6) + +-FIND_PACKAGE(OpenCV REQUIRED QUIET COMPONENTS core calib3d imgproc highgui stitching photo video videoio OPTIONAL_COMPONENTS aruco objdetect xfeatures2d nonfree gpu cudafeatures2d cudaoptflow cudaimgproc) ++# OpenCV components. calib3d was split into "calib" + "geometry" in OpenCV 5. ++# These lists are reused below to generate RTABMapConfig.cmake so downstream ++# find_package(RTABMap) requests the same components this build used. ++SET(RTABMAP_OpenCV_COMPONENTS_5 core imgproc highgui stitching photo video videoio calib geometry) ++SET(RTABMAP_OpenCV_COMPONENTS_4 core imgproc highgui stitching photo video videoio calib3d) ++SET(RTABMAP_OpenCV_OPTIONAL_COMPONENTS_5 objdetect xfeatures2d nonfree gpu cudafeatures2d cudaoptflow cudaimgproc) ++SET(RTABMAP_OpenCV_OPTIONAL_COMPONENTS_4 aruco objdetect xfeatures2d nonfree gpu cudafeatures2d cudaoptflow cudaimgproc) ++ ++# Probe OpenCV without a version constraint first, then request the components ++# matching the detected major version. ++FIND_PACKAGE(OpenCV REQUIRED QUIET COMPONENTS core) ++IF(OpenCV_VERSION_MAJOR GREATER 4) ++ FIND_PACKAGE(OpenCV REQUIRED QUIET COMPONENTS ${RTABMAP_OpenCV_COMPONENTS_5} OPTIONAL_COMPONENTS ${RTABMAP_OpenCV_OPTIONAL_COMPONENTS_5}) ++ELSE() ++ FIND_PACKAGE(OpenCV REQUIRED QUIET COMPONENTS ${RTABMAP_OpenCV_COMPONENTS_4} OPTIONAL_COMPONENTS ${RTABMAP_OpenCV_OPTIONAL_COMPONENTS_4}) ++ENDIF() + + IF(WITH_QT) + FIND_PACKAGE(PCL 1.7 REQUIRED QUIET COMPONENTS common io kdtree search surface filters registration sample_consensus segmentation visualization) +@@ -536,8 +555,12 @@ IF(WITH_G2O) ENDIF(WITH_G2O) IF(WITH_GTSAM) @@ -25,14 +49,317 @@ index 8b55e49..6bf425e 100644 FIND_PACKAGE(GTSAM CONFIG QUIET) + SET(CMAKE_FIND_PACKAGE_PREFER_CONFIG ${_RTABMAP_CMAKE_FIND_PACKAGE_PREFER_CONFIG}) IF(GTSAM_FOUND) - INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/CheckGTSAMFeatures.cmake) - ENDIF(GTSAM_FOUND) + # For issue https://github.com/introlab/rtabmap/pull/1626 + FIND_FILE(GTSAM_NOISE_MODEL_FACTOR_N_FILE gtsam/nonlinear/NoiseModelFactorN.h +@@ -1318,6 +1341,18 @@ install(EXPORT rtabmapTargets + #### + # Setup RTABMapConfig.cmake + #### ++IF(OpenCV_VERSION_MAJOR GREATER 4) ++ SET(CONF_OPENCV_COMPONENTS ${RTABMAP_OpenCV_COMPONENTS_5}) ++ SET(CONF_OPENCV_OPTIONAL_COMPONENTS ${RTABMAP_OpenCV_OPTIONAL_COMPONENTS_5}) ++ELSE() ++ SET(CONF_OPENCV_COMPONENTS ${RTABMAP_OpenCV_COMPONENTS_4}) ++ SET(CONF_OPENCV_OPTIONAL_COMPONENTS ${RTABMAP_OpenCV_OPTIONAL_COMPONENTS_4}) ++ENDIF() ++STRING(REPLACE ";" " " CONF_OPENCV_COMPONENTS "${CONF_OPENCV_COMPONENTS}") ++STRING(REPLACE ";" " " CONF_OPENCV_OPTIONAL_COMPONENTS "${CONF_OPENCV_OPTIONAL_COMPONENTS}") ++# Pin the OpenCV major version so downstream projects find the same major RTAB-Map was ++# built against ++SET(CONF_OPENCV_VERSION_MAJOR ${OpenCV_VERSION_MAJOR}) + include(CMakePackageConfigHelpers) + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" +@@ -1484,7 +1519,8 @@ ENDIF(PCL_COMPILE_OPTIONS) + MESSAGE(STATUS "") + MESSAGE(STATUS "Optional dependencies ('*' affects some default parameters) :") + IF(OpenCV_FOUND) +- IF(OPENCV_ARUCO_FOUND) ++ IF((OpenCV_VERSION_MAJOR LESS 4 AND OPENCV_ARUCO_FOUND) OR ++ (OpenCV_VERSION_MAJOR GREATER 4 AND OPENCV_OBJDETECT_FOUND)) + set(ARUCO_STR "YES") + ELSE() + set(ARUCO_STR "NO") +diff --git a/RTABMapConfig.cmake.in b/RTABMapConfig.cmake.in +index 155ef3e..713359b 100644 +--- a/RTABMapConfig.cmake.in ++++ b/RTABMapConfig.cmake.in +@@ -1,7 +1,7 @@ + include(CMakeFindDependencyMacro) + + # Mandatory dependencies +-find_dependency(OpenCV COMPONENTS core calib3d imgproc highgui stitching photo video OPTIONAL_COMPONENTS aruco objdetect xfeatures2d nonfree gpu cudafeatures2d) ++find_dependency(OpenCV @CONF_OPENCV_VERSION_MAJOR@ COMPONENTS @CONF_OPENCV_COMPONENTS@ OPTIONAL_COMPONENTS @CONF_OPENCV_OPTIONAL_COMPONENTS@) + + if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/RTABMap_guiTargets.cmake") + find_dependency(PCL 1.7 COMPONENTS common io kdtree search surface filters registration sample_consensus segmentation visualization) +diff --git a/corelib/include/rtabmap/core/DBDriverSqlite3.h b/corelib/include/rtabmap/core/DBDriverSqlite3.h +index a5df8e9..ad7358d 100644 +--- a/corelib/include/rtabmap/core/DBDriverSqlite3.h ++++ b/corelib/include/rtabmap/core/DBDriverSqlite3.h +@@ -30,7 +30,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines + #include "rtabmap/core/DBDriver.h" ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + + typedef struct sqlite3_stmt sqlite3_stmt; + typedef struct sqlite3 sqlite3; +diff --git a/corelib/include/rtabmap/core/EpipolarGeometry.h b/corelib/include/rtabmap/core/EpipolarGeometry.h +index e9408cd..c739d0d 100644 +--- a/corelib/include/rtabmap/core/EpipolarGeometry.h ++++ b/corelib/include/rtabmap/core/EpipolarGeometry.h +@@ -31,7 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/core/Parameters.h" + #include "rtabmap/utilite/UStl.h" + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + #include +diff --git a/corelib/include/rtabmap/core/Features2d.h b/corelib/include/rtabmap/core/Features2d.h +index eec3f57..82a6ddb 100644 +--- a/corelib/include/rtabmap/core/Features2d.h ++++ b/corelib/include/rtabmap/core/Features2d.h +@@ -32,7 +32,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + #include "rtabmap/core/Parameters.h" +@@ -70,6 +74,10 @@ class BriefDescriptorExtractor; + class SIFT; + #endif + class SURF; ++#if (CV_MAJOR_VERSION == 5) ++class BRISK; ++class KAZE; ++#endif + } + namespace cuda { + class FastFeatureDetector; +@@ -89,7 +97,13 @@ typedef cv::xfeatures2d::FREAK CV_FREAK; + typedef cv::xfeatures2d::DAISY CV_DAISY; + typedef cv::GFTTDetector CV_GFTT; + typedef cv::xfeatures2d::BriefDescriptorExtractor CV_BRIEF; ++#if (CV_MAJOR_VERSION < 5) + typedef cv::BRISK CV_BRISK; ++typedef cv::KAZE CV_KAZE; ++#else ++typedef cv::xfeatures2d::BRISK CV_BRISK; ++typedef cv::xfeatures2d::KAZE CV_KAZE; ++#endif + typedef cv::ORB CV_ORB; + typedef cv::cuda::SURF_CUDA CV_SURF_GPU; + typedef cv::cuda::ORB CV_ORB_GPU; +@@ -578,7 +592,7 @@ private: + int diffusivity_; + + #if CV_MAJOR_VERSION > 2 +- cv::Ptr kaze_; ++ cv::Ptr kaze_; + #endif + }; + +diff --git a/corelib/include/rtabmap/core/MarkerDetector.h b/corelib/include/rtabmap/core/MarkerDetector.h +index 630bf87..26b6a73 100644 +--- a/corelib/include/rtabmap/core/MarkerDetector.h ++++ b/corelib/include/rtabmap/core/MarkerDetector.h +@@ -32,7 +32,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + +-#ifdef HAVE_OPENCV_ARUCO ++#if (CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT) ++#include ++#elif defined(HAVE_OPENCV_ARUCO) + #include + #endif + +@@ -97,8 +99,11 @@ private: + float maxRange_; + float minRange_; + int dictionaryId_; +-#ifdef HAVE_OPENCV_ARUCO +- cv::Ptr detectorParams_; ++#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) ++#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7) ++ cv::Ptr arucoDetector_; ++#endif ++ cv::Ptr detectorParams_; + cv::Ptr dictionary_; + #endif + void * apriltagLibDetector_; +diff --git a/corelib/include/rtabmap/core/Memory.h b/corelib/include/rtabmap/core/Memory.h +index 8c3306a..543b834 100644 +--- a/corelib/include/rtabmap/core/Memory.h ++++ b/corelib/include/rtabmap/core/Memory.h +@@ -41,7 +41,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include "rtabmap/utilite/UStl.h" + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + + namespace rtabmap { +diff --git a/corelib/include/rtabmap/core/OdometryInfo.h b/corelib/include/rtabmap/core/OdometryInfo.h +index 484692b..4f96a59 100644 +--- a/corelib/include/rtabmap/core/OdometryInfo.h ++++ b/corelib/include/rtabmap/core/OdometryInfo.h +@@ -34,7 +34,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/core/RegistrationInfo.h" + #include "rtabmap/core/CameraModel.h" + #include "rtabmap/core/LaserScan.h" ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + + namespace rtabmap { + +diff --git a/corelib/include/rtabmap/core/SensorData.h b/corelib/include/rtabmap/core/SensorData.h +index ea5a5de..a088755 100644 +--- a/corelib/include/rtabmap/core/SensorData.h ++++ b/corelib/include/rtabmap/core/SensorData.h +@@ -34,7 +34,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + #include +diff --git a/corelib/include/rtabmap/core/Signature.h b/corelib/include/rtabmap/core/Signature.h +index 9dbbe53..11f6f9c 100644 +--- a/corelib/include/rtabmap/core/Signature.h ++++ b/corelib/include/rtabmap/core/Signature.h +@@ -31,7 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + #include +diff --git a/corelib/include/rtabmap/core/Statistics.h b/corelib/include/rtabmap/core/Statistics.h +index 1cdaf40..f787d9b 100644 +--- a/corelib/include/rtabmap/core/Statistics.h ++++ b/corelib/include/rtabmap/core/Statistics.h +@@ -31,7 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines + + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + #include +diff --git a/corelib/include/rtabmap/core/VWDictionary.h b/corelib/include/rtabmap/core/VWDictionary.h +index ebfa3a6..3a7e195 100644 +--- a/corelib/include/rtabmap/core/VWDictionary.h ++++ b/corelib/include/rtabmap/core/VWDictionary.h +@@ -31,7 +31,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + #include "rtabmap/core/Parameters.h" +diff --git a/corelib/include/rtabmap/core/stereo/stereoRectifyFisheye.h b/corelib/include/rtabmap/core/stereo/stereoRectifyFisheye.h +index 2fc12a2..60b1d79 100644 +--- a/corelib/include/rtabmap/core/stereo/stereoRectifyFisheye.h ++++ b/corelib/include/rtabmap/core/stereo/stereoRectifyFisheye.h +@@ -32,6 +32,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #ifndef CORELIB_SRC_OPENCV_STEREORECTIFYFISHEYE_H_ + #define CORELIB_SRC_OPENCV_STEREORECTIFYFISHEYE_H_ + ++// This header relies on the OpenCV C API (cvRodrigues2, cvProjectPoints2, ...) ++// which was removed in OpenCV 5. Pull in only the version macros (available in ++// all OpenCV versions) so we can fail early with a clear message rather than ++// with cryptic errors from the includes below. ++#include ++#if CV_MAJOR_VERSION >= 5 ++#error "stereoRectifyFisheye.h is not supported with OpenCV 5 or later (it uses the removed OpenCV C API). Use cv::fisheye::stereoRectify() instead, or guard your include with '#if CV_MAJOR_VERSION < 5'." ++#endif ++ + #include + #if CV_MAJOR_VERSION >= 3 + #include +diff --git a/corelib/include/rtabmap/core/util3d_correspondences.h b/corelib/include/rtabmap/core/util3d_correspondences.h +index 6bbaeb2..d53ece4 100644 +--- a/corelib/include/rtabmap/core/util3d_correspondences.h ++++ b/corelib/include/rtabmap/core/util3d_correspondences.h +@@ -32,7 +32,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include + #include ++#include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + #include +diff --git a/corelib/include/rtabmap/core/util3d_features.h b/corelib/include/rtabmap/core/util3d_features.h +index 2ea95bf..6547e5c 100644 +--- a/corelib/include/rtabmap/core/util3d_features.h ++++ b/corelib/include/rtabmap/core/util3d_features.h +@@ -30,7 +30,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include + ++#include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + #include diff --git a/corelib/src/CMakeLists.txt b/corelib/src/CMakeLists.txt -index 892279c..06c7972 100644 +index e6bf74c..fdfe0fa 100644 --- a/corelib/src/CMakeLists.txt +++ b/corelib/src/CMakeLists.txt -@@ -912,6 +912,12 @@ configure_file( - +@@ -875,6 +875,12 @@ add_definitions(${PCL_DEFINITIONS}) + # The extension is automatically found. ADD_LIBRARY(rtabmap_core ${SRC_FILES} ${RESOURCES_HEADERS}) ADD_LIBRARY(rtabmap::core ALIAS rtabmap_core) +# GTSAM and this target both instantiate an identical inline TBB allocator @@ -44,3 +371,2601 @@ index 892279c..06c7972 100644 generate_export_header(rtabmap_core DEPRECATED_MACRO_NAME RTABMAP_DEPRECATED) +diff --git a/corelib/src/EpipolarGeometry.cpp b/corelib/src/EpipolarGeometry.cpp +index 38f1584..758a14a 100644 +--- a/corelib/src/EpipolarGeometry.cpp ++++ b/corelib/src/EpipolarGeometry.cpp +@@ -33,8 +33,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UMath.h" + + #include +-#include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + + namespace rtabmap +diff --git a/corelib/src/Features2d.cpp b/corelib/src/Features2d.cpp +index da83db7..184a4d8 100644 +--- a/corelib/src/Features2d.cpp ++++ b/corelib/src/Features2d.cpp +@@ -36,7 +36,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UMath.h" + #include "rtabmap/utilite/ULogger.h" + #include "rtabmap/utilite/UTimer.h" +-#include + #include + #include + +@@ -865,7 +864,7 @@ std::vector Feature2D::generateKeypoints(const cv::Mat & image, co + cv::cornerSubPix( image, corners, + cv::Size( _subPixWinSize, _subPixWinSize ), + cv::Size( -1, -1 ), +- cv::TermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, _subPixIterations, _subPixEps ) ); ++ cv::TermCriteria( cv::TermCriteria::MAX_ITER | cv::TermCriteria::EPS, _subPixIterations, _subPixEps ) ); + + for(unsigned int i=0;i 4 ++#ifdef HAVE_OPENCV_XFEATURES2D ++ brisk_ = CV_BRISK::create(thresh_, octaves_, patternScale_); ++#else ++ UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so BRISK cannot be used!"); ++#endif ++#elif CV_MAJOR_VERSION < 3 + brisk_ = cv::Ptr(new CV_BRISK(thresh_, octaves_, patternScale_)); + #else + brisk_ = CV_BRISK::create(thresh_, octaves_, patternScale_); +@@ -2389,6 +2393,7 @@ std::vector BRISK::generateKeypointsImpl(const cv::Mat & image, co + { + UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U); + std::vector keypoints; ++#if CV_MAJOR_VERSION < 5 || (CV_MAJOR_VERSION > 4 && defined(HAVE_OPENCV_XFEATURES2D)) + cv::Mat imgRoi(image, roi); + cv::Mat maskRoi; + if(!mask.empty()) +@@ -2396,6 +2401,9 @@ std::vector BRISK::generateKeypointsImpl(const cv::Mat & image, co + maskRoi = cv::Mat(mask, roi); + } + brisk_->detect(imgRoi, keypoints, maskRoi); // Opencv keypoints ++#else ++ UWARN("RTAB-Map is not built with BRISK feature support!"); ++#endif + return keypoints; + } + +@@ -2403,7 +2411,11 @@ cv::Mat BRISK::generateDescriptorsImpl(const cv::Mat & image, std::vector 4 && defined(HAVE_OPENCV_XFEATURES2D)) + brisk_->compute(image, keypoints, descriptors); ++#else ++ UWARN("RTAB-Map is not built with BRISK feature support!"); ++#endif + return descriptors; + } + +@@ -2436,10 +2448,16 @@ void KAZE::parseParameters(const ParametersMap & parameters) + Parameters::parse(parameters, Parameters::kKAZENOctaveLayers(), nOctaveLayers_); + Parameters::parse(parameters, Parameters::kKAZEDiffusivity(), diffusivity_); + +-#if CV_MAJOR_VERSION > 3 +- kaze_ = cv::KAZE::create(extended_, upright_, threshold_, nOctaves_, nOctaveLayers_, (cv::KAZE::DiffusivityType)diffusivity_); ++#if CV_MAJOR_VERSION > 4 ++#ifdef HAVE_OPENCV_XFEATURES2D ++ kaze_ = CV_KAZE::create(extended_, upright_, threshold_, nOctaves_, nOctaveLayers_, (CV_KAZE::DiffusivityType)diffusivity_); ++#else ++ UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so KAZE cannot be used!"); ++#endif ++#elif CV_MAJOR_VERSION > 3 ++ kaze_ = CV_KAZE::create(extended_, upright_, threshold_, nOctaves_, nOctaveLayers_, (CV_KAZE::DiffusivityType)diffusivity_); + #elif CV_MAJOR_VERSION > 2 +- kaze_ = cv::KAZE::create(extended_, upright_, threshold_, nOctaves_, nOctaveLayers_, diffusivity_); ++ kaze_ = CV_KAZE::create(extended_, upright_, threshold_, nOctaves_, nOctaveLayers_, diffusivity_); + #else + UWARN("RTAB-Map is not built with OpenCV3 so Kaze feature cannot be used!"); + #endif +@@ -2449,7 +2467,7 @@ std::vector KAZE::generateKeypointsImpl(const cv::Mat & image, con + { + UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U); + std::vector keypoints; +-#if CV_MAJOR_VERSION > 2 ++#if (CV_MAJOR_VERSION > 2 && CV_MAJOR_VERSION < 5) || (CV_MAJOR_VERSION > 4 && defined(HAVE_OPENCV_XFEATURES2D)) + cv::Mat imgRoi(image, roi); + cv::Mat maskRoi; + if (!mask.empty()) +@@ -2458,7 +2476,7 @@ std::vector KAZE::generateKeypointsImpl(const cv::Mat & image, con + } + kaze_->detect(imgRoi, keypoints, maskRoi); // Opencv keypoints + #else +- UWARN("RTAB-Map is not built with OpenCV3 so Kaze feature cannot be used!"); ++ UWARN("RTAB-Map is not built with Kaze feature support!"); + #endif + return keypoints; + } +@@ -2467,10 +2485,10 @@ cv::Mat KAZE::generateDescriptorsImpl(const cv::Mat & image, std::vector 2 ++#if (CV_MAJOR_VERSION > 2 && CV_MAJOR_VERSION < 5) || (CV_MAJOR_VERSION > 4 && defined(HAVE_OPENCV_XFEATURES2D)) + kaze_->compute(image, keypoints, descriptors); + #else +- UWARN("RTAB-Map is not built with OpenCV3 so Kaze feature cannot be used!"); ++ UWARN("RTAB-Map is not built with Kaze feature support!"); + #endif + return descriptors; + } +diff --git a/corelib/src/MarkerDetector.cpp b/corelib/src/MarkerDetector.cpp +index 1484082..0b7acde 100644 +--- a/corelib/src/MarkerDetector.cpp ++++ b/corelib/src/MarkerDetector.cpp +@@ -30,6 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + ++#if CV_MAJOR_VERSION > 4 ++#include ++#endif ++ + #ifdef HAVE_OPENCV_ARUCO + #if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION <8) + namespace cv{ +@@ -72,7 +76,7 @@ extern "C" { + #include "apriltag/tag36h11.h" + } + +-#ifndef HAVE_OPENCV_ARUCO ++#if !((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) && !defined(HAVE_OPENCV_ARUCO) + // To match opencv::aruco module, add opencv::aruco dictionary enum + namespace cv{ + namespace aruco { +@@ -200,7 +204,7 @@ MarkerDetector::MarkerDetector(const ParametersMap & parameters) : + apriltagLibDetector_(NULL), + apriltagLibFamily_(NULL) + { +-#ifdef HAVE_OPENCV_ARUCO ++#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) + #if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7) + detectorParams_.reset(new cv::aruco::DetectorParameters()); + #elif CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >=2) +@@ -310,7 +314,7 @@ void MarkerDetector::parseParameters(const ParametersMap & parameters) + } + } + +-#ifdef HAVE_OPENCV_ARUCO ++#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) + detectorParams_->adaptiveThreshWinSizeMin = 3; + detectorParams_->adaptiveThreshWinSizeMax = 23; + detectorParams_->adaptiveThreshWinSizeStep = 10; +@@ -364,6 +368,7 @@ void MarkerDetector::parseParameters(const ParametersMap & parameters) + dictionaryId_ = Parameters::defaultMarkerDictionary(); + } + #endif ++ + #if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7) + dictionary_.reset(new cv::aruco::Dictionary()); + *dictionary_ = cv::aruco::getPredefinedDictionary(cv::aruco::PredefinedDictionaryType(dictionaryId_)); +@@ -373,6 +378,11 @@ void MarkerDetector::parseParameters(const ParametersMap & parameters) + dictionary_.reset(new cv::aruco::Dictionary()); + *dictionary_ = cv::aruco::getPredefinedDictionary(cv::aruco::PredefinedDictionaryType(dictionaryId_)); + #endif ++ ++#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7) ++ arucoDetector_.reset(new cv::aruco::ArucoDetector(*dictionary_, *detectorParams_)); ++#endif ++ + #else + if(strategy_ == 0) + { +@@ -441,7 +451,7 @@ void MarkerDetector::parseParameters(const ParametersMap & parameters) + #else + if(strategy_ == 1) + { +-#ifdef HAVE_OPENCV_ARUCO ++#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) + UERROR("RTAB-Map is not built with apriltag library! Fallback to OpenCV (%s=0).", Parameters::kMarkerStrategy().c_str()); + strategy_ = kStrategyOpencv; + #else +@@ -471,6 +481,34 @@ std::map MarkerDetector::detect(const cv::Mat & image, const Cam + return detections; + } + ++#if (((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO)) && (CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)) ++// Drop-in replacement for cv::aruco::estimatePoseSingleMarkers(), which was deprecated ++// in OpenCV 4.7 and removed in OpenCV 5. It reproduces the legacy default behavior (marker ++// object points ordered as ARUCO_CCW_CENTER + SOLVEPNP_ITERATIVE) using cv::solvePnP() per ++// marker. For OpenCV < 4.7 the native cv::aruco::estimatePoseSingleMarkers() is still used. ++static void estimatePoseSingleMarkers( ++ const std::vector > & corners, ++ float markerLength, ++ const cv::Mat & cameraMatrix, ++ const cv::Mat & distCoeffs, ++ std::vector & rvecs, ++ std::vector & tvecs) ++{ ++ cv::Mat objPoints(4, 1, CV_32FC3); ++ objPoints.ptr(0)[0] = cv::Vec3f(-markerLength/2.f, markerLength/2.f, 0); ++ objPoints.ptr(0)[1] = cv::Vec3f( markerLength/2.f, markerLength/2.f, 0); ++ objPoints.ptr(0)[2] = cv::Vec3f( markerLength/2.f, -markerLength/2.f, 0); ++ objPoints.ptr(0)[3] = cv::Vec3f(-markerLength/2.f, -markerLength/2.f, 0); ++ ++ rvecs.resize(corners.size()); ++ tvecs.resize(corners.size()); ++ for(size_t i=0; i MarkerDetector::detect(const cv::Mat & image, + const std::vector & models, + const cv::Mat & depth, +@@ -482,20 +520,27 @@ std::map MarkerDetector::detect(const cv::Mat & image, + UASSERT(int((depth.cols/models.size())*models.size()) == depth.cols); + int subRGBWidth = image.cols/models.size(); + ++ // Only a real depth map (CV_16UC1/CV_32FC1) can be used for marker length estimation. ++ // Ignore anything else (e.g. a stereo right image passed by mistake) instead of crashing ++ // later in util2d::getDepth(). ++ cv::Mat depthMap = depth; ++ if(!depthMap.empty() && depthMap.type()!=CV_16UC1 && depthMap.type()!=CV_32FC1) ++ { ++ UWARN("Marker detection: ignoring depth image with unsupported type=%d (expected CV_16UC1 or CV_32FC1).", depthMap.type()); ++ depthMap = cv::Mat(); ++ } ++ + float rgbToDepthFactorX = 1.0f; + float rgbToDepthFactorY = 1.0f; +- if(!depth.empty()) ++ if(!depthMap.empty()) + { +- rgbToDepthFactorX = float(depth.cols) / float(image.cols); +- rgbToDepthFactorY = float(depth.rows) / float(image.rows); ++ rgbToDepthFactorX = float(depthMap.cols) / float(image.cols); ++ rgbToDepthFactorY = float(depthMap.rows) / float(image.rows); + } + else if(markerLength_ == 0) + { +- if(depth.empty()) +- { +- UERROR("Depth image is empty, please set %s parameter to non-null.", Parameters::kMarkerLength().c_str()); +- return std::map(); +- } ++ UERROR("Depth image is empty, please set %s parameter to non-null.", Parameters::kMarkerLength().c_str()); ++ return std::map(); + } + + std::vector< int > ids; +@@ -632,8 +677,10 @@ std::map MarkerDetector::detect(const cv::Mat & image, + { + std::vector< int > cvIds; + std::vector< std::vector< cv::Point2f > > cvCorners, cvRejected; +-#ifdef HAVE_OPENCV_ARUCO +-#if CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >=2) ++#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) ++#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7) ++ arucoDetector_->detectMarkers(image, cvCorners, cvIds, cvRejected); ++#elif CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION == 3 && CV_MINOR_VERSION >=2) + cv::aruco::detectMarkers(image, dictionary_, cvCorners, cvIds, detectorParams_, cvRejected); + #else + cv::aruco::detectMarkers(image, *dictionary_, cvCorners, cvIds, *detectorParams_, cvRejected); +@@ -686,9 +733,15 @@ std::map MarkerDetector::detect(const cv::Mat & image, + + for(size_t cam=0; cam < cvCornersPerCam.size(); ++cam) + { +- std::vector< cv::Vec3d > rvecs, tvecs; + const CameraModel & model = models[cam]; ++ ++ std::vector< cv::Vec3d > rvecs, tvecs; ++#if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7) ++ estimatePoseSingleMarkers(cvCornersPerCam[cam], 1.0f, model.K(), model.D(), rvecs, tvecs); ++#else + cv::aruco::estimatePoseSingleMarkers(cvCornersPerCam[cam], 1.0f, model.K(), model.D(), rvecs, tvecs); ++#endif ++ + float offsetX = cam*subRGBWidth; + for(size_t i=0; i MarkerDetector::detect(const cv::Mat & image, + { + float length = 0.0f; + std::map::const_iterator findIter = extraMarkerLengths.find(ids[i]); +- if(markerLengths_.empty() && !depth.empty() && (markerLength_ == 0 || (markerLength_<0 && findIter==extraMarkerLengths.end()))) ++ if(markerLengths_.empty() && !depthMap.empty() && (markerLength_ == 0 || (markerLength_<0 && findIter==extraMarkerLengths.end()))) + { +- float d = util2d::getDepth(depth, (corners[i][0].x + (corners[i][2].x-corners[i][0].x)/2.0f)*rgbToDepthFactorX, (corners[i][0].y + (corners[i][2].y-corners[i][0].y)/2.0f)*rgbToDepthFactorY, true, 0.02f, true); +- float d1 = util2d::getDepth(depth, corners[i][0].x*rgbToDepthFactorX, corners[i][0].y*rgbToDepthFactorY, true, 0.02f, true); +- float d2 = util2d::getDepth(depth, corners[i][1].x*rgbToDepthFactorX, corners[i][1].y*rgbToDepthFactorY, true, 0.02f, true); +- float d3 = util2d::getDepth(depth, corners[i][2].x*rgbToDepthFactorX, corners[i][2].y*rgbToDepthFactorY, true, 0.02f, true); +- float d4 = util2d::getDepth(depth, corners[i][3].x*rgbToDepthFactorX, corners[i][3].y*rgbToDepthFactorY, true, 0.02f, true); ++ float d = util2d::getDepth(depthMap, (corners[i][0].x + (corners[i][2].x-corners[i][0].x)/2.0f)*rgbToDepthFactorX, (corners[i][0].y + (corners[i][2].y-corners[i][0].y)/2.0f)*rgbToDepthFactorY, true, 0.02f, true); ++ float d1 = util2d::getDepth(depthMap, corners[i][0].x*rgbToDepthFactorX, corners[i][0].y*rgbToDepthFactorY, true, 0.02f, true); ++ float d2 = util2d::getDepth(depthMap, corners[i][1].x*rgbToDepthFactorX, corners[i][1].y*rgbToDepthFactorY, true, 0.02f, true); ++ float d3 = util2d::getDepth(depthMap, corners[i][2].x*rgbToDepthFactorX, corners[i][2].y*rgbToDepthFactorY, true, 0.02f, true); ++ float d4 = util2d::getDepth(depthMap, corners[i][3].x*rgbToDepthFactorX, corners[i][3].y*rgbToDepthFactorY, true, 0.02f, true); + // Accept measurement only if all 4 depth values are valid and + // they are at the same depth (camera should be perpendicular to marker for + // best depth estimation) +@@ -887,7 +940,7 @@ std::map MarkerDetector::detect(const cv::Mat & image, + + if(!ids.empty()) + { +-#ifdef HAVE_OPENCV_ARUCO ++#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) + cv::aruco::drawDetectedMarkers(*imageWithDetections, corners, ids); + #else + UWARN("RTAB-Map is not built with \"aruco\" module from OpenCV. Cannot draw markers on image."); +diff --git a/corelib/src/Memory.cpp b/corelib/src/Memory.cpp +index 37afdbf..c88304c 100644 +--- a/corelib/src/Memory.cpp ++++ b/corelib/src/Memory.cpp +@@ -62,8 +62,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + #include ++#if CV_MAJOR_VERSION >=5 ++#include ++#endif + + namespace rtabmap { + +@@ -5373,7 +5375,7 @@ Signature * Memory::createSignature(const SensorData & inputData, const Transfor + cv::Mat imageMono; + if(decimatedData.imageRaw().channels() == 3) + { +- cv::cvtColor(decimatedData.imageRaw(), imageMono, CV_BGR2GRAY); ++ cv::cvtColor(decimatedData.imageRaw(), imageMono, cv::COLOR_BGR2GRAY); + } + else + { +@@ -5681,7 +5683,7 @@ Signature * Memory::createSignature(const SensorData & inputData, const Transfor + cv::Mat imageMono; + if(data.imageRaw().channels() == 3) + { +- cv::cvtColor(data.imageRaw(), imageMono, CV_BGR2GRAY); ++ cv::cvtColor(data.imageRaw(), imageMono, cv::COLOR_BGR2GRAY); + } + else + { +diff --git a/corelib/src/RegistrationVis.cpp b/corelib/src/RegistrationVis.cpp +index 738e72b..3e5cee3 100644 +--- a/corelib/src/RegistrationVis.cpp ++++ b/corelib/src/RegistrationVis.cpp +@@ -43,7 +43,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include ++#if CV_MAJOR_VERSION > 4 ++#include ++#endif + + #if defined(HAVE_OPENCV_XFEATURES2D) && (CV_MAJOR_VERSION > 3 || (CV_MAJOR_VERSION==3 && CV_MINOR_VERSION >=4 && CV_SUBMINOR_VERSION >= 1)) + #include // For GMS matcher +@@ -2172,7 +2174,7 @@ Transform RegistrationVis::computeTransformationImpl( + if(!transform.isNull() && !pcaData.empty()) + { + cv::Mat pcaEigenVectors, pcaEigenValues; +- cv::PCA pca_analysis(pcaData, cv::Mat(), CV_PCA_DATA_AS_ROW); ++ cv::PCA pca_analysis(pcaData, cv::Mat(), cv::PCA::DATA_AS_ROW); + // We take the second eigen value + info.inliersDistribution = pca_analysis.eigenvalues.at(0, 1); + +diff --git a/corelib/src/SensorCaptureThread.cpp b/corelib/src/SensorCaptureThread.cpp +index 6414fb9..07858d5 100644 +--- a/corelib/src/SensorCaptureThread.cpp ++++ b/corelib/src/SensorCaptureThread.cpp +@@ -39,7 +39,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/core/IMUFilter.h" + #include "rtabmap/core/Features2d.h" + #include "rtabmap/core/clams/discrete_depth_distortion_model.h" +-#include + #include + #include + #include +@@ -742,11 +741,11 @@ void SensorCaptureThread::postUpdate(SensorData * dataPtr, SensorCaptureInfo * i + else if(data.imageRaw().type() == CV_8UC3) + { + cv::Mat channels[3]; +- cv::cvtColor(data.imageRaw(), image, CV_BGR2YCrCb); ++ cv::cvtColor(data.imageRaw(), image, cv::COLOR_BGR2YCrCb); + cv::split(image, channels); + cv::equalizeHist(channels[0], channels[0]); + cv::merge(channels, 3, image); +- cv::cvtColor(image, image, CV_YCrCb2BGR); ++ cv::cvtColor(image, image, cv::COLOR_YCrCb2BGR); + } + if(!data.depthRaw().empty()) + { +@@ -762,11 +761,11 @@ void SensorCaptureThread::postUpdate(SensorData * dataPtr, SensorCaptureInfo * i + else if(data.rightRaw().type() == CV_8UC3) + { + cv::Mat channels[3]; +- cv::cvtColor(data.rightRaw(), right, CV_BGR2YCrCb); ++ cv::cvtColor(data.rightRaw(), right, cv::COLOR_BGR2YCrCb); + cv::split(right, channels); + cv::equalizeHist(channels[0], channels[0]); + cv::merge(channels, 3, right); +- cv::cvtColor(right, right, CV_YCrCb2BGR); ++ cv::cvtColor(right, right, cv::COLOR_YCrCb2BGR); + } + data.setStereoImage(image, right, data.stereoCameraModels()[0]); + } +@@ -781,11 +780,11 @@ void SensorCaptureThread::postUpdate(SensorData * dataPtr, SensorCaptureInfo * i + else if(data.imageRaw().type() == CV_8UC3) + { + cv::Mat channels[3]; +- cv::cvtColor(data.imageRaw(), image, CV_BGR2YCrCb); ++ cv::cvtColor(data.imageRaw(), image, cv::COLOR_BGR2YCrCb); + cv::split(image, channels); + clahe->apply(channels[0], channels[0]); + cv::merge(channels, 3, image); +- cv::cvtColor(image, image, CV_YCrCb2BGR); ++ cv::cvtColor(image, image, cv::COLOR_YCrCb2BGR); + } + if(!data.depthRaw().empty()) + { +@@ -801,11 +800,11 @@ void SensorCaptureThread::postUpdate(SensorData * dataPtr, SensorCaptureInfo * i + else if(data.rightRaw().type() == CV_8UC3) + { + cv::Mat channels[3]; +- cv::cvtColor(data.rightRaw(), right, CV_BGR2YCrCb); ++ cv::cvtColor(data.rightRaw(), right, cv::COLOR_BGR2YCrCb); + cv::split(right, channels); + clahe->apply(channels[0], channels[0]); + cv::merge(channels, 3, right); +- cv::cvtColor(right, right, CV_YCrCb2BGR); ++ cv::cvtColor(right, right, cv::COLOR_YCrCb2BGR); + } + data.setStereoImage(image, right, data.stereoCameraModels()[0]); + } +diff --git a/corelib/src/StereoCameraModel.cpp b/corelib/src/StereoCameraModel.cpp +index 421d3f4..8830c37 100644 +--- a/corelib/src/StereoCameraModel.cpp ++++ b/corelib/src/StereoCameraModel.cpp +@@ -33,7 +33,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + +-#if CV_MAJOR_VERSION > 2 or (CV_MAJOR_VERSION == 2 and (CV_MINOR_VERSION >4 or (CV_MINOR_VERSION == 4 and CV_SUBMINOR_VERSION >=10))) ++#if (CV_MAJOR_VERSION > 2 and CV_MAJOR_VERSION < 5) or (CV_MAJOR_VERSION == 2 and (CV_MINOR_VERSION >4 or (CV_MINOR_VERSION == 4 and CV_SUBMINOR_VERSION >=10))) + #include + #endif + +@@ -179,12 +179,20 @@ void StereoCameraModel::updateStereoRectification() + { + cv::Vec4d D_left(left_.D_raw().at(0,0), left_.D_raw().at(0,1), left_.D_raw().at(0,4), left_.D_raw().at(0,5)); + cv::Vec4d D_right(right_.D_raw().at(0,0), right_.D_raw().at(0,1), right_.D_raw().at(0,4), right_.D_raw().at(0,5)); +- ++#if CV_MAJOR_VERSION < 5 + stereoRectifyFisheye( + left_.K_raw(), D_left, + right_.K_raw(), D_right, + left_.imageSize(), R_, T_, R1, R2, P1, P2, Q, + cv::CALIB_ZERO_DISPARITY, 0, left_.imageSize()); ++#else ++ double balance = 0.0, fov_scale = 1.0; ++ cv::fisheye::stereoRectify( ++ left_.K_raw(), D_left, ++ right_.K_raw(), D_right, ++ left_.imageSize(), R_, T_, R1, R2, P1, P2, Q, ++ cv::CALIB_ZERO_DISPARITY, left_.imageSize(), balance, fov_scale); ++#endif + + // Re-zoom to original focal distance + if(P1.at(0,0) < 0) +diff --git a/corelib/src/camera/CameraDepthAI.cpp b/corelib/src/camera/CameraDepthAI.cpp +index beaca87..326d5bd 100644 +--- a/corelib/src/camera/CameraDepthAI.cpp ++++ b/corelib/src/camera/CameraDepthAI.cpp +@@ -32,7 +32,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +- ++#if CV_MAJOR_VERSION < 5 ++#include ++#else ++#include ++#endif + + namespace rtabmap { + +diff --git a/corelib/src/camera/CameraFreenect.cpp b/corelib/src/camera/CameraFreenect.cpp +index 9d48215..a402c7b 100644 +--- a/corelib/src/camera/CameraFreenect.cpp ++++ b/corelib/src/camera/CameraFreenect.cpp +@@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + + #ifdef RTABMAP_FREENECT + #include +@@ -183,7 +182,7 @@ private: + + if(color_) + { +- cv::cvtColor(rgbIrBuffer_, rgbIrLastFrame_, CV_RGB2BGR); ++ cv::cvtColor(rgbIrBuffer_, rgbIrLastFrame_, cv::COLOR_RGB2BGR); + } + else // IrDepth + { +diff --git a/corelib/src/camera/CameraFreenect2.cpp b/corelib/src/camera/CameraFreenect2.cpp +index 85f7bdf..1514311 100644 +--- a/corelib/src/camera/CameraFreenect2.cpp ++++ b/corelib/src/camera/CameraFreenect2.cpp +@@ -29,7 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + + #ifdef RTABMAP_FREENECT2 + #include +@@ -430,11 +429,11 @@ SensorData CameraFreenect2::captureImage(SensorCaptureInfo * info) + cv::Mat rgbMat; // rtabmap uses 3 channels RGB + #ifdef LIBFREENECT2_WITH_TEGRAJPEG_SUPPORT + +- cv::cvtColor(rgbMatC4, rgbMat, CV_RGBA2BGR); ++ cv::cvtColor(rgbMatC4, rgbMat, cv::COLOR_RGBA2BGR); + + #else + +- cv::cvtColor(rgbMatC4, rgbMat, CV_BGRA2BGR); ++ cv::cvtColor(rgbMatC4, rgbMat, cv::COLOR_BGRA2BGR); + + #endif + cv::flip(rgbMat, rgb, 1); +@@ -490,11 +489,11 @@ SensorData CameraFreenect2::captureImage(SensorCaptureInfo * info) + cv::Mat rgbMat; // rtabmap uses 3 channels RGB + #ifdef LIBFREENECT2_WITH_TEGRAJPEG_SUPPORT + +- cv::cvtColor(rgbMatC4, rgbMat, CV_RGB2BGR); ++ cv::cvtColor(rgbMatC4, rgbMat, cv::COLOR_RGB2BGR); + + #else + +- cv::cvtColor(rgbMatC4, rgbMat, CV_BGRA2BGR); ++ cv::cvtColor(rgbMatC4, rgbMat, cv::COLOR_BGRA2BGR); + + #endif + cv::flip(rgbMat, rgb, 1); +@@ -607,11 +606,11 @@ SensorData CameraFreenect2::captureImage(SensorCaptureInfo * info) + // rtabmap uses 3 channels RGB + #ifdef LIBFREENECT2_WITH_TEGRAJPEG_SUPPORT + +- cv::cvtColor(rgbMatBGRA, rgb, CV_RGBA2BGR); ++ cv::cvtColor(rgbMatBGRA, rgb, cv::COLOR_RGBA2BGR); + + #else + +- cv::cvtColor(rgbMatBGRA, rgb, CV_BGRA2BGR); ++ cv::cvtColor(rgbMatBGRA, rgb, cv::COLOR_BGRA2BGR); + + #endif + cv::flip(rgb, rgb, 1); +@@ -629,11 +628,11 @@ SensorData CameraFreenect2::captureImage(SensorCaptureInfo * info) + // rtabmap uses 3 channels RGB + #ifdef LIBFREENECT2_WITH_TEGRAJPEG_SUPPORT + +- cv::cvtColor(rgbMatBGRA, rgb, CV_RGBA2BGR); ++ cv::cvtColor(rgbMatBGRA, rgb, cv::COLOR_RGBA2BGR); + + #else + +- cv::cvtColor(rgbMatBGRA, rgb, CV_BGRA2BGR); ++ cv::cvtColor(rgbMatBGRA, rgb, cv::COLOR_BGRA2BGR); + + #endif + cv::flip(rgb, rgb, 1); +diff --git a/corelib/src/camera/CameraImages.cpp b/corelib/src/camera/CameraImages.cpp +index 9767412..824c9be 100644 +--- a/corelib/src/camera/CameraImages.cpp ++++ b/corelib/src/camera/CameraImages.cpp +@@ -34,7 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include ++#include + #include + + namespace rtabmap +@@ -933,7 +933,7 @@ SensorData CameraImages::captureImage(SensorCaptureInfo * info) + { + UWARN("Conversion from 4 channels to 3 channels (file=%s)", imageFilePath.c_str()); + cv::Mat out; +- cv::cvtColor(img, out, CV_BGRA2BGR); ++ cv::cvtColor(img, out, cv::COLOR_BGRA2BGR); + img = out; + } + else if(!img.empty() && _bayerMode >= 0 && _bayerMode <=3) +@@ -941,7 +941,7 @@ SensorData CameraImages::captureImage(SensorCaptureInfo * info) + cv::Mat debayeredImg; + try + { +- cv::cvtColor(img, debayeredImg, CV_BayerBG2BGR + _bayerMode); ++ cv::cvtColor(img, debayeredImg, cv::COLOR_BayerBG2BGR + _bayerMode); + img = debayeredImg; + } + catch(const cv::Exception & e) +diff --git a/corelib/src/camera/CameraK4A.cpp b/corelib/src/camera/CameraK4A.cpp +index ad5714d..caf659b 100644 +--- a/corelib/src/camera/CameraK4A.cpp ++++ b/corelib/src/camera/CameraK4A.cpp +@@ -29,7 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + + #ifdef RTABMAP_K4A + #include +@@ -508,7 +507,7 @@ SensorData CameraK4A::captureImage(SensorCaptureInfo * info) + CV_8UC4, + (void*)k4a_image_get_buffer(rgb_image_)); + +- cv::cvtColor(bgra, bgrCV, CV_BGRA2BGR); ++ cv::cvtColor(bgra, bgrCV, cv::COLOR_BGRA2BGR); + } + bgrCV = model_.rectifyImage(bgrCV); + +diff --git a/corelib/src/camera/CameraK4W2.cpp b/corelib/src/camera/CameraK4W2.cpp +index e289029..9a96251 100644 +--- a/corelib/src/camera/CameraK4W2.cpp ++++ b/corelib/src/camera/CameraK4W2.cpp +@@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + + #ifdef RTABMAP_K4W2 + #include +@@ -486,11 +485,11 @@ SensorData CameraK4W2::captureImage(SensorCaptureInfo * info) + { + cv::Mat tmp; + cv::resize(cv::Mat(nColorHeight, nColorWidth, CV_8UC4, pColorBuffer), tmp, cv::Size(), 0.5, 0.5, cv::INTER_AREA); +- cv::cvtColor(tmp, imageColor, CV_BGRA2BGR); ++ cv::cvtColor(tmp, imageColor, cv::COLOR_BGRA2BGR); + } + else + { +- cv::cvtColor(cv::Mat(nColorHeight, nColorWidth, CV_8UC4, pColorBuffer), imageColor, CV_BGRA2BGR); ++ cv::cvtColor(cv::Mat(nColorHeight, nColorWidth, CV_8UC4, pColorBuffer), imageColor, cv::COLOR_BGRA2BGR); + } + // loop over output pixels + for (int depthIndex = 0; depthIndex < (nDepthWidth*nDepthHeight); ++depthIndex) +diff --git a/corelib/src/camera/CameraOpenNI2.cpp b/corelib/src/camera/CameraOpenNI2.cpp +index 8be86b7..4d2ff1a 100644 +--- a/corelib/src/camera/CameraOpenNI2.cpp ++++ b/corelib/src/camera/CameraOpenNI2.cpp +@@ -29,7 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + + #ifdef RTABMAP_OPENNI2 + #include +@@ -514,7 +513,7 @@ SensorData CameraOpenNI2::captureImage(SensorCaptureInfo * info) + cv::Mat tmp(h, w, CV_8UC3, (void *)colorFrame.getData()); + if(_type==kTypeColorDepth) + { +- cv::cvtColor(tmp, rgb, CV_RGB2BGR); ++ cv::cvtColor(tmp, rgb, cv::COLOR_RGB2BGR); + } + else // IR + { +diff --git a/corelib/src/camera/CameraOpenNICV.cpp b/corelib/src/camera/CameraOpenNICV.cpp +index 13536d6..1359561 100644 +--- a/corelib/src/camera/CameraOpenNICV.cpp ++++ b/corelib/src/camera/CameraOpenNICV.cpp +@@ -26,9 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include + #include +-#if CV_MAJOR_VERSION > 3 +-#include +-#endif ++#include + + namespace rtabmap + { +@@ -59,30 +57,34 @@ bool CameraOpenNICV::init(const std::string & calibrationFolder, const std::stri + } + + ULOGGER_DEBUG("Camera::init()"); +- _capture.open( _asus?CV_CAP_OPENNI_ASUS:CV_CAP_OPENNI ); ++#if CV_MAJOR_VERSION < 5 ++ _capture.open( _asus?cv::CAP_OPENNI_ASUS:cv::CAP_OPENNI ); ++#else ++ _capture.open( _asus?cv::CAP_OPENNI2_ASUS:cv::CAP_OPENNI2 ); ++#endif + if(_capture.isOpened()) + { +- _capture.set( CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, CV_CAP_OPENNI_VGA_30HZ ); +- _depthFocal = _capture.get( CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH ); ++ _capture.set( cv::CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, cv::CAP_OPENNI_VGA_30HZ ); ++ _depthFocal = _capture.get( cv::CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH ); + // Print some avalible device settings. + UINFO("Depth generator output mode:"); +- UINFO("FRAME_WIDTH %f", _capture.get( CV_CAP_PROP_FRAME_WIDTH )); +- UINFO("FRAME_HEIGHT %f", _capture.get( CV_CAP_PROP_FRAME_HEIGHT )); +- UINFO("FRAME_MAX_DEPTH %f mm", _capture.get( CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH )); +- UINFO("BASELINE %f mm", _capture.get( CV_CAP_PROP_OPENNI_BASELINE )); +- UINFO("FPS %f", _capture.get( CV_CAP_PROP_FPS )); +- UINFO("Focal %f", _capture.get( CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH )); +- UINFO("REGISTRATION %f", _capture.get( CV_CAP_PROP_OPENNI_REGISTRATION )); +- if(_capture.get( CV_CAP_PROP_OPENNI_REGISTRATION ) == 0.0) ++ UINFO("FRAME_WIDTH %f", _capture.get( cv::CAP_PROP_FRAME_WIDTH )); ++ UINFO("FRAME_HEIGHT %f", _capture.get( cv::CAP_PROP_FRAME_HEIGHT )); ++ UINFO("FRAME_MAX_DEPTH %f mm", _capture.get( cv::CAP_PROP_OPENNI_FRAME_MAX_DEPTH )); ++ UINFO("BASELINE %f mm", _capture.get( cv::CAP_PROP_OPENNI_BASELINE )); ++ UINFO("FPS %f", _capture.get( cv::CAP_PROP_FPS )); ++ UINFO("Focal %f", _capture.get( cv::CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH )); ++ UINFO("REGISTRATION %f", _capture.get( cv::CAP_PROP_OPENNI_REGISTRATION )); ++ if(_capture.get( cv::CAP_PROP_OPENNI_REGISTRATION ) == 0.0) + { + UERROR("Depth registration is not activated on this device!"); + } +- if( _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT ) ) ++ if( _capture.get( cv::CAP_OPENNI_IMAGE_GENERATOR_PRESENT ) ) + { + UINFO("Image generator output mode:"); +- UINFO("FRAME_WIDTH %f", _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_WIDTH )); +- UINFO("FRAME_HEIGHT %f", _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_HEIGHT )); +- UINFO("FPS %f", _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FPS )); ++ UINFO("FRAME_WIDTH %f", _capture.get( cv::CAP_OPENNI_IMAGE_GENERATOR+cv::CAP_PROP_FRAME_WIDTH )); ++ UINFO("FRAME_HEIGHT %f", _capture.get( cv::CAP_OPENNI_IMAGE_GENERATOR+cv::CAP_PROP_FRAME_HEIGHT )); ++ UINFO("FPS %f", _capture.get( cv::CAP_OPENNI_IMAGE_GENERATOR+cv::CAP_PROP_FPS )); + } + else + { +@@ -112,8 +114,8 @@ SensorData CameraOpenNICV::captureImage(SensorCaptureInfo * info) + { + _capture.grab(); + cv::Mat depth, rgb; +- _capture.retrieve(depth, CV_CAP_OPENNI_DEPTH_MAP ); +- _capture.retrieve(rgb, CV_CAP_OPENNI_BGR_IMAGE ); ++ _capture.retrieve(depth, cv::CAP_OPENNI_DEPTH_MAP ); ++ _capture.retrieve(rgb, cv::CAP_OPENNI_BGR_IMAGE ); + + depth = depth.clone(); + rgb = rgb.clone(); +diff --git a/corelib/src/camera/CameraOpenni.cpp b/corelib/src/camera/CameraOpenni.cpp +index 9fb8dc7..68cba16 100644 +--- a/corelib/src/camera/CameraOpenni.cpp ++++ b/corelib/src/camera/CameraOpenni.cpp +@@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + + #ifdef RTABMAP_OPENNI + #include +@@ -94,7 +93,7 @@ void CameraOpenni::image_cb ( + + cv::Mat rgbFrame(rgb->getHeight(), rgb->getWidth(), CV_8UC3); + rgb->fillRGB(rgb->getWidth(), rgb->getHeight(), rgbFrame.data); +- cv::cvtColor(rgbFrame, rgb_, CV_RGB2BGR); ++ cv::cvtColor(rgbFrame, rgb_, cv::COLOR_RGB2BGR); + + depth_ = cv::Mat(rgb->getHeight(), rgb->getWidth(), CV_16UC1); + depth->fillDepthImageRaw(rgb->getWidth(), rgb->getHeight(), (unsigned short*)depth_.data); +diff --git a/corelib/src/camera/CameraRealSense.cpp b/corelib/src/camera/CameraRealSense.cpp +index 3f545bb..0136238 100644 +--- a/corelib/src/camera/CameraRealSense.cpp ++++ b/corelib/src/camera/CameraRealSense.cpp +@@ -29,7 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + + #ifdef RTABMAP_REALSENSE + #include +@@ -938,7 +937,7 @@ SensorData CameraRealSense::captureImage(SensorCaptureInfo * info) + } + else + { +- cv::cvtColor(rgb, bgr, CV_RGB2BGR); ++ cv::cvtColor(rgb, bgr, cv::COLOR_RGB2BGR); + } + + bool rectified = false; +diff --git a/corelib/src/camera/CameraRealSense2.cpp b/corelib/src/camera/CameraRealSense2.cpp +index fb15b0c..aad8e2c 100644 +--- a/corelib/src/camera/CameraRealSense2.cpp ++++ b/corelib/src/camera/CameraRealSense2.cpp +@@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + + #ifdef RTABMAP_REALSENSE2 + #include +@@ -1421,7 +1420,7 @@ SensorData CameraRealSense2::captureImage(SensorCaptureInfo * info) + cv::Mat bgr; + if(rgb.channels() == 3) + { +- cv::cvtColor(rgb, bgr, CV_RGB2BGR); ++ cv::cvtColor(rgb, bgr, cv::COLOR_RGB2BGR); + } + else + { +diff --git a/corelib/src/camera/CameraStereoDC1394.cpp b/corelib/src/camera/CameraStereoDC1394.cpp +index 691516b..2c21108 100644 +--- a/corelib/src/camera/CameraStereoDC1394.cpp ++++ b/corelib/src/camera/CameraStereoDC1394.cpp +@@ -28,7 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + + #ifdef RTABMAP_DC1394 + #include +@@ -295,8 +294,8 @@ public: + + //DC1394_COLOR_CODING_RAW16: + //DC1394_COLOR_FILTER_BGGR +- cv::cvtColor(cv::Mat(frame->size[1], frame->size[0], CV_8UC1, capture_buffer), left, CV_BayerRG2BGR); +- cv::cvtColor(cv::Mat(frame->size[1], frame->size[0], CV_8UC1, capture_buffer+image.total()), right, CV_BayerRG2GRAY); ++ cv::cvtColor(cv::Mat(frame->size[1], frame->size[0], CV_8UC1, capture_buffer), left, cv::COLOR_BayerRG2BGR); ++ cv::cvtColor(cv::Mat(frame->size[1], frame->size[0], CV_8UC1, capture_buffer+image.total()), right, cv::COLOR_BayerRG2GRAY); + + dc1394_capture_enqueue(camera_, frame); + +diff --git a/corelib/src/camera/CameraStereoImages.cpp b/corelib/src/camera/CameraStereoImages.cpp +index c50a3b8..e0dd643 100644 +--- a/corelib/src/camera/CameraStereoImages.cpp ++++ b/corelib/src/camera/CameraStereoImages.cpp +@@ -27,7 +27,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include + #include +-#include + + namespace rtabmap + { +@@ -184,7 +183,7 @@ SensorData CameraStereoImages::captureImage(SensorCaptureInfo * info) + if(rightImage.type() != CV_8UC1 && rightGrayScale_) + { + cv::Mat tmp; +- cv::cvtColor(rightImage, tmp, CV_BGR2GRAY); ++ cv::cvtColor(rightImage, tmp, cv::COLOR_BGR2GRAY); + rightImage = tmp; + } + if(this->isImagesRectified() && stereoModel_.isValidForRectification()) +diff --git a/corelib/src/camera/CameraStereoTara.cpp b/corelib/src/camera/CameraStereoTara.cpp +index e4ea3cd..f4ec60a 100644 +--- a/corelib/src/camera/CameraStereoTara.cpp ++++ b/corelib/src/camera/CameraStereoTara.cpp +@@ -34,9 +34,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#if CV_MAJOR_VERSION > 3 +-#include +-#endif ++#include + + namespace rtabmap + { +@@ -81,18 +79,18 @@ bool CameraStereoTara::init(const std::string & calibrationFolder, const std::st + + capture_.open(usbDevice_); + +- capture_.set(CV_CAP_PROP_FOURCC, CV_FOURCC('Y', '1', '6', ' ')); +- capture_.set(CV_CAP_PROP_FPS, 60); +- capture_.set(CV_CAP_PROP_FRAME_WIDTH, 752); +- capture_.set(CV_CAP_PROP_FRAME_HEIGHT, 480); +- capture_.set(CV_CAP_PROP_CONVERT_RGB,false); ++ capture_.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('Y', '1', '6', ' ')); ++ capture_.set(cv::CAP_PROP_FPS, 60); ++ capture_.set(cv::CAP_PROP_FRAME_WIDTH, 752); ++ capture_.set(cv::CAP_PROP_FRAME_HEIGHT, 480); ++ capture_.set(cv::CAP_PROP_CONVERT_RGB,false); + + ULOGGER_DEBUG("CameraStereoTara: Usb device initialization on device %d", usbDevice_); + + + if (cameraName_.empty()) + { +- unsigned int guid = (unsigned int)capture_.get(CV_CAP_PROP_GUID); ++ unsigned int guid = (unsigned int)capture_.get(cv::CAP_PROP_GUID); + if (guid != 0 && guid != 0xffffffff) + { + cameraName_ = uFormat("%08x", guid); +diff --git a/corelib/src/camera/CameraStereoVideo.cpp b/corelib/src/camera/CameraStereoVideo.cpp +index f31f40b..5de23a6 100644 +--- a/corelib/src/camera/CameraStereoVideo.cpp ++++ b/corelib/src/camera/CameraStereoVideo.cpp +@@ -28,13 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include +-#if CV_MAJOR_VERSION > 3 +-#include +-#if CV_MAJOR_VERSION > 4 +-#include +-#endif +-#endif ++#include + + namespace rtabmap + { +@@ -172,7 +166,7 @@ bool CameraStereoVideo::init(const std::string & calibrationFolder, const std::s + + if (cameraName_.empty()) + { +- unsigned int guid = (unsigned int)capture_.get(CV_CAP_PROP_GUID); ++ unsigned int guid = (unsigned int)capture_.get(cv::CAP_PROP_GUID); + if (guid != 0 && guid != 0xffffffff) + { + cameraName_ = uFormat("%08x", guid); +@@ -214,17 +208,17 @@ bool CameraStereoVideo::init(const std::string & calibrationFolder, const std::s + if(capture_.isOpened()) + { + bool resolutionSet = false; +- resolutionSet = capture_.set(CV_CAP_PROP_FRAME_WIDTH, stereoModel_.left().imageWidth()*(capture2_.isOpened()?1:2)); +- resolutionSet = resolutionSet && capture_.set(CV_CAP_PROP_FRAME_HEIGHT, stereoModel_.left().imageHeight()); ++ resolutionSet = capture_.set(cv::CAP_PROP_FRAME_WIDTH, stereoModel_.left().imageWidth()*(capture2_.isOpened()?1:2)); ++ resolutionSet = resolutionSet && capture_.set(cv::CAP_PROP_FRAME_HEIGHT, stereoModel_.left().imageHeight()); + if(capture2_.isOpened()) + { +- resolutionSet = resolutionSet && capture2_.set(CV_CAP_PROP_FRAME_WIDTH, stereoModel_.right().imageWidth()); +- resolutionSet = resolutionSet && capture2_.set(CV_CAP_PROP_FRAME_HEIGHT, stereoModel_.right().imageHeight()); ++ resolutionSet = resolutionSet && capture2_.set(cv::CAP_PROP_FRAME_WIDTH, stereoModel_.right().imageWidth()); ++ resolutionSet = resolutionSet && capture2_.set(cv::CAP_PROP_FRAME_HEIGHT, stereoModel_.right().imageHeight()); + } + + // Check if the resolution was set successfully +- int actualWidth = int(capture_.get(CV_CAP_PROP_FRAME_WIDTH)); +- int actualHeight = int(capture_.get(CV_CAP_PROP_FRAME_HEIGHT)); ++ int actualWidth = int(capture_.get(cv::CAP_PROP_FRAME_WIDTH)); ++ int actualHeight = int(capture_.get(cv::CAP_PROP_FRAME_HEIGHT)); + if(!resolutionSet || + actualWidth != stereoModel_.left().imageWidth()*(capture2_.isOpened()?1:2) || + actualHeight != stereoModel_.left().imageHeight()) +@@ -244,17 +238,17 @@ bool CameraStereoVideo::init(const std::string & calibrationFolder, const std::s + if(capture_.isOpened()) + { + bool resolutionSet = false; +- resolutionSet = capture_.set(CV_CAP_PROP_FRAME_WIDTH, _width*(capture2_.isOpened()?1:2)); +- resolutionSet = resolutionSet && capture_.set(CV_CAP_PROP_FRAME_HEIGHT, _height); ++ resolutionSet = capture_.set(cv::CAP_PROP_FRAME_WIDTH, _width*(capture2_.isOpened()?1:2)); ++ resolutionSet = resolutionSet && capture_.set(cv::CAP_PROP_FRAME_HEIGHT, _height); + if(capture2_.isOpened()) + { +- resolutionSet = resolutionSet && capture2_.set(CV_CAP_PROP_FRAME_WIDTH, _width); +- resolutionSet = resolutionSet && capture2_.set(CV_CAP_PROP_FRAME_HEIGHT, _height); ++ resolutionSet = resolutionSet && capture2_.set(cv::CAP_PROP_FRAME_WIDTH, _width); ++ resolutionSet = resolutionSet && capture2_.set(cv::CAP_PROP_FRAME_HEIGHT, _height); + } + + // Check if the resolution was set successfully +- int actualWidth = int(capture_.get(CV_CAP_PROP_FRAME_WIDTH)); +- int actualHeight = int(capture_.get(CV_CAP_PROP_FRAME_HEIGHT)); ++ int actualWidth = int(capture_.get(cv::CAP_PROP_FRAME_WIDTH)); ++ int actualHeight = int(capture_.get(cv::CAP_PROP_FRAME_HEIGHT)); + if(!resolutionSet || + actualWidth != _width*(capture2_.isOpened()?1:2) || + actualHeight != _height) +@@ -273,10 +267,10 @@ bool CameraStereoVideo::init(const std::string & calibrationFolder, const std::s + if (this->getFrameRate() > 0) + { + bool fpsSupported = false; +- fpsSupported = capture_.set(CV_CAP_PROP_FPS, this->getFrameRate()); ++ fpsSupported = capture_.set(cv::CAP_PROP_FPS, this->getFrameRate()); + if (capture2_.isOpened()) + { +- fpsSupported = fpsSupported && capture2_.set(CV_CAP_PROP_FPS, this->getFrameRate()); ++ fpsSupported = fpsSupported && capture2_.set(cv::CAP_PROP_FPS, this->getFrameRate()); + } + if(fpsSupported) + { +@@ -310,14 +304,14 @@ bool CameraStereoVideo::init(const std::string & calibrationFolder, const std::s + std::string fourccUpperCase = uToUpperCase(_fourcc); + int fourcc = cv::VideoWriter::fourcc(fourccUpperCase.at(0), fourccUpperCase.at(1), fourccUpperCase.at(2), fourccUpperCase.at(3)); + bool fourccSupported = false; +- fourccSupported = capture_.set(CV_CAP_PROP_FOURCC, fourcc); ++ fourccSupported = capture_.set(cv::CAP_PROP_FOURCC, fourcc); + if (capture2_.isOpened()) + { +- fourccSupported = fourccSupported && capture2_.set(CV_CAP_PROP_FOURCC, fourcc); ++ fourccSupported = fourccSupported && capture2_.set(cv::CAP_PROP_FOURCC, fourcc); + } + + // Check if the FOURCC was set successfully +- int actualFourcc = int(capture_.get(CV_CAP_PROP_FOURCC)); ++ int actualFourcc = int(capture_.get(cv::CAP_PROP_FOURCC)); + + if(!fourccSupported || actualFourcc != fourcc) + { +@@ -386,7 +380,7 @@ SensorData CameraStereoVideo::captureImage(SensorCaptureInfo * info) + if(rightImage.type() != CV_8UC1 && rightGrayScale_) + { + cv::Mat tmp; +- cv::cvtColor(rightImage, tmp, CV_BGR2GRAY); ++ cv::cvtColor(rightImage, tmp, cv::COLOR_BGR2GRAY); + rightImage = tmp; + rightCvt = true; + } +diff --git a/corelib/src/camera/CameraStereoZedOC.cpp b/corelib/src/camera/CameraStereoZedOC.cpp +index 014976a..e3ba6d4 100644 +--- a/corelib/src/camera/CameraStereoZedOC.cpp ++++ b/corelib/src/camera/CameraStereoZedOC.cpp +@@ -38,6 +38,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include "SimpleIni.h" + ++#if CV_MAJOR_VERSION >= 5 ++#include ++#endif ++ + /////////////////////////////////////////////////////////////////////////// + // + // Copyright (c) 2018, STEREOLABS. +diff --git a/corelib/src/camera/CameraVideo.cpp b/corelib/src/camera/CameraVideo.cpp +index 9a0a70d..1776bca 100644 +--- a/corelib/src/camera/CameraVideo.cpp ++++ b/corelib/src/camera/CameraVideo.cpp +@@ -28,12 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#if CV_MAJOR_VERSION > 3 +-#include +-#if CV_MAJOR_VERSION > 4 +-#include +-#endif +-#endif ++#include + + namespace rtabmap + { +@@ -105,7 +100,7 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string + { + if (_guid.empty()) + { +- unsigned int guid = (unsigned int)_capture.get(CV_CAP_PROP_GUID); ++ unsigned int guid = (unsigned int)_capture.get(cv::CAP_PROP_GUID); + if (guid != 0 && guid != 0xffffffff) + { + _guid = uFormat("%08x", guid); +@@ -143,12 +138,12 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string + } + + bool resolutionSet = false; +- resolutionSet = _capture.set(CV_CAP_PROP_FRAME_WIDTH, _model.imageWidth()); +- resolutionSet = resolutionSet && _capture.set(CV_CAP_PROP_FRAME_HEIGHT, _model.imageHeight()); ++ resolutionSet = _capture.set(cv::CAP_PROP_FRAME_WIDTH, _model.imageWidth()); ++ resolutionSet = resolutionSet && _capture.set(cv::CAP_PROP_FRAME_HEIGHT, _model.imageHeight()); + + // Check if the resolution was set successfully +- int actualWidth = int(_capture.get(CV_CAP_PROP_FRAME_WIDTH)); +- int actualHeight = int(_capture.get(CV_CAP_PROP_FRAME_HEIGHT)); ++ int actualWidth = int(_capture.get(cv::CAP_PROP_FRAME_WIDTH)); ++ int actualHeight = int(_capture.get(cv::CAP_PROP_FRAME_HEIGHT)); + if(!resolutionSet || + actualWidth != _model.imageWidth() || + actualHeight != _model.imageHeight()) +@@ -165,12 +160,12 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string + else if(_width > 0 && _height > 0) + { + int resolutionSet = false; +- resolutionSet = _capture.set(CV_CAP_PROP_FRAME_WIDTH, _width); +- resolutionSet = resolutionSet && _capture.set(CV_CAP_PROP_FRAME_HEIGHT, _height); ++ resolutionSet = _capture.set(cv::CAP_PROP_FRAME_WIDTH, _width); ++ resolutionSet = resolutionSet && _capture.set(cv::CAP_PROP_FRAME_HEIGHT, _height); + + // Check if the resolution was set successfully +- int actualWidth = int(_capture.get(CV_CAP_PROP_FRAME_WIDTH)); +- int actualHeight = int(_capture.get(CV_CAP_PROP_FRAME_HEIGHT)); ++ int actualWidth = int(_capture.get(cv::CAP_PROP_FRAME_WIDTH)); ++ int actualHeight = int(_capture.get(cv::CAP_PROP_FRAME_HEIGHT)); + if(!resolutionSet || actualWidth != _width || actualHeight != _height) + { + UWARN("Desired resolution (%dx%d) cannot be set to camera driver, " +@@ -182,7 +177,7 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string + } + + // Set FPS +- if (this->getFrameRate() > 0 && _capture.set(CV_CAP_PROP_FPS, this->getFrameRate())) ++ if (this->getFrameRate() > 0 && _capture.set(cv::CAP_PROP_FPS, this->getFrameRate())) + { + // Check if the FPS was set successfully + double actualFPS = _capture.get(cv::CAP_PROP_FPS); +@@ -213,10 +208,10 @@ bool CameraVideo::init(const std::string & calibrationFolder, const std::string + std::string fourccUpperCase = uToUpperCase(_fourcc); + int fourcc = cv::VideoWriter::fourcc(fourccUpperCase.at(0), fourccUpperCase.at(1), fourccUpperCase.at(2), fourccUpperCase.at(3)); + +- bool fourccSupported = _capture.set(CV_CAP_PROP_FOURCC, fourcc); ++ bool fourccSupported = _capture.set(cv::CAP_PROP_FOURCC, fourcc); + + // Check if the FOURCC was set successfully +- int actualFourcc = int(_capture.get(CV_CAP_PROP_FOURCC)); ++ int actualFourcc = int(_capture.get(cv::CAP_PROP_FOURCC)); + + if(!fourccSupported || actualFourcc != fourcc) + { +diff --git a/corelib/src/odometry/OdometryDVO.cpp b/corelib/src/odometry/OdometryDVO.cpp +index 2f7190d..a1e425d 100644 +--- a/corelib/src/odometry/OdometryDVO.cpp ++++ b/corelib/src/odometry/OdometryDVO.cpp +@@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/ULogger.h" + #include "rtabmap/utilite/UTimer.h" + #include "rtabmap/utilite/UStl.h" +-#include + + #ifdef RTABMAP_DVO + #include +@@ -124,7 +123,7 @@ Transform OdometryDVO::computeTransform( + { + if(data.imageRaw().type() == CV_8UC3) + { +- cv::cvtColor(data.imageRaw(), grey, CV_BGR2GRAY); ++ cv::cvtColor(data.imageRaw(), grey, cv::COLOR_BGR2GRAY); + } + else + { +diff --git a/corelib/src/odometry/OdometryF2M.cpp b/corelib/src/odometry/OdometryF2M.cpp +index 58d0e3a..63b096d 100644 +--- a/corelib/src/odometry/OdometryF2M.cpp ++++ b/corelib/src/odometry/OdometryF2M.cpp +@@ -42,7 +42,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UTimer.h" + #include "rtabmap/utilite/UMath.h" + #include "rtabmap/utilite/UConversion.h" ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + +diff --git a/corelib/src/odometry/OdometryFovis.cpp b/corelib/src/odometry/OdometryFovis.cpp +index 673639a..c1f5a99 100644 +--- a/corelib/src/odometry/OdometryFovis.cpp ++++ b/corelib/src/odometry/OdometryFovis.cpp +@@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/ULogger.h" + #include "rtabmap/utilite/UTimer.h" + #include "rtabmap/utilite/UStl.h" +-#include + + #ifdef RTABMAP_FOVIS + #include +@@ -137,7 +136,7 @@ Transform OdometryFovis::computeTransform( + cv::Mat gray; + if(data.imageRaw().type() == CV_8UC3) + { +- cv::cvtColor(data.imageRaw(), gray, CV_BGR2GRAY); ++ cv::cvtColor(data.imageRaw(), gray, cv::COLOR_BGR2GRAY); + } + else if(data.imageRaw().type() == CV_8UC1) + { +@@ -302,7 +301,7 @@ Transform OdometryFovis::computeTransform( + } + if(data.rightRaw().type() == CV_8UC3) + { +- cv::cvtColor(data.rightRaw(), right, CV_BGR2GRAY); ++ cv::cvtColor(data.rightRaw(), right, cv::COLOR_BGR2GRAY); + } + else if(data.rightRaw().type() == CV_8UC1) + { +diff --git a/corelib/src/odometry/OdometryMSCKF.cpp b/corelib/src/odometry/OdometryMSCKF.cpp +index ac62c25..709f9d1 100644 +--- a/corelib/src/odometry/OdometryMSCKF.cpp ++++ b/corelib/src/odometry/OdometryMSCKF.cpp +@@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UTimer.h" + #include "rtabmap/utilite/UStl.h" + #include "rtabmap/utilite/UThread.h" +-#include + + #ifdef RTABMAP_MSCKF_VIO + #include +@@ -867,7 +866,7 @@ Transform OdometryMSCKF::computeTransform( + + if(data.imageRaw().type() == CV_8UC3) + { +- cv::cvtColor(data.imageRaw(), cam0.image, CV_BGR2GRAY); ++ cv::cvtColor(data.imageRaw(), cam0.image, cv::COLOR_BGR2GRAY); + } + else + { +@@ -875,7 +874,7 @@ Transform OdometryMSCKF::computeTransform( + } + if(data.rightRaw().type() == CV_8UC3) + { +- cv::cvtColor(data.rightRaw(), cam1.image, CV_BGR2GRAY); ++ cv::cvtColor(data.rightRaw(), cam1.image, cv::COLOR_BGR2GRAY); + } + else + { +diff --git a/corelib/src/odometry/OdometryMono.cpp b/corelib/src/odometry/OdometryMono.cpp +index b942aa8..e29e2e2 100644 +--- a/corelib/src/odometry/OdometryMono.cpp ++++ b/corelib/src/odometry/OdometryMono.cpp +@@ -43,7 +43,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UStl.h" + #include "rtabmap/utilite/UMath.h" + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + +diff --git a/corelib/src/odometry/OdometryORBSLAM2.cpp b/corelib/src/odometry/OdometryORBSLAM2.cpp +index 1ae10bc..616678c 100644 +--- a/corelib/src/odometry/OdometryORBSLAM2.cpp ++++ b/corelib/src/odometry/OdometryORBSLAM2.cpp +@@ -33,7 +33,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UStl.h" + #include "rtabmap/utilite/UDirectory.h" + #include +-#include + #include + + #if defined(RTABMAP_ORB_SLAM) and RTABMAP_ORB_SLAM == 2 +@@ -426,7 +425,7 @@ public: + } + else + { +- cvtColor(mImGray,mImGray,CV_BGR2GRAY); ++ cvtColor(mImGray,mImGray,cv::COLOR_BGR2GRAY); + } + } + else if(mImGray.channels()==4) +@@ -437,7 +436,7 @@ public: + } + else + { +- cvtColor(mImGray,mImGray,CV_BGRA2GRAY); ++ cvtColor(mImGray,mImGray,cv::COLOR_BGRA2GRAY); + } + } + if(imGrayRight.channels()==3) +@@ -448,7 +447,7 @@ public: + } + else + { +- cvtColor(imGrayRight,imGrayRight,CV_BGR2GRAY); ++ cvtColor(imGrayRight,imGrayRight,cv::COLOR_BGR2GRAY); + } + } + else if(imGrayRight.channels()==4) +@@ -459,7 +458,7 @@ public: + } + else + { +- cvtColor(imGrayRight,imGrayRight,CV_BGRA2GRAY); ++ cvtColor(imGrayRight,imGrayRight,cv::COLOR_BGRA2GRAY); + } + } + +@@ -480,14 +479,14 @@ public: + if(mbRGB) + cvtColor(mImGray,mImGray,CV_RGB2GRAY); + else +- cvtColor(mImGray,mImGray,CV_BGR2GRAY); ++ cvtColor(mImGray,mImGray,cv::COLOR_BGR2GRAY); + } + else if(mImGray.channels()==4) + { + if(mbRGB) + cvtColor(mImGray,mImGray,CV_RGBA2GRAY); + else +- cvtColor(mImGray,mImGray,CV_BGRA2GRAY); ++ cvtColor(mImGray,mImGray,cv::COLOR_BGRA2GRAY); + } + + UASSERT(imDepth.type()==CV_32F); +diff --git a/corelib/src/odometry/OdometryORBSLAM3.cpp b/corelib/src/odometry/OdometryORBSLAM3.cpp +index f0e5d64..77e7d45 100644 +--- a/corelib/src/odometry/OdometryORBSLAM3.cpp ++++ b/corelib/src/odometry/OdometryORBSLAM3.cpp +@@ -34,7 +34,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UDirectory.h" + #include "rtabmap/utilite/UFile.h" + #include +-#include + #include + + #if defined(RTABMAP_ORB_SLAM) and RTABMAP_ORB_SLAM == 3 +@@ -469,12 +468,12 @@ Transform OdometryORBSLAM3::computeTransform( + cv::Mat leftMono = data.imageRaw(); + if(data.imageRaw().channels() == 3) { + leftMono = cv::Mat(); +- cv::cvtColor(data.imageRaw(), leftMono, CV_BGR2GRAY); ++ cv::cvtColor(data.imageRaw(), leftMono, cv::COLOR_BGR2GRAY); + } + cv::Mat rightMono = data.rightRaw(); + if(data.rightRaw().channels() == 3) { + rightMono = cv::Mat(); +- cv::cvtColor(data.imageRaw(), rightMono, CV_BGR2GRAY); ++ cv::cvtColor(data.imageRaw(), rightMono, cv::COLOR_BGR2GRAY); + } + UDEBUG("Adding Stereo Frame %f", data.stamp()); + Tcw = orbslam_->TrackStereo(leftMono, rightMono, data.stamp(), orbslamImus_); +diff --git a/corelib/src/odometry/OdometryOkvis.cpp b/corelib/src/odometry/OdometryOkvis.cpp +index 10497b9..7c97e27 100644 +--- a/corelib/src/odometry/OdometryOkvis.cpp ++++ b/corelib/src/odometry/OdometryOkvis.cpp +@@ -34,7 +34,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UThread.h" + #include "rtabmap/utilite/UFile.h" + #include "rtabmap/utilite/UDirectory.h" +-#include + + #ifdef RTABMAP_OKVIS + #include +@@ -427,7 +426,7 @@ Transform OdometryOkvis::computeTransform( + cv::Mat gray; + if(images[i].type() == CV_8UC3) + { +- cv::cvtColor(images[i], gray, CV_BGR2GRAY); ++ cv::cvtColor(images[i], gray, cv::COLOR_BGR2GRAY); + } + else if(images[i].type() == CV_8UC1) + { +diff --git a/corelib/src/odometry/OdometryOpenVINS.cpp b/corelib/src/odometry/OdometryOpenVINS.cpp +index e953968..4c9dcc4 100644 +--- a/corelib/src/odometry/OdometryOpenVINS.cpp ++++ b/corelib/src/odometry/OdometryOpenVINS.cpp +@@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/ULogger.h" + #include "rtabmap/utilite/UTimer.h" + #include +-#include + + #ifdef RTABMAP_OPENVINS + #include "core/VioManager.h" +@@ -419,7 +418,7 @@ Transform OdometryOpenVINS::computeTransform( + + cv::Mat image; + if(data.imageRaw().type() == CV_8UC3) +- cv::cvtColor(data.imageRaw(), image, CV_BGR2GRAY); ++ cv::cvtColor(data.imageRaw(), image, cv::COLOR_BGR2GRAY); + else if(data.imageRaw().type() == CV_8UC1) + image = data.imageRaw().clone(); + else +@@ -450,7 +449,7 @@ Transform OdometryOpenVINS::computeTransform( + if(!data.rightRaw().empty()) + { + if(data.rightRaw().type() == CV_8UC3) +- cv::cvtColor(data.rightRaw(), image, CV_BGR2GRAY); ++ cv::cvtColor(data.rightRaw(), image, cv::COLOR_BGR2GRAY); + else if(data.rightRaw().type() == CV_8UC1) + image = data.rightRaw().clone(); + else +diff --git a/corelib/src/odometry/OdometryVINSFusion.cpp b/corelib/src/odometry/OdometryVINSFusion.cpp +index 9c63360..9677940 100644 +--- a/corelib/src/odometry/OdometryVINSFusion.cpp ++++ b/corelib/src/odometry/OdometryVINSFusion.cpp +@@ -33,7 +33,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UStl.h" + #include "rtabmap/utilite/UThread.h" + #include "rtabmap/utilite/UDirectory.h" +-#include + + #ifdef RTABMAP_VINS_FUSION + #include +@@ -444,7 +443,7 @@ Transform OdometryVINSFusion::computeTransform( + cv::Mat right; + if(data.imageRaw().type() == CV_8UC3) + { +- cv::cvtColor(data.imageRaw(), left, CV_BGR2GRAY); ++ cv::cvtColor(data.imageRaw(), left, cv::COLOR_BGR2GRAY); + } + else if(data.imageRaw().type() == CV_8UC1) + { +@@ -456,7 +455,7 @@ Transform OdometryVINSFusion::computeTransform( + } + if(data.rightRaw().type() == CV_8UC3) + { +- cv::cvtColor(data.rightRaw(), right, CV_BGR2GRAY); ++ cv::cvtColor(data.rightRaw(), right, cv::COLOR_BGR2GRAY); + } + else if(data.rightRaw().type() == CV_8UC1) + { +diff --git a/corelib/src/odometry/OdometryViso2.cpp b/corelib/src/odometry/OdometryViso2.cpp +index 808e763..dc6192b 100644 +--- a/corelib/src/odometry/OdometryViso2.cpp ++++ b/corelib/src/odometry/OdometryViso2.cpp +@@ -31,7 +31,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/ULogger.h" + #include "rtabmap/utilite/UTimer.h" + #include "rtabmap/utilite/UStl.h" +-#include + + #ifdef RTABMAP_VISO2 + #include +@@ -131,7 +130,7 @@ Transform OdometryViso2::computeTransform( + cv::Mat leftGray; + if(data.imageRaw().type() == CV_8UC3) + { +- cv::cvtColor(data.imageRaw(), leftGray, CV_BGR2GRAY); ++ cv::cvtColor(data.imageRaw(), leftGray, cv::COLOR_BGR2GRAY); + } + else if(data.imageRaw().type() == CV_8UC1) + { +@@ -144,7 +143,7 @@ Transform OdometryViso2::computeTransform( + cv::Mat rightGray; + if(data.rightRaw().type() == CV_8UC3) + { +- cv::cvtColor(data.rightRaw(), rightGray, CV_BGR2GRAY); ++ cv::cvtColor(data.rightRaw(), rightGray, cv::COLOR_BGR2GRAY); + } + else if(data.rightRaw().type() == CV_8UC1) + { +diff --git a/corelib/src/opencv/ORBextractor.cc b/corelib/src/opencv/ORBextractor.cc +index 2d3cd7c..542e169 100644 +--- a/corelib/src/opencv/ORBextractor.cc ++++ b/corelib/src/opencv/ORBextractor.cc +@@ -64,7 +64,11 @@ + + #include + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + #include +diff --git a/corelib/src/opencv/ORBextractor.h b/corelib/src/opencv/ORBextractor.h +index 861ca05..82ede5b 100644 +--- a/corelib/src/opencv/ORBextractor.h ++++ b/corelib/src/opencv/ORBextractor.h +@@ -31,8 +31,6 @@ + + #include + #include +-#include +- + + namespace rtabmap + { +diff --git a/corelib/src/opencv/Orb.cpp b/corelib/src/opencv/Orb.cpp +index f56874e..c5034a7 100644 +--- a/corelib/src/opencv/Orb.cpp ++++ b/corelib/src/opencv/Orb.cpp +@@ -40,7 +40,6 @@ + + #include "opencv2/features2d/features2d.hpp" + #include "opencv2/imgproc/imgproc.hpp" +-#include "opencv2/imgproc/imgproc_c.h" + #include + #include + +@@ -252,7 +251,7 @@ static void computeOrbDescriptor(const KeyPoint& kpt, + } + } + else +- CV_Error( CV_StsBadSize, "Wrong WTA_K. It can be only 2, 3 or 4." ); ++ CV_Error( cv::Error::StsBadSize, "Wrong WTA_K. It can be only 2, 3 or 4." ); + + #undef GET_VALUE + } +@@ -752,7 +751,7 @@ void CV_ORB::operator()( InputArray _image, InputArray _mask, std::vectornlevels; + +diff --git a/corelib/src/opencv/five-point.h b/corelib/src/opencv/five-point.h +index 1a5b778..f1aa8c7 100644 +--- a/corelib/src/opencv/five-point.h ++++ b/corelib/src/opencv/five-point.h +@@ -8,6 +8,10 @@ + #ifndef CORELIB_SRC_OPENCV_FIVE_POINT_H_ + #define CORELIB_SRC_OPENCV_FIVE_POINT_H_ + ++#if CV_MAJOR_VERSION > 4 ++#include ++#endif ++ + namespace cv3 + { + +diff --git a/corelib/src/opencv/solvepnp.cpp b/corelib/src/opencv/solvepnp.cpp +index f5b3a07..ecd2be9 100644 +--- a/corelib/src/opencv/solvepnp.cpp ++++ b/corelib/src/opencv/solvepnp.cpp +@@ -53,7 +53,7 @@ class PnPRansacCallback : public PointSetRegistrator::Callback + + public: + +- PnPRansacCallback(Mat _cameraMatrix=Mat(3,3,CV_64F), Mat _distCoeffs=Mat(4,1,CV_64F), int _flags=CV_ITERATIVE, ++ PnPRansacCallback(Mat _cameraMatrix=Mat(3,3,CV_64F), Mat _distCoeffs=Mat(4,1,CV_64F), int _flags=cv::SOLVEPNP_ITERATIVE, + bool _useExtrinsicGuess=false, Mat _rvec=Mat(), Mat _tvec=Mat() ) + : cameraMatrix(_cameraMatrix), distCoeffs(_distCoeffs), flags(_flags), useExtrinsicGuess(_useExtrinsicGuess), + rvec(_rvec), tvec(_tvec) {} +@@ -142,12 +142,12 @@ bool solvePnPRansac(InputArray _opoints, InputArray _ipoints, + Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat(); + + int model_points = 6; +- int ransac_kernel_method = CV_EPNP; ++ int ransac_kernel_method = cv::SOLVEPNP_EPNP; + + if( npoints == 4 ) + { + model_points = 4; +- ransac_kernel_method = CV_P3P; ++ ransac_kernel_method = cv::SOLVEPNP_P3P; + } + + Ptr cb; // pointer to callback +@@ -178,7 +178,7 @@ bool solvePnPRansac(InputArray _opoints, InputArray _ipoints, + opoints_inliers.resize(npoints1); + ipoints_inliers.resize(npoints1); + result = solvePnP(opoints_inliers, ipoints_inliers, cameraMatrix, +- distCoeffs, rvec, tvec, useExtrinsicGuess, flags == CV_P3P ? CV_EPNP : flags) ? 1 : -1; ++ distCoeffs, rvec, tvec, useExtrinsicGuess, flags == cv::SOLVEPNP_P3P ? cv::SOLVEPNP_EPNP : flags) ? 1 : -1; + } + + if( result <= 0 || _local_model.rows <= 0) +@@ -213,7 +213,7 @@ bool solvePnPRansac(InputArray _opoints, InputArray _ipoints, + int RANSACUpdateNumIters( double p, double ep, int modelPoints, int maxIters ) + { + if( modelPoints <= 0 ) +- CV_Error( 0, "the number of model points should be positive" ); ++ CV_Error( cv::Error::Code::StsBadArg, "the number of model points should be positive" ); + + p = MAX(p, 0.); + p = MIN(p, 1.); +diff --git a/corelib/src/opencv/solvepnp.h b/corelib/src/opencv/solvepnp.h +index e88b570..382f9db 100644 +--- a/corelib/src/opencv/solvepnp.h ++++ b/corelib/src/opencv/solvepnp.h +@@ -45,9 +45,10 @@ + #define RTABMAP_CORELIB_SRC_OPENCV_SOLVEPNP_H_ + + #include ++#if CV_MAJOR_VERSION >= 5 ++#include ++#else + #include +-#if CV_MAJOR_VERSION >= 3 +-#include + #endif + + namespace cv3 { +@@ -95,7 +96,7 @@ bool solvePnPRansac( cv::InputArray objectPoints, cv::InputArray imagePoints, + cv::OutputArray rvec, cv::OutputArray tvec, + bool useExtrinsicGuess = false, int iterationsCount = 100, + float reprojectionError = 8.0, double confidence = 0.99, +- cv::OutputArray inliers = cv::noArray(), int flags = CV_ITERATIVE ); ++ cv::OutputArray inliers = cv::noArray(), int flags = cv::SOLVEPNP_ITERATIVE ); + + int RANSACUpdateNumIters( double p, double ep, int modelPoints, int maxIters ); + +diff --git a/corelib/src/optimizer/OptimizerCeres.cpp b/corelib/src/optimizer/OptimizerCeres.cpp +index 046d401..d2d64c3 100644 +--- a/corelib/src/optimizer/OptimizerCeres.cpp ++++ b/corelib/src/optimizer/OptimizerCeres.cpp +@@ -26,6 +26,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "rtabmap/core/Graph.h" + ++#if CV_MAJOR_VERSION < 5 ++#include ++#else ++#include ++#endif ++ + #include + #include + #include +diff --git a/corelib/src/stereo/StereoBM.cpp b/corelib/src/stereo/StereoBM.cpp +index 1b390c6..57f6b7d 100644 +--- a/corelib/src/stereo/StereoBM.cpp ++++ b/corelib/src/stereo/StereoBM.cpp +@@ -27,9 +27,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#include ++#endif + #include +-#include + + namespace rtabmap { + +@@ -88,7 +92,7 @@ cv::Mat StereoBM::computeDisparity( + cv::Mat leftMono; + if(leftImage.channels() == 3) + { +- cv::cvtColor(leftImage, leftMono, CV_BGR2GRAY); ++ cv::cvtColor(leftImage, leftMono, cv::COLOR_BGR2GRAY); + } + else + { +@@ -98,7 +102,7 @@ cv::Mat StereoBM::computeDisparity( + cv::Mat rightMono; + if(rightImage.channels() == 3) + { +- cv::cvtColor(rightImage, rightMono, CV_BGR2GRAY); ++ cv::cvtColor(rightImage, rightMono, cv::COLOR_BGR2GRAY); + } + else + { +diff --git a/corelib/src/stereo/StereoSGBM.cpp b/corelib/src/stereo/StereoSGBM.cpp +index 6763aeb..d8e651a 100644 +--- a/corelib/src/stereo/StereoSGBM.cpp ++++ b/corelib/src/stereo/StereoSGBM.cpp +@@ -27,9 +27,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#include ++#endif + #include +-#include + + namespace rtabmap { + +@@ -77,7 +81,7 @@ cv::Mat StereoSGBM::computeDisparity( + cv::Mat leftMono; + if(leftImage.channels() == 3) + { +- cv::cvtColor(leftImage, leftMono, CV_BGR2GRAY); ++ cv::cvtColor(leftImage, leftMono, cv::COLOR_BGR2GRAY); + } + else + { +@@ -87,7 +91,7 @@ cv::Mat StereoSGBM::computeDisparity( + cv::Mat rightMono; + if(rightImage.channels() == 3) + { +- cv::cvtColor(rightImage, rightMono, CV_BGR2GRAY); ++ cv::cvtColor(rightImage, rightMono, cv::COLOR_BGR2GRAY); + } + else + { +diff --git a/corelib/src/util2d.cpp b/corelib/src/util2d.cpp +index 0251d0f..0c9318f 100644 +--- a/corelib/src/util2d.cpp ++++ b/corelib/src/util2d.cpp +@@ -34,11 +34,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + #include + #include + #include +-#include + #include + #include + +@@ -46,6 +44,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #endif + ++#if CV_MAJOR_VERSION < 5 ++#include ++#else ++#include ++#endif ++ + namespace rtabmap + { + +@@ -747,7 +751,7 @@ cv::Mat disparityFromStereoImages( + cv::Mat leftMono; + if(leftImage.channels() == 3) + { +- cv::cvtColor(leftImage, leftMono, CV_BGR2GRAY); ++ cv::cvtColor(leftImage, leftMono, cv::COLOR_BGR2GRAY); + } + else + { +@@ -2042,8 +2046,8 @@ cv::Mat brightnessAndContrastAuto(const cv::Mat &src, const cv::Mat & mask, floa + //to calculate grayscale histogram + cv::Mat gray; + if (src.type() == CV_8UC1) gray = src; +- else if (src.type() == CV_8UC3) cvtColor(src, gray, CV_BGR2GRAY); +- else if (src.type() == CV_8UC4) cvtColor(src, gray, CV_BGRA2GRAY); ++ else if (src.type() == CV_8UC3) cvtColor(src, gray, cv::COLOR_BGR2GRAY); ++ else if (src.type() == CV_8UC4) cvtColor(src, gray, cv::COLOR_BGRA2GRAY); + if (clipLowHistPercent == 0 && clipHighHistPercent == 0) + { + // keep full available range +diff --git a/corelib/src/util3d.cpp b/corelib/src/util3d.cpp +index facb0d6..dfad02a 100644 +--- a/corelib/src/util3d.cpp ++++ b/corelib/src/util3d.cpp +@@ -41,7 +41,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + + namespace rtabmap + { +@@ -892,7 +891,7 @@ pcl::PointCloud::Ptr cloudFromStereoImages( + cv::Mat leftMono; + if(leftColor.channels() == 3) + { +- cv::cvtColor(leftColor, leftMono, CV_BGR2GRAY); ++ cv::cvtColor(leftColor, leftMono, cv::COLOR_BGR2GRAY); + } + else + { +@@ -902,7 +901,7 @@ pcl::PointCloud::Ptr cloudFromStereoImages( + cv::Mat rightMono; + if(rightColor.channels() == 3) + { +- cv::cvtColor(rightColor, rightMono, CV_BGR2GRAY); ++ cv::cvtColor(rightColor, rightMono, cv::COLOR_BGR2GRAY); + } + else + { +@@ -1038,7 +1037,7 @@ std::vector::Ptr> cloudsFromSensorData( + cv::Mat leftMono; + if(sensorData.imageRaw().channels() == 3) + { +- cv::cvtColor(sensorData.imageRaw(), leftMono, CV_BGR2GRAY); ++ cv::cvtColor(sensorData.imageRaw(), leftMono, cv::COLOR_BGR2GRAY); + } + else + { +@@ -1048,7 +1047,7 @@ std::vector::Ptr> cloudsFromSensorData( + cv::Mat rightMono; + if(sensorData.rightRaw().channels() == 3) + { +- cv::cvtColor(sensorData.rightRaw(), rightMono, CV_BGR2GRAY); ++ cv::cvtColor(sensorData.rightRaw(), rightMono, cv::COLOR_BGR2GRAY); + } + else + { +diff --git a/corelib/src/util3d_correspondences.cpp b/corelib/src/util3d_correspondences.cpp +index 5a81869..41cc1e6 100644 +--- a/corelib/src/util3d_correspondences.cpp ++++ b/corelib/src/util3d_correspondences.cpp +@@ -30,7 +30,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + +diff --git a/corelib/src/util3d_surface.cpp b/corelib/src/util3d_surface.cpp +index bccae36..3625426 100644 +--- a/corelib/src/util3d_surface.cpp ++++ b/corelib/src/util3d_surface.cpp +@@ -39,8 +39,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UConversion.h" + #include "rtabmap/utilite/UMath.h" + #include "rtabmap/utilite/UTimer.h" +-#include +-#include + #include + #include + #include +@@ -1745,7 +1743,7 @@ cv::Mat mergeTextures( + if(resizedImage.type() == CV_8UC1) + { + cv::Mat resizedImageColor; +- cv::cvtColor(resizedImage, resizedImageColor, CV_GRAY2BGR); ++ cv::cvtColor(resizedImage, resizedImageColor, cv::COLOR_GRAY2BGR); + resizedImage = resizedImageColor; + } + UASSERT(resizedImage.type() == globalTextures.type()); +@@ -2609,7 +2607,7 @@ bool multiBandTexturing( + if(imageRoi.channels() == 1) + { + cv::Mat imageRoiColor; +- cv::cvtColor(imageRoi, imageRoiColor, CV_GRAY2BGR); ++ cv::cvtColor(imageRoi, imageRoiColor, cv::COLOR_GRAY2BGR); + imageRoi = imageRoiColor; + } + +@@ -3218,7 +3216,7 @@ float computeNormalsComplexity( + } + if(oi>1) + { +- cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), CV_PCA_DATA_AS_ROW); ++ cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), cv::PCA::DATA_AS_ROW); + + if(pcaEigenVectors) + { +@@ -3279,7 +3277,7 @@ float computeNormalsComplexity( + } + if(oi>1) + { +- cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), CV_PCA_DATA_AS_ROW); ++ cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), cv::PCA::DATA_AS_ROW); + + if(pcaEigenVectors) + { +@@ -3335,7 +3333,7 @@ float computeNormalsComplexity( + } + if(oi>1) + { +- cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), CV_PCA_DATA_AS_ROW); ++ cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), cv::PCA::DATA_AS_ROW); + + if(pcaEigenVectors) + { +@@ -3391,7 +3389,7 @@ float computeNormalsComplexity( + } + if(oi>1) + { +- cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), CV_PCA_DATA_AS_ROW); ++ cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), cv::PCA::DATA_AS_ROW); + + if(pcaEigenVectors) + { +@@ -3447,7 +3445,7 @@ float computeNormalsComplexity( + } + if(oi>1) + { +- cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), CV_PCA_DATA_AS_ROW); ++ cv::PCA pca_analysis(cv::Mat(data_normals, cv::Range(0, oi*2)), cv::Mat(), cv::PCA::DATA_AS_ROW); + + if(pcaEigenVectors) + { +diff --git a/guilib/include/rtabmap/gui/DatabaseViewer.h b/guilib/include/rtabmap/gui/DatabaseViewer.h +index 07f9494..bcd6735 100644 +--- a/guilib/include/rtabmap/gui/DatabaseViewer.h ++++ b/guilib/include/rtabmap/gui/DatabaseViewer.h +@@ -36,7 +36,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include + #include +diff --git a/guilib/include/rtabmap/gui/ImageView.h b/guilib/include/rtabmap/gui/ImageView.h +index 8e8df85..95e4ff8 100644 +--- a/guilib/include/rtabmap/gui/ImageView.h ++++ b/guilib/include/rtabmap/gui/ImageView.h +@@ -34,7 +34,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include ++#include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include + #include "rtabmap/utilite/UCv2Qt.h" + #include +diff --git a/guilib/include/rtabmap/gui/KeypointItem.h b/guilib/include/rtabmap/gui/KeypointItem.h +index 7f4f9f6..30db5c3 100644 +--- a/guilib/include/rtabmap/gui/KeypointItem.h ++++ b/guilib/include/rtabmap/gui/KeypointItem.h +@@ -34,7 +34,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include ++#include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + + namespace rtabmap { + +diff --git a/guilib/src/CalibrationDialog.cpp b/guilib/src/CalibrationDialog.cpp +index f6b27fe..3fd4530 100644 +--- a/guilib/src/CalibrationDialog.cpp ++++ b/guilib/src/CalibrationDialog.cpp +@@ -28,15 +28,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/gui/CalibrationDialog.h" + #include "ui_calibrationDialog.h" + ++#include + #include + #include +-#include ++#if CV_MAJOR_VERSION >= 5 ++#include ++#include ++#else + #include +-#if CV_MAJOR_VERSION >= 3 +-#include + #endif + #include +-#if CV_MAJOR_VERSION > 2 or (CV_MAJOR_VERSION == 2 and (CV_MINOR_VERSION >4 or (CV_MINOR_VERSION == 4 and CV_SUBMINOR_VERSION >=10))) ++#if (CV_MAJOR_VERSION > 2 and CV_MAJOR_VERSION < 5) or (CV_MAJOR_VERSION == 2 and (CV_MINOR_VERSION >4 or (CV_MINOR_VERSION == 4 and CV_SUBMINOR_VERSION >=10))) + #include + #endif + +@@ -276,18 +278,23 @@ void CalibrationDialog::generateBoard() + if(ui_->comboBox_board_type->currentIndex() >= 1 ) + { + try { ++ const int marginInPixels = squareSizeInPixels/4; ++ cv::Size size( ++ squareSizeInPixels*ui_->spinBox_boardWidth->value() + 2*marginInPixels, ++ squareSizeInPixels*ui_->spinBox_boardHeight->value() + 2*marginInPixels); ++ UINFO("Creating board image of %dx%d pixels (%dx%d squares)", ++ size.width, size.height, ++ ui_->spinBox_boardWidth->value(), ui_->spinBox_boardHeight->value()); + #if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7) + charucoBoard_->generateImage( +- cv::Size(squareSizeInPixels*ui_->spinBox_boardWidth->value(), +- squareSizeInPixels*ui_->spinBox_boardHeight->value()), ++ size, + image, +- squareSizeInPixels/4, 1); ++ marginInPixels, 1); + #else + charucoBoard_->draw( +- cv::Size(squareSizeInPixels*ui_->spinBox_boardWidth->value(), +- squareSizeInPixels*ui_->spinBox_boardHeight->value()), ++ size, + image, +- squareSizeInPixels/4, 1); ++ marginInPixels, 1); + #endif + + int arucoDict = ui_->comboBox_marker_dictionary->currentIndex(); +@@ -297,7 +304,7 @@ void CalibrationDialog::generateBoard() + } + catch(const cv::Exception & e) + { +- UERROR("%f", e.what()); ++ UERROR("%s", e.what()); + QMessageBox::critical(this, tr("Generating Board"), + tr("Cannot generate the board. Make sure the dictionary " + "selected is big enough for the board size. Error:\"%1\"").arg(e.what())); +@@ -737,7 +744,7 @@ void CalibrationDialog::processImages(const cv::Mat & imageLeft, const cv::Mat & + cv::Size boardSize(ui_->spinBox_boardWidth->value(), ui_->spinBox_boardHeight->value()); + if(!viewGray.empty()) + { +- int flags = CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE; ++ int flags = cv::CALIB_CB_ADAPTIVE_THRESH | cv::CALIB_CB_NORMALIZE_IMAGE; + + if(!viewGray.empty()) + { +@@ -748,7 +755,7 @@ void CalibrationDialog::processImages(const cv::Mat & imageLeft, const cv::Mat & + if( scale == 1 ) + timg = viewGray; + else +- cv::resize(viewGray, timg, cv::Size(), scale, scale, CV_INTER_CUBIC); ++ cv::resize(viewGray, timg, cv::Size(), scale, scale, cv::INTER_CUBIC); + + #ifdef HAVE_CHARUCO + if(ui_->comboBox_board_type->currentIndex() >= 1 ) +@@ -833,7 +840,7 @@ void CalibrationDialog::processImages(const cv::Mat & imageLeft, const cv::Mat & + float ratio = ui_->comboBox_board_type->currentIndex() >= 1 ?6.0f:2.0f; + float radius = minSquareDistance==-1.0f?5.0f:(minSquareDistance/ratio); + cv::cornerSubPix( viewGray, pointBuf[id], cv::Size(radius, radius), cv::Size(-1,-1), +- cv::TermCriteria( CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1 )); ++ cv::TermCriteria( cv::TermCriteria::EPS + cv::TermCriteria::MAX_ITER, 30, 0.1 )); + + // Filter points that drifted to far (caused by reflection or bad subpixel gradient) + float threshold = ui_->doubleSpinBox_subpixel_error->value(); +@@ -1388,6 +1395,13 @@ void CalibrationDialog::calibrate() + UINFO("Calibrating camera %d (samples=%d)", id, (int)imagePoints_[id].size()); + logStream << "Calibrating camera " << id << " (samples=" << imagePoints_[id].size() << ")" << ENDL; + ++ // Work on local copies: the fisheye auto-prune below removes ill-conditioned views, ++ // and we must NOT mutate the persistent buffers, otherwise clicking Calibrate again ++ // would run on a smaller (already-pruned) sample set and give different results. ++ std::vector > objectPoints = objectPoints_[id]; ++ std::vector > imagePoints = imagePoints_[id]; ++ std::vector imageIds = imageIds_[id]; ++ + //calibrate + std::vector rvecs, tvecs; + std::vector reprojErrs; +@@ -1401,26 +1415,78 @@ void CalibrationDialog::calibrate() + + if(fishEye) + { +- try +- { +- rms = cv::fisheye::calibrate( +- objectPoints_[id], +- imagePoints_[id], +- imageSize_[id], +- K, +- D, +- rvecs, +- tvecs, +- cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC | +- cv::fisheye::CALIB_CHECK_COND | +- cv::fisheye::CALIB_FIX_SKEW); +- } +- catch(const cv::Exception & e) ++ // cv::fisheye::calibrate() with CALIB_CHECK_COND throws as soon as a single ++ // view is ill-conditioned (e.g. too few / poorly spread ChArUco corners), ++ // aborting the whole calibration. Auto-prune the offending view (its index is ++ // reported in the exception message) and retry until it succeeds, keeping the ++ // CHECK_COND safety without discarding every good view. ++ const int minFisheyeViews = COUNT_MIN/2; ++ bool calibrated = false; ++ while(!calibrated) + { +- UERROR("Error: %s (try restarting the calibration)", e.what()); +- QMessageBox::warning(this, tr("Calibration failed!"), tr("Error: %1 (try restarting the calibration)").arg(e.what())); +- processingData_ = false; +- return; ++ try ++ { ++ rms = cv::fisheye::calibrate( ++ objectPoints, ++ imagePoints, ++ imageSize_[id], ++ K, ++ D, ++ rvecs, ++ tvecs, ++ cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC | ++ cv::fisheye::CALIB_CHECK_COND | ++ cv::fisheye::CALIB_FIX_SKEW); ++ calibrated = true; ++ } ++ catch(const cv::Exception & e) ++ { ++ // Parse the ill-conditioned view index, e.g. ++ // "CALIB_CHECK_COND - Ill-conditioned matrix for input array 43" ++ int badIndex = -1; ++ const QString token = "input array "; ++ QString msg = e.what(); ++ int tokenPos = msg.indexOf(token); ++ if(tokenPos >= 0) ++ { ++ bool ok = false; ++ int v = msg.mid(tokenPos + token.length()).section(' ', 0, 0).toInt(&ok); ++ if(ok) ++ { ++ badIndex = v; ++ } ++ } ++ ++ if(badIndex >= 0 && badIndex < (int)objectPoints.size() && ++ (int)objectPoints.size() > minFisheyeViews) ++ { ++ int removedImageId = badIndex < (int)imageIds.size() ? imageIds[badIndex] : -1; ++ UWARN("Fisheye calibration: view %d (image %d) is ill-conditioned, " ++ "removing it and retrying (%d views left).", ++ badIndex, removedImageId, (int)objectPoints.size()-1); ++ logStream << "Fisheye calibration: removed ill-conditioned view " << badIndex ++ << " (image " << removedImageId << "), " ++ << (int)objectPoints.size()-1 << " views left" << ENDL; ++ ++ // Prune the local copies only (never the persistent buffers). Keep them ++ // aligned: the per-view reprojection loop below indexes them together ++ // with rvecs/tvecs. ++ objectPoints.erase(objectPoints.begin()+badIndex); ++ imagePoints.erase(imagePoints.begin()+badIndex); ++ if(badIndex < (int)imageIds.size()) ++ { ++ imageIds.erase(imageIds.begin()+badIndex); ++ } ++ // loop and retry with the pruned set ++ } ++ else ++ { ++ UERROR("Error: %s (try restarting the calibration)", e.what()); ++ QMessageBox::warning(this, tr("Calibration failed!"), tr("Error: %1 (try restarting the calibration)").arg(e.what())); ++ processingData_ = false; ++ return; ++ } ++ } + } + } + else +@@ -1429,8 +1495,8 @@ void CalibrationDialog::calibrate() + cv::Mat stdDevsMatInt, stdDevsMatExt; + cv::Mat perViewErrorsMat; + rms = cv::calibrateCamera( +- objectPoints_[id], +- imagePoints_[id], ++ objectPoints, ++ imagePoints, + imageSize_[id], + K, + D, +@@ -1440,14 +1506,14 @@ void CalibrationDialog::calibrate() + stdDevsMatExt, + perViewErrorsMat, + ui_->comboBox_calib_model->currentIndex()==2?cv::CALIB_RATIONAL_MODEL:0); +- if((int)imageIds_[id].size() == perViewErrorsMat.rows) ++ if((int)imageIds.size() == perViewErrorsMat.rows) + { + UINFO("Per view errors:"); + logStream << "Per view errors:" << ENDL; + for(int i=0; i(i,0)); +- logStream << "Image " << imageIds_[id][i] << ": " << perViewErrorsMat.at(i,0) << ENDL; ++ UINFO("Image %d: %f", imageIds[i], perViewErrorsMat.at(i,0)); ++ logStream << "Image " << imageIds[i] << ": " << perViewErrorsMat.at(i,0) << ENDL; + } + } + } +@@ -1459,23 +1525,23 @@ void CalibrationDialog::calibrate() + std::vector imagePoints2; + int i, totalPoints = 0; + double totalErr = 0, err; +- reprojErrs.resize(objectPoints_[id].size()); ++ reprojErrs.resize(objectPoints.size()); + +- for( i = 0; i < (int)objectPoints_[id].size(); ++i ) ++ for( i = 0; i < (int)objectPoints.size(); ++i ) + { + #if CV_MAJOR_VERSION > 2 or (CV_MAJOR_VERSION == 2 and (CV_MINOR_VERSION >4 or (CV_MINOR_VERSION == 4 and CV_SUBMINOR_VERSION >=10))) + if(fishEye) + { +- cv::fisheye::projectPoints( cv::Mat(objectPoints_[id][i]), imagePoints2, rvecs[i], tvecs[i], K, D); ++ cv::fisheye::projectPoints( cv::Mat(objectPoints[i]), imagePoints2, rvecs[i], tvecs[i], K, D); + } + else + #endif + { +- cv::projectPoints( cv::Mat(objectPoints_[id][i]), rvecs[i], tvecs[i], K, D, imagePoints2); ++ cv::projectPoints( cv::Mat(objectPoints[i]), rvecs[i], tvecs[i], K, D, imagePoints2); + } +- err = cv::norm(cv::Mat(imagePoints_[id][i]), cv::Mat(imagePoints2), CV_L2); ++ err = cv::norm(cv::Mat(imagePoints[i]), cv::Mat(imagePoints2), cv::NORM_L2); + +- int n = (int)objectPoints_[id][i].size(); ++ int n = (int)objectPoints[i].size(); + reprojErrs[i] = (float) std::sqrt(err*err/n); + totalErr += err*err; + totalPoints += n; +@@ -1576,9 +1642,14 @@ void CalibrationDialog::calibrate() + cv::Mat P = stereoModel_.right().P().clone(); + P.at(0,3) = -P.at(0,0)*ui_->doubleSpinBox_stereoBaseline->value(); + double scale = ui_->doubleSpinBox_stereoBaseline->value() / stereoModel_.baseline(); +- UWARN("Scale %f (setting square size from %f to %f)", scale, ui_->doubleSpinBox_squareSize->value(), ui_->doubleSpinBox_squareSize->value()*scale); +- logStream << "Baseline rescaled from " << stereoModel_.baseline() << " to " << ui_->doubleSpinBox_stereoBaseline->value() << " scale=" << scale << ENDL; +- ui_->doubleSpinBox_squareSize->setValue(ui_->doubleSpinBox_squareSize->value()*scale); ++ UWARN("Scale %f applied to stereo baseline (computed %f m -> expected %f m). " ++ "If the mismatch is caused by the measured square size, it would be %f m instead of %f m.", ++ scale, stereoModel_.baseline(), ui_->doubleSpinBox_stereoBaseline->value(), ++ ui_->doubleSpinBox_squareSize->value()*scale, ui_->doubleSpinBox_squareSize->value()); ++ logStream << "Baseline rescaled from " << stereoModel_.baseline() << " to " << ui_->doubleSpinBox_stereoBaseline->value() ++ << " scale=" << scale << " (implied square size " << ui_->doubleSpinBox_squareSize->value()*scale ++ << " m instead of " << ui_->doubleSpinBox_squareSize->value() << " m)" << ENDL; ++ UASSERT(!stereoModel_.T().empty()); + stereoModel_ = StereoCameraModel( + stereoModel_.name(), + stereoModel_.left().imageSize(),stereoModel_.left().K_raw(), stereoModel_.left().D_raw(), stereoModel_.left().R(), stereoModel_.left().P(), +@@ -1708,26 +1779,58 @@ StereoCameraModel CalibrationDialog::stereoCalibration(const CameraModel & left, + cv::Vec4d D_right(right.D_raw().at(0,0), right.D_raw().at(0,1), right.D_raw().at(0,4), right.D_raw().at(0,5)); + + UASSERT(stereoImagePoints_[0].size() == stereoImagePoints_[1].size()); ++ UASSERT(stereoObjectPoints_.size() == stereoImagePoints_[0].size()); ++ // cv::fisheye::stereoCalibrate() reads the number of points from the first view and ++ // lays out its Jacobian assuming EVERY view has that same count (fisheye.cpp ++ // "reshape(1, n_points*2)"). ChArUco detects a variable number of corners per view, ++ // so we make the counts uniform by evenly subsampling every view down to the common ++ // minimum count (kept spatially spread, not just the first N). ++ size_t minPoints = stereoImagePoints_[0][0].size(); ++ for(unsigned int i =0; i > objectPoints(stereoObjectPoints_.size()); + std::vector > leftPoints(stereoImagePoints_[0].size()); + std::vector > rightPoints(stereoImagePoints_[1].size()); ++ bool subsampled = false; + for(unsigned int i =0; i1 ? (size_t)((k*(n-1))/(minPoints-1)) : 0; ++ objectPoints[i][k].x = stereoObjectPoints_[i][j].x; ++ objectPoints[i][k].y = stereoObjectPoints_[i][j].y; ++ objectPoints[i][k].z = stereoObjectPoints_[i][j].z; ++ leftPoints[i][k].x = stereoImagePoints_[0][i][j].x; ++ leftPoints[i][k].y = stereoImagePoints_[0][i][j].y; ++ rightPoints[i][k].x = stereoImagePoints_[1][i][j].x; ++ rightPoints[i][k].y = stereoImagePoints_[1][i][j].y; + } + } ++ if(subsampled) ++ { ++ UWARN("Fisheye stereo calibration requires the same number of points in every " ++ "view; sub-sampled all %d views to the common minimum of %d points.", ++ (int)stereoImagePoints_[0].size(), (int)minPoints); ++ if(logStream) (*logStream) << "Fisheye stereo: sub-sampled all views to " << (int)minPoints << " points" << ENDL; ++ } + + try + { + rms = cv::fisheye::stereoCalibrate( +- stereoObjectPoints_, ++ objectPoints, + leftPoints, + rightPoints, + left.K_raw(), D_left, right.K_raw(), D_right, +@@ -1739,30 +1842,41 @@ StereoCameraModel CalibrationDialog::stereoCalibration(const CameraModel & left, + catch(const cv::Exception & e) + { + UERROR("Error: %s (try restarting the calibration)", e.what()); ++ QMessageBox::warning(const_cast(this), tr("Calibration failed!"), tr("Error: %1 (try restarting the calibration)").arg(e.what())); + return output; + } + + std::cout << "R = " << R << std::endl; + std::cout << "T = " << Tvec << std::endl; + ++ // cv::fisheye::stereoCalibrate() returns the translation as a Vec3d (Tvec) and does ++ // not fill the cv::Mat T; populate it here so the returned model always carries a ++ // valid 3x1 extrinsic translation (used e.g. by the baseline rescaling below). ++ T = cv::Mat(3, 1, CV_64FC1); ++ T.at(0,0) = Tvec[0]; ++ T.at(1,0) = Tvec[1]; ++ T.at(2,0) = Tvec[2]; ++ + if(imageSize_[0] == imageSize_[1] && !ignoreStereoRectification) + { + UINFO("Compute stereo rectification"); + + cv::Mat R1, R2, P1, P2, Q; ++#if CV_MAJOR_VERSION < 5 + stereoRectifyFisheye( + left.K_raw(), D_left, + right.K_raw(), D_right, + imageSize, R, Tvec, R1, R2, P1, P2, Q, + cv::CALIB_ZERO_DISPARITY, 0, imageSize); +- +- // Very hard to get good results with this one: +- /*double balance = 0.0, fov_scale = 1.0; ++#else ++ // Very hard to get good results with this one, however we cannot use the previous one anymore in opencv5 ++ double balance = 0.0, fov_scale = 1.0; + cv::fisheye::stereoRectify( + left.K_raw(), D_left, + right.K_raw(), D_right, + imageSize, R, Tvec, R1, R2, P1, P2, Q, +- cv::CALIB_ZERO_DISPARITY, imageSize, balance, fov_scale);*/ ++ cv::CALIB_ZERO_DISPARITY, imageSize, balance, fov_scale); ++#endif + + std::cout << "R1 = " << R1 << std::endl; + std::cout << "R2 = " << R2 << std::endl; +@@ -1791,11 +1905,6 @@ StereoCameraModel CalibrationDialog::stereoCalibration(const CameraModel & left, + std::cout << "P1n = " << P1 << std::endl; + std::cout << "P2n = " << P2 << std::endl; + +- +- cv::Mat T(3,1,CV_64FC1); +- T.at (0,0) = Tvec[0]; +- T.at (1,0) = Tvec[1]; +- T.at (2,0) = Tvec[2]; + output = StereoCameraModel( + cameraName_.toStdString(), + imageSize_[0], left.K_raw(), left.D_raw(), R1, P1, +@@ -1915,8 +2024,8 @@ StereoCameraModel CalibrationDialog::stereoCalibration(const CameraModel & left, + { + int npt = (int)stereoImagePoints_[0][i].size(); + +- cv::Mat imgpt0 = cv::Mat(stereoImagePoints_[0][i]); +- cv::Mat imgpt1 = cv::Mat(stereoImagePoints_[1][i]); ++ std::vector imgpt0 = stereoImagePoints_[0][i]; ++ std::vector imgpt1 = stereoImagePoints_[1][i]; + cv::undistortPoints(imgpt0, imgpt0, left.K_raw(), left.D_raw(), R1, P1); + cv::undistortPoints(imgpt1, imgpt1, right.K_raw(), right.D_raw(), R2, P2); + computeCorrespondEpilines(imgpt0, 1, F, lines[0]); +@@ -1925,10 +2034,10 @@ StereoCameraModel CalibrationDialog::stereoCalibration(const CameraModel & left, + double sampleErr = 0.0; + for(int j = 0; j < npt; j++ ) + { +- double errij = fabs(stereoImagePoints_[0][i][j].x*lines[1][j][0] + +- stereoImagePoints_[0][i][j].y*lines[1][j][1] + lines[1][j][2]) + +- fabs(stereoImagePoints_[1][i][j].x*lines[0][j][0] + +- stereoImagePoints_[1][i][j].y*lines[0][j][1] + lines[0][j][2]); ++ double errij = fabs(imgpt0[j].x*lines[1][j][0] + ++ imgpt0[j].y*lines[1][j][1] + lines[1][j][2]) + ++ fabs(imgpt1[j].x*lines[0][j][0] + ++ imgpt1[j].y*lines[0][j][1] + lines[0][j][2]); + sampleErr += errij; + } + UINFO("Stereo image %d: %f", stereoImageIds_[i], sampleErr/npt); +diff --git a/guilib/src/CameraViewer.cpp b/guilib/src/CameraViewer.cpp +index 6588d51..3d7bbab 100644 +--- a/guilib/src/CameraViewer.cpp ++++ b/guilib/src/CameraViewer.cpp +@@ -85,7 +85,7 @@ CameraViewer::CameraViewer(QWidget * parent, const ParametersMap & parameters) : + showScanCheckbox_->setChecked(true); + + markerCheckbox_ = new QCheckBox("Detect markers", this); +-#if defined(HAVE_OPENCV_ARUCO) || defined(RTABMAP_APRILTAG) ++#if ((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO) || defined(RTABMAP_APRILTAG) + markerCheckbox_->setEnabled(true); + markerDetector_ = new MarkerDetector(parameters); + #else +@@ -175,7 +175,8 @@ void CameraViewer::showImage(const rtabmap::SensorData & data) + if(!models.empty() && models[0].isValidForProjection()) + { + cv::Mat imageWithDetections; +- detections = markerDetector_->detect(left, models, depthOrRight, _landmarksSize, &imageWithDetections); ++ cv::Mat depth = (depthOrRight.type()==CV_16UC1 || depthOrRight.type()==CV_32FC1) ? depthOrRight : cv::Mat(); ++ detections = markerDetector_->detect(left, models, depth, _landmarksSize, &imageWithDetections); + imageView_->setImage(uCvMat2QImage(imageWithDetections)); + for(std::map::iterator iter=detections.begin(); iter!=detections.end(); ++iter) + { +diff --git a/guilib/src/DatabaseViewer.cpp b/guilib/src/DatabaseViewer.cpp +index 8951266..a133cb3 100644 +--- a/guilib/src/DatabaseViewer.cpp ++++ b/guilib/src/DatabaseViewer.cpp +@@ -43,8 +43,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include +-#include + #include + #include + #include +@@ -5956,7 +5954,7 @@ void DatabaseViewer::updateStereo(const SensorData * data) + cv::Mat leftMono; + if(data->imageRaw().channels() == 3) + { +- cv::cvtColor(data->imageRaw(), leftMono, CV_BGR2GRAY); ++ cv::cvtColor(data->imageRaw(), leftMono, cv::COLOR_BGR2GRAY); + } + else + { +@@ -5965,7 +5963,7 @@ void DatabaseViewer::updateStereo(const SensorData * data) + cv::Mat rightMono; + if(data->rightRaw().channels() == 3) + { +- cv::cvtColor(data->rightRaw(), rightMono, CV_BGR2GRAY); ++ cv::cvtColor(data->rightRaw(), rightMono, cv::COLOR_BGR2GRAY); + } + else + { +diff --git a/guilib/src/MainWindow.cpp b/guilib/src/MainWindow.cpp +index 8daf26b..363d9cf 100644 +--- a/guilib/src/MainWindow.cpp ++++ b/guilib/src/MainWindow.cpp +@@ -91,6 +91,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + ++#if CV_MAJOR_VERSION >= 5 ++#include ++#endif ++ + //RGB-D stuff + #include "rtabmap/core/CameraRGBD.h" + #include "rtabmap/core/Odometry.h" +@@ -123,10 +127,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #endif + +-#ifdef HAVE_OPENCV_ARUCO +-#include +-#endif +- + #define LOG_FILE_NAME "LogRtabmap.txt" + #define SHARE_SHOW_LOG_FILE "share/rtabmap/showlogs.m" + #define SHARE_GET_PRECISION_RECALL_FILE "share/rtabmap/getPrecisionRecall.m" +diff --git a/guilib/src/PreferencesDialog.cpp b/guilib/src/PreferencesDialog.cpp +index 2ccdd09..f42667d 100644 +--- a/guilib/src/PreferencesDialog.cpp ++++ b/guilib/src/PreferencesDialog.cpp +@@ -475,10 +475,10 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) : + _ui->checkBox_showOdomFrustums->setChecked(false); + #endif + +-#if !defined(HAVE_OPENCV_ARUCO) && !defined(RTABMAP_APRILTAG) ++#if !((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) && !defined(HAVE_OPENCV_ARUCO) && !defined(RTABMAP_APRILTAG) + _ui->label_markerDetection->setText(_ui->label_markerDetection->text()+" This option works only if OpenCV has been built with \"aruco\" module and/or RTAB-Map has been built with AprilTag library support."); + #endif +-#ifndef HAVE_OPENCV_ARUCO ++#if !(((CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION==4 && CV_MINOR_VERSION >=7)) && defined(HAVE_OPENCV_OBJDETECT)) || defined(HAVE_OPENCV_ARUCO)) + _ui->MarkerStrategy->setItemData(0, 0, Qt::UserRole - 1); + #endif + #ifndef RTABMAP_APRILTAG +diff --git a/guilib/src/ui/calibrationDialog.ui b/guilib/src/ui/calibrationDialog.ui +index d429252..96a5d27 100644 +--- a/guilib/src/ui/calibrationDialog.ui ++++ b/guilib/src/ui/calibrationDialog.ui +@@ -345,10 +345,10 @@ + + + +- ++ Number of inner squares on the board + + +- Square Size ++ Board Size + + + +@@ -385,10 +385,10 @@ + + + +- Number of inner squares on the board ++ + + +- Board Size ++ Square Size + + + +diff --git a/tools/Camera/main.cpp b/tools/Camera/main.cpp +index e337030..3bf320c 100644 +--- a/tools/Camera/main.cpp ++++ b/tools/Camera/main.cpp +@@ -32,7 +32,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UDirectory.h" + #include "rtabmap/utilite/UConversion.h" + #include +-#include + #include + + void showUsage() +@@ -178,7 +177,7 @@ int main(int argc, char * argv[]) + + cv::Mat rgb; + rgb = camera->takeImage().imageRaw(); +- cv::namedWindow("Video", CV_WINDOW_AUTOSIZE); // create window ++ cv::namedWindow("Video", cv::WINDOW_AUTOSIZE); // create window + while(!rgb.empty()) + { + cv::imshow("Video", rgb); // show frame +diff --git a/tools/CameraRGBD/main.cpp b/tools/CameraRGBD/main.cpp +index b8342e6..ff40f3c 100644 +--- a/tools/CameraRGBD/main.cpp ++++ b/tools/CameraRGBD/main.cpp +@@ -40,10 +40,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include "rtabmap/utilite/UEventsManager.h" + #include + #include +-#include +-#if CV_MAJOR_VERSION >= 3 +-#include +-#endif + #include + #include + #include +@@ -454,7 +450,7 @@ int main(int argc, char * argv[]) + { + if(right.channels() == 3) + { +- cv::cvtColor(right, right, CV_BGR2GRAY); ++ cv::cvtColor(right, right, cv::COLOR_BGR2GRAY); + } + pcl::PointCloud::Ptr cloud = rtabmap::util3d::cloudFromStereoImages( + rgb, right, +diff --git a/tools/EpipolarGeometry/main.cpp b/tools/EpipolarGeometry/main.cpp +index aa309fa..22e6016 100644 +--- a/tools/EpipolarGeometry/main.cpp ++++ b/tools/EpipolarGeometry/main.cpp +@@ -26,7 +26,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + #include +-#include + #include + #include + #include +@@ -36,7 +35,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include ++#if CV_MAJOR_VERSION < 5 + #include ++#else ++#include ++#endif + #include "rtabmap/core/Features2d.h" + #include "rtabmap/core/EpipolarGeometry.h" + #include "rtabmap/core/VWDictionary.h" +diff --git a/tools/StereoEval/main.cpp b/tools/StereoEval/main.cpp +index bd3313f..9c15e34 100644 +--- a/tools/StereoEval/main.cpp ++++ b/tools/StereoEval/main.cpp +@@ -37,7 +37,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #include + #include + #include +-#include + #include + #include + +@@ -222,7 +221,7 @@ int main(int argc, char * argv[]) + cv::Mat leftMono; + if(left.channels() == 3) + { +- cv::cvtColor(left, leftMono, CV_BGR2GRAY); ++ cv::cvtColor(left, leftMono, cv::COLOR_BGR2GRAY); + } + else + { +@@ -231,7 +230,7 @@ int main(int argc, char * argv[]) + cv::Mat rightMono; + if(right.channels() == 3) + { +- cv::cvtColor(right, rightMono, CV_BGR2GRAY); ++ cv::cvtColor(right, rightMono, cv::COLOR_BGR2GRAY); + } + else + { +@@ -266,7 +265,7 @@ int main(int argc, char * argv[]) + cv::cornerSubPix(leftMono, leftCorners, + cv::Size( subPixWinSize, subPixWinSize ), + cv::Size( -1, -1 ), +- cv::TermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, subPixIterations, subPixEps ) ); ++ cv::TermCriteria( cv::TermCriteria::MAX_ITER | cv::TermCriteria::EPS, subPixIterations, subPixEps ) ); + UDEBUG("cv::cornerSubPix() end"); + } +