Preferences: Fixed xfeatures2d features not available without nonfree on OpenCV >= 3.4.2 (https://github.com/introlab/rtabmap_ros/issues/422)

This commit is contained in:
matlabbe
2020-05-25 17:31:13 -04:00
parent 35385e299d
commit b40d9610ed
7 changed files with 88 additions and 47 deletions
+9 -9
View File
@@ -672,6 +672,10 @@ ENDIF(APPLE AND BUILD_AS_BUNDLE)
SET(CONF_DEPENDENCIES SET(CONF_DEPENDENCIES
${ZLIB_LIBRARIES} ${ZLIB_LIBRARIES}
) )
# OpenCV2 has nonfree if OPENCV_NONFREE_FOUND
# OpenCV<=3.4.2 has nonfree if OPENCV_XFEATURES2D_FOUND
# OpenCV>3.4.2 has nonfree if OPENCV_XFEATURES2D_FOUND and OPENCV_ENABLE_NONFREE is defined
IF(NOT (OPENCV_NONFREE_FOUND OR OPENCV_XFEATURES2D_FOUND)) IF(NOT (OPENCV_NONFREE_FOUND OR OPENCV_XFEATURES2D_FOUND))
SET(NONFREE "//") SET(NONFREE "//")
ELSEIF(OpenCV_VERSION VERSION_GREATER "3.4.2") ELSEIF(OpenCV_VERSION VERSION_GREATER "3.4.2")
@@ -1056,18 +1060,14 @@ IF(OpenCV_FOUND)
MESSAGE(STATUS " *With OpenCV 2 nonfree module (SIFT/SURF) = NO (not found, License: BSD)") MESSAGE(STATUS " *With OpenCV 2 nonfree module (SIFT/SURF) = NO (not found, License: BSD)")
ENDIF() ENDIF()
ELSE() ELSE()
IF(OpenCV_VERSION VERSION_GREATER "4.2.0") IF(OPENCV_XFEATURES2D_FOUND)
IF(OPENCV_XFEATURES2D_FOUND) IF(NONFREE STREQUAL "//")
MESSAGE(STATUS " *With OpenCV ${OpenCV_VERSION} xfeatures2d module (SURF/BRIEF/FREAK) = YES (License: Non commercial)") MESSAGE(STATUS " *With OpenCV ${OpenCV_VERSION} xfeatures2d = YES, nonfree = NO (License: BSD)")
ELSE() ELSE()
MESSAGE(STATUS " *With OpenCV ${OpenCV_VERSION} xfeatures2d module (SURF/BRIEF/FREAK) = NO (not found, License: BSD)") MESSAGE(STATUS " *With OpenCV ${OpenCV_VERSION} xfeatures2d = YES, nonfree = YES (License: Non commercial)")
ENDIF() ENDIF()
ELSE() ELSE()
IF(OPENCV_XFEATURES2D_FOUND) MESSAGE(STATUS " *With OpenCV ${OpenCV_VERSION} xfeatures2d = NO, nonfree = NO (License: BSD)")
MESSAGE(STATUS " *With OpenCV ${OpenCV_VERSION} xfeatures2d module (SIFT/SURF/BRIEF/FREAK) = YES (License: Non commercial)")
ELSE()
MESSAGE(STATUS " *With OpenCV ${OpenCV_VERSION} xfeatures2d module (SIFT/SURF/BRIEF/FREAK) = NO (not found, License: BSD)")
ENDIF()
ENDIF() ENDIF()
ENDIF() ENDIF()
ENDIF(OpenCV_FOUND) ENDIF(OpenCV_FOUND)
-1
View File
@@ -44,7 +44,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@GTSAM@#define RTABMAP_GTSAM @GTSAM@#define RTABMAP_GTSAM
@CERES@#define RTABMAP_CERES @CERES@#define RTABMAP_CERES
@VERTIGO@#define RTABMAP_VERTIGO @VERTIGO@#define RTABMAP_VERTIGO
@OPENCV3@#define RTABMAP_OPENCV3
@OPENNI2@#define RTABMAP_OPENNI2 @OPENNI2@#define RTABMAP_OPENNI2
@FREENECT@#define RTABMAP_FREENECT @FREENECT@#define RTABMAP_FREENECT
@FREENECT2@#define RTABMAP_FREENECT2 @FREENECT2@#define RTABMAP_FREENECT2
+6 -12
View File
@@ -32,6 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "rtabmap/core/RtabmapExp.h" // DLL export/import defines #include "rtabmap/core/RtabmapExp.h" // DLL export/import defines
#include "rtabmap/core/Version.h" // DLL export/import defines #include "rtabmap/core/Version.h" // DLL export/import defines
#include <rtabmap/utilite/UConversion.h> #include <rtabmap/utilite/UConversion.h>
#include <opencv2/core/version.hpp>
#include <opencv2/opencv_modules.hpp>
#include <string> #include <string>
#include <map> #include <map>
@@ -239,13 +241,9 @@ class RTABMAP_EXP Parameters
RTABMAP_PARAM(Kp, MaxFeatures, int, 500, "Maximum features extracted from the images (0 means not bounded, <0 means no extraction)."); RTABMAP_PARAM(Kp, MaxFeatures, int, 500, "Maximum features extracted from the images (0 means not bounded, <0 means no extraction).");
RTABMAP_PARAM(Kp, BadSignRatio, float, 0.5, "Bad signature ratio (less than Ratio x AverageWordsPerImage = bad)."); RTABMAP_PARAM(Kp, BadSignRatio, float, 0.5, "Bad signature ratio (less than Ratio x AverageWordsPerImage = bad).");
RTABMAP_PARAM(Kp, NndrRatio, float, 0.8, "NNDR ratio (A matching pair is detected, if its distance is closer than X times the distance of the second nearest neighbor.)"); RTABMAP_PARAM(Kp, NndrRatio, float, 0.8, "NNDR ratio (A matching pair is detected, if its distance is closer than X times the distance of the second nearest neighbor.)");
#ifndef RTABMAP_NONFREE #if CV_MAJOR_VERSION > 2 && !defined(HAVE_OPENCV_FEATURES2D)
#ifdef RTABMAP_OPENCV3 // OpenCV>2 without xFeatures2D module doesn't have BRIEF
// OpenCV 3 without xFeatures2D module doesn't have BRIEF
RTABMAP_PARAM(Kp, DetectorStrategy, int, 8, "0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB 9=KAZE 10=ORB-OCTREE 11=SuperPoint Torch."); RTABMAP_PARAM(Kp, DetectorStrategy, int, 8, "0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB 9=KAZE 10=ORB-OCTREE 11=SuperPoint Torch.");
#else
RTABMAP_PARAM(Kp, DetectorStrategy, int, 6, "0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB 9=KAZE 10=ORB-OCTREE 11=SuperPoint Torch.");
#endif
#else #else
RTABMAP_PARAM(Kp, DetectorStrategy, int, 6, "0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB 9=KAZE 10=ORB-OCTREE 11=SuperPoint Torch."); RTABMAP_PARAM(Kp, DetectorStrategy, int, 6, "0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB 9=KAZE 10=ORB-OCTREE 11=SuperPoint Torch.");
#endif #endif
@@ -586,13 +584,9 @@ class RTABMAP_EXP Parameters
RTABMAP_PARAM(Vis, MinInliersDistribution, float, 0.0, "Minimum distribution value of the inliers in the image to accept the transformation. The distribution is the second eigen value of the PCA (Principal Component Analysis) on the keypoints of the normalized image [-0.5, 0.5]. The value would be between 0 and 0.5. 0 means disabled."); RTABMAP_PARAM(Vis, MinInliersDistribution, float, 0.0, "Minimum distribution value of the inliers in the image to accept the transformation. The distribution is the second eigen value of the PCA (Principal Component Analysis) on the keypoints of the normalized image [-0.5, 0.5]. The value would be between 0 and 0.5. 0 means disabled.");
RTABMAP_PARAM(Vis, Iterations, int, 300, "Maximum iterations to compute the transform."); RTABMAP_PARAM(Vis, Iterations, int, 300, "Maximum iterations to compute the transform.");
#ifndef RTABMAP_NONFREE #if CV_MAJOR_VERSION > 2 && !defined(HAVE_OPENCV_FEATURES2D)
#ifdef RTABMAP_OPENCV3 // OpenCV>2 without xFeatures2D module doesn't have BRIEF
// OpenCV 3 without xFeatures2D module doesn't have BRIEF
RTABMAP_PARAM(Vis, FeatureType, int, 8, "0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB 9=KAZE 10=ORB-OCTREE 11=SuperPoint Torch."); RTABMAP_PARAM(Vis, FeatureType, int, 8, "0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB 9=KAZE 10=ORB-OCTREE 11=SuperPoint Torch.");
#else
RTABMAP_PARAM(Vis, FeatureType, int, 6, "0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB 9=KAZE 10=ORB-OCTREE 11=SuperPoint Torch.");
#endif
#else #else
RTABMAP_PARAM(Vis, FeatureType, int, 6, "0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB 9=KAZE 10=ORB-OCTREE 11=SuperPoint Torch."); RTABMAP_PARAM(Vis, FeatureType, int, 6, "0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK 8=GFTT/ORB 9=KAZE 10=ORB-OCTREE 11=SuperPoint Torch.");
#endif #endif
+1 -1
View File
@@ -501,7 +501,7 @@ Feature2D * Feature2D::create(Feature2D::Type type, const ParametersMap & parame
#ifndef RTABMAP_NONFREE #ifndef RTABMAP_NONFREE
if(type == Feature2D::kFeatureSurf) if(type == Feature2D::kFeatureSurf)
{ {
UWARN("SURF features cannot be used because OpenCV was not built with xfeatures2d module. SIFT is used instead."); UWARN("SURF features cannot be used because OpenCV was not built with nonfree module. SIFT is used instead.");
type = Feature2D::kFeatureSift; type = Feature2D::kFeatureSift;
} }
#endif #endif
+9
View File
@@ -40,6 +40,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SimpleIni.h" #include "SimpleIni.h"
#include <opencv2/core/version.hpp> #include <opencv2/core/version.hpp>
#include <pcl/pcl_config.h> #include <pcl/pcl_config.h>
#include <opencv2/opencv_modules.hpp>
#ifndef DISABLE_VTK #ifndef DISABLE_VTK
#include <vtkVersion.h> #include <vtkVersion.h>
#endif #endif
@@ -602,6 +603,14 @@ ParametersMap Parameters::parseArguments(int argc, char * argv[], bool onlyParam
#endif #endif
str = "OpenCV:"; str = "OpenCV:";
std::cout << str << std::setw(spacing - str.size()) << CV_VERSION << std::endl; std::cout << str << std::setw(spacing - str.size()) << CV_VERSION << std::endl;
#if CV_MAJOR_VERSION >= 3
str = "With OpenCV xfeatures2d:";
#ifdef HAVE_OPENCV_XFEATURES2D
std::cout << str << std::setw(spacing - str.size()) << "true" << std::endl;
#else
std::cout << str << std::setw(spacing - str.size()) << "false" << std::endl;
#endif
#endif
str = "With OpenCV nonfree:"; str = "With OpenCV nonfree:";
#ifdef RTABMAP_NONFREE #ifdef RTABMAP_NONFREE
std::cout << str << std::setw(spacing - str.size()) << "true" << std::endl; std::cout << str << std::setw(spacing - str.size()) << "true" << std::endl;
+15 -2
View File
@@ -47,12 +47,25 @@ AboutDialog::AboutDialog(QWidget * parent) :
version.append(" [DEMO]"); version.append(" [DEMO]");
#endif #endif
QString cv_version = CV_VERSION; QString cv_version = CV_VERSION;
#ifdef RTABMAP_NONFREE #if CV_MAJOR_VERSION < 3
#ifdef RTABMAP_NONFREE
cv_version.append(" [With nonfree]"); cv_version.append(" [With nonfree]");
_ui->label_opencv_license->setText("Not Commercial"); _ui->label_opencv_license->setText("Not Commercial");
#else #else
cv_version.append(" [Without nonfree]"); cv_version.append(" [Without nonfree]");
_ui->label_opencv_license->setText("BSD"); _ui->label_opencv_license->setText("BSD");
#endif
#elif defined(HAVE_OPENCV_XFEATURES2D)
#ifdef RTABMAP_NONFREE
cv_version.append(" [With xfeatures2d, nonfree]");
_ui->label_opencv_license->setText("Not Commercial");
#else
cv_version.append(" [With xfeatures2d]");
_ui->label_opencv_license->setText("BSD");
#endif
#else
cv_version.append(" [Without xfeatures2d and nonfree]");
_ui->label_opencv_license->setText("BSD");
#endif #endif
_ui->label_version->setText(version); _ui->label_version->setText(version);
_ui->label_opencv_version->setText(cv_version); _ui->label_opencv_version->setText(cv_version);
+48 -22
View File
@@ -191,26 +191,29 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) :
_ui->stereosgbm_mode->setItemData(2, 0, Qt::UserRole - 1); _ui->stereosgbm_mode->setItemData(2, 0, Qt::UserRole - 1);
#endif #endif
//SURF
#ifndef RTABMAP_NONFREE #ifndef RTABMAP_NONFREE
_ui->comboBox_detector_strategy->setItemData(0, 0, Qt::UserRole - 1); _ui->comboBox_detector_strategy->setItemData(0, 0, Qt::UserRole - 1);
_ui->comboBox_detector_strategy->setItemData(1, 0, Qt::UserRole - 1); _ui->vis_feature_detector->setItemData(0, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(0, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(1, 0, Qt::UserRole - 1);
#if CV_MAJOR_VERSION >= 3
_ui->comboBox_detector_strategy->setItemData(0, 0, Qt::UserRole - 1);
_ui->comboBox_detector_strategy->setItemData(1, 0, Qt::UserRole - 1);
_ui->comboBox_detector_strategy->setItemData(3, 0, Qt::UserRole - 1);
_ui->comboBox_detector_strategy->setItemData(4, 0, Qt::UserRole - 1);
_ui->comboBox_detector_strategy->setItemData(5, 0, Qt::UserRole - 1);
_ui->comboBox_detector_strategy->setItemData(6, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(0, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(1, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(3, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(4, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(5, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(6, 0, Qt::UserRole - 1);
#endif #endif
// SIFT
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3)
#ifndef RTABMAP_NONFREE
_ui->comboBox_detector_strategy->setItemData(1, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(1, 0, Qt::UserRole - 1);
#endif
#endif
#if CV_MAJOR_VERSION >= 3 && !defined(HAVE_OPENCV_XFEATURES2D)
_ui->comboBox_detector_strategy->setItemData(3, 0, Qt::UserRole - 1);
_ui->comboBox_detector_strategy->setItemData(4, 0, Qt::UserRole - 1);
_ui->comboBox_detector_strategy->setItemData(5, 0, Qt::UserRole - 1);
_ui->comboBox_detector_strategy->setItemData(6, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(3, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(4, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(5, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(6, 0, Qt::UserRole - 1);
#endif #endif
#ifndef RTABMAP_ORB_OCTREE #ifndef RTABMAP_ORB_OCTREE
@@ -219,16 +222,16 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) :
#endif #endif
#ifndef RTABMAP_SUPERPOINT_TORCH #ifndef RTABMAP_SUPERPOINT_TORCH
_ui->comboBox_detector_strategy->setItemData(11, 0, Qt::UserRole - 1); _ui->comboBox_detector_strategy->setItemData(11, 0, Qt::UserRole - 1);
_ui->vis_feature_detector->setItemData(11, 0, Qt::UserRole - 1); _ui->vis_feature_detector->setItemData(11, 0, Qt::UserRole - 1);
#endif #endif
#ifndef RTABMAP_PYMATCHER #ifndef RTABMAP_PYMATCHER
_ui->reextract_nn->setItemData(6, 0, Qt::UserRole - 1); _ui->reextract_nn->setItemData(6, 0, Qt::UserRole - 1);
#endif #endif
#if !defined(HAVE_OPENCV_XFEATURES2D) || (CV_MAJOR_VERSION == 3 && (CV_MINOR_VERSION<4 || CV_MINOR_VERSION==4 && CV_SUBMINOR_VERSION<1)) #if !defined(HAVE_OPENCV_XFEATURES2D) || (CV_MAJOR_VERSION == 3 && (CV_MINOR_VERSION<4 || CV_MINOR_VERSION==4 && CV_SUBMINOR_VERSION<1))
_ui->reextract_nn->setItemData(7, 0, Qt::UserRole - 1); _ui->reextract_nn->setItemData(7, 0, Qt::UserRole - 1);
#endif #endif
#if CV_MAJOR_VERSION >= 3 #if CV_MAJOR_VERSION >= 3
@@ -2918,6 +2921,7 @@ void PreferencesDialog::writeCoreSettings(const QString & filePath) const
bool PreferencesDialog::validateForm() bool PreferencesDialog::validateForm()
{ {
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3)
#ifndef RTABMAP_NONFREE #ifndef RTABMAP_NONFREE
// verify that SURF/SIFT cannot be selected if not built with OpenCV nonfree module // verify that SURF/SIFT cannot be selected if not built with OpenCV nonfree module
// BOW dictionary type // BOW dictionary type
@@ -2938,6 +2942,28 @@ bool PreferencesDialog::validateForm()
_ui->vis_feature_detector->setCurrentIndex(Feature2D::kFeatureFastBrief); _ui->vis_feature_detector->setCurrentIndex(Feature2D::kFeatureFastBrief);
} }
#endif #endif
#else //>= 4.3.0
#ifndef RTABMAP_NONFREE
// verify that SURF cannot be selected if not built with OpenCV nonfree module
// BOW dictionary type
if(_ui->comboBox_detector_strategy->currentIndex() <= 1)
{
QMessageBox::warning(this, tr("Parameter warning"),
tr("Selected feature type (SURF) is not available. RTAB-Map is not built "
"with the nonfree module from OpenCV. SIFT is set instead for the bag-of-words dictionary."));
_ui->comboBox_detector_strategy->setCurrentIndex(Feature2D::kFeatureSift);
}
// BOW Reextract features type
if(_ui->vis_feature_detector->currentIndex() <= 1)
{
QMessageBox::warning(this, tr("Parameter warning"),
tr("Selected feature type (SURF) is not available. RTAB-Map is not built "
"with the nonfree module from OpenCV. Fast/Brief is set instead for the re-extraction "
"of features on loop closure."));
_ui->vis_feature_detector->setCurrentIndex(Feature2D::kFeatureFastBrief);
}
#endif
#endif
#if CV_MAJOR_VERSION < 3 #if CV_MAJOR_VERSION < 3
if (_ui->comboBox_detector_strategy->currentIndex() == Feature2D::kFeatureKaze) if (_ui->comboBox_detector_strategy->currentIndex() == Feature2D::kFeatureKaze)