Fixed SIFT build errors with OpenCV 4.3.0
This commit is contained in:
parent
88418c7d9a
commit
328c7236b5
@ -166,9 +166,9 @@ IF(NOT CATKIN_BUILD)
|
|||||||
ADD_SUBDIRECTORY( src )
|
ADD_SUBDIRECTORY( src )
|
||||||
ADD_SUBDIRECTORY( app )
|
ADD_SUBDIRECTORY( app )
|
||||||
ADD_SUBDIRECTORY( tools )
|
ADD_SUBDIRECTORY( tools )
|
||||||
IF(NONFREE)
|
IF(NONFREE OR OpenCV_VERSION VERSION_GREATER "4.2.0") # SIFT is free from 4.3.0
|
||||||
ADD_SUBDIRECTORY( example )
|
ADD_SUBDIRECTORY( example )
|
||||||
ENDIF(NONFREE)
|
ENDIF(NONFREE OR OpenCV_VERSION VERSION_GREATER "4.2.0")
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
# Uninstall target, for "make uninstall"
|
# Uninstall target, for "make uninstall"
|
||||||
@ -293,12 +293,20 @@ IF(NOT CATKIN_BUILD)
|
|||||||
ELSE()
|
ELSE()
|
||||||
MESSAGE(STATUS " With OpenCV ${OpenCV_VERSION_MAJOR} xfeatures2d module (BRIEF/FREAK/KAZE) = NO (not found)")
|
MESSAGE(STATUS " With OpenCV ${OpenCV_VERSION_MAJOR} xfeatures2d module (BRIEF/FREAK/KAZE) = NO (not found)")
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
IF(OpenCV_VERSION VERSION_GREATER "4.2.0")
|
||||||
|
IF(NONFREE)
|
||||||
|
MESSAGE(STATUS " With OpenCV ${OpenCV_VERSION_MAJOR} nonfree module (SURF) = YES")
|
||||||
|
ELSE()
|
||||||
|
MESSAGE(STATUS " With OpenCV ${OpenCV_VERSION_MAJOR} nonfree module (SURF) = NO")
|
||||||
|
ENDIF()
|
||||||
|
ELSEIF()
|
||||||
IF(NONFREE)
|
IF(NONFREE)
|
||||||
MESSAGE(STATUS " With OpenCV ${OpenCV_VERSION_MAJOR} nonfree module (SIFT/SURF) = YES")
|
MESSAGE(STATUS " With OpenCV ${OpenCV_VERSION_MAJOR} nonfree module (SIFT/SURF) = YES")
|
||||||
ELSE()
|
ELSE()
|
||||||
MESSAGE(STATUS " With OpenCV ${OpenCV_VERSION_MAJOR} nonfree module (SIFT/SURF) = NO")
|
MESSAGE(STATUS " With OpenCV ${OpenCV_VERSION_MAJOR} nonfree module (SIFT/SURF) = NO")
|
||||||
ENDIF()
|
ENDIF()
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
IF(QT4_FOUND)
|
IF(QT4_FOUND)
|
||||||
MESSAGE(STATUS " With Qt4 = YES")
|
MESSAGE(STATUS " With Qt4 = YES")
|
||||||
|
|||||||
@ -108,8 +108,10 @@ int main(int argc, char * argv[])
|
|||||||
// detector = cv::Ptr(new cv::StarFeatureDetector());
|
// detector = cv::Ptr(new cv::StarFeatureDetector());
|
||||||
// detector = cv::Ptr(new cv::SURF(600.0));
|
// detector = cv::Ptr(new cv::SURF(600.0));
|
||||||
// detector = cv::Ptr(new cv::BRISK());
|
// detector = cv::Ptr(new cv::BRISK());
|
||||||
#else
|
#elif CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3)
|
||||||
detector = cv::xfeatures2d::SIFT::create();
|
detector = cv::xfeatures2d::SIFT::create();
|
||||||
|
#else // >= 4.3.0
|
||||||
|
detector = cv::SIFT::create();
|
||||||
#endif
|
#endif
|
||||||
detector->detect(objectImg, objectKeypoints);
|
detector->detect(objectImg, objectKeypoints);
|
||||||
printf("Object: %d keypoints detected in %d ms\n", (int)objectKeypoints.size(), time.restart());
|
printf("Object: %d keypoints detected in %d ms\n", (int)objectKeypoints.size(), time.restart());
|
||||||
@ -128,8 +130,10 @@ int main(int argc, char * argv[])
|
|||||||
// extractor = cv::Ptr(new cv::SURF(600.0));
|
// extractor = cv::Ptr(new cv::SURF(600.0));
|
||||||
// extractor = cv::Ptr(new cv::BRISK());
|
// extractor = cv::Ptr(new cv::BRISK());
|
||||||
// extractor = cv::Ptr(new cv::FREAK());
|
// extractor = cv::Ptr(new cv::FREAK());
|
||||||
#else
|
#elif CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3)
|
||||||
extractor = cv::xfeatures2d::SIFT::create();
|
extractor = cv::xfeatures2d::SIFT::create();
|
||||||
|
#else // >= 4.3.0
|
||||||
|
extractor = cv::SIFT::create();
|
||||||
#endif
|
#endif
|
||||||
extractor->compute(objectImg, objectKeypoints, objectDescriptors);
|
extractor->compute(objectImg, objectKeypoints, objectDescriptors);
|
||||||
printf("Object: %d descriptors extracted in %d ms\n", objectDescriptors.rows, time.restart());
|
printf("Object: %d descriptors extracted in %d ms\n", objectDescriptors.rows, time.restart());
|
||||||
|
|||||||
@ -346,7 +346,9 @@ void ParametersToolBox::addParameter(QVBoxLayout * layout,
|
|||||||
if(key.compare(Settings::kFeature2D_1Detector()) == 0)
|
if(key.compare(Settings::kFeature2D_1Detector()) == 0)
|
||||||
{
|
{
|
||||||
#if FINDOBJECT_NONFREE == 0
|
#if FINDOBJECT_NONFREE == 0
|
||||||
|
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3) // <4.3.0
|
||||||
widget->setItemData(5, 0, Qt::UserRole - 1); // disable SIFT
|
widget->setItemData(5, 0, Qt::UserRole - 1); // disable SIFT
|
||||||
|
#endif
|
||||||
widget->setItemData(7, 0, Qt::UserRole - 1); // disable SURF
|
widget->setItemData(7, 0, Qt::UserRole - 1); // disable SURF
|
||||||
#endif
|
#endif
|
||||||
#if CV_MAJOR_VERSION < 3
|
#if CV_MAJOR_VERSION < 3
|
||||||
@ -366,7 +368,9 @@ void ParametersToolBox::addParameter(QVBoxLayout * layout,
|
|||||||
if(key.compare(Settings::kFeature2D_2Descriptor()) == 0)
|
if(key.compare(Settings::kFeature2D_2Descriptor()) == 0)
|
||||||
{
|
{
|
||||||
#if FINDOBJECT_NONFREE == 0
|
#if FINDOBJECT_NONFREE == 0
|
||||||
|
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3) // <4.3.0
|
||||||
widget->setItemData(2, 0, Qt::UserRole - 1); // disable SIFT
|
widget->setItemData(2, 0, Qt::UserRole - 1); // disable SIFT
|
||||||
|
#endif
|
||||||
widget->setItemData(3, 0, Qt::UserRole - 1); // disable SURF
|
widget->setItemData(3, 0, Qt::UserRole - 1); // disable SURF
|
||||||
#endif
|
#endif
|
||||||
#if CV_MAJOR_VERSION < 3
|
#if CV_MAJOR_VERSION < 3
|
||||||
|
|||||||
127
src/Settings.cpp
127
src/Settings.cpp
@ -137,6 +137,7 @@ ParametersMap Settings::loadSettings(const QString & fileName)
|
|||||||
int index = str.split(':').first().toInt();
|
int index = str.split(':').first().toInt();
|
||||||
if(key.compare(Settings::kFeature2D_1Detector()) == 0)
|
if(key.compare(Settings::kFeature2D_1Detector()) == 0)
|
||||||
{
|
{
|
||||||
|
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3)
|
||||||
#if FINDOBJECT_NONFREE == 0
|
#if FINDOBJECT_NONFREE == 0
|
||||||
if(index == 5 || index == 7)
|
if(index == 5 || index == 7)
|
||||||
{
|
{
|
||||||
@ -147,6 +148,16 @@ ParametersMap Settings::loadSettings(const QString & fileName)
|
|||||||
Settings::defaultFeature2D_1Detector().split(':').last().split(";").at(index).toStdString().c_str());
|
Settings::defaultFeature2D_1Detector().split(':').last().split(";").at(index).toStdString().c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#elif FINDOBJECT_NONFREE == 0
|
||||||
|
if(index == 7)
|
||||||
|
{
|
||||||
|
index = Settings::defaultFeature2D_1Detector().split(':').first().toInt();
|
||||||
|
UWARN("Trying to set \"%s\" to SURF but Find-Object isn't built "
|
||||||
|
"with the nonfree module from OpenCV. Keeping default combo value: %s.",
|
||||||
|
Settings::kFeature2D_1Detector().toStdString().c_str(),
|
||||||
|
Settings::defaultFeature2D_1Detector().split(':').last().split(";").at(index).toStdString().c_str());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#if FINDOBJECT_TORCH == 0
|
#if FINDOBJECT_TORCH == 0
|
||||||
if(index == 12)
|
if(index == 12)
|
||||||
{
|
{
|
||||||
@ -160,6 +171,7 @@ ParametersMap Settings::loadSettings(const QString & fileName)
|
|||||||
}
|
}
|
||||||
else if(key.compare(Settings::kFeature2D_2Descriptor()) == 0)
|
else if(key.compare(Settings::kFeature2D_2Descriptor()) == 0)
|
||||||
{
|
{
|
||||||
|
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3)
|
||||||
#if FINDOBJECT_NONFREE == 0
|
#if FINDOBJECT_NONFREE == 0
|
||||||
if(index == 2 || index == 3)
|
if(index == 2 || index == 3)
|
||||||
{
|
{
|
||||||
@ -170,6 +182,16 @@ ParametersMap Settings::loadSettings(const QString & fileName)
|
|||||||
Settings::defaultFeature2D_2Descriptor().split(':').last().split(";").at(index).toStdString().c_str());
|
Settings::defaultFeature2D_2Descriptor().split(':').last().split(";").at(index).toStdString().c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#elif FINDOBJECT_NONFREE == 0
|
||||||
|
if(index == 3)
|
||||||
|
{
|
||||||
|
index = Settings::defaultFeature2D_2Descriptor().split(':').first().toInt();
|
||||||
|
UWARN("Trying to set \"%s\" to SURF but Find-Object isn't built "
|
||||||
|
"with the nonfree module from OpenCV. Keeping default combo value: %s.",
|
||||||
|
Settings::kFeature2D_2Descriptor().toStdString().c_str(),
|
||||||
|
Settings::defaultFeature2D_2Descriptor().split(':').last().split(";").at(index).toStdString().c_str());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#if FINDOBJECT_TORCH == 0
|
#if FINDOBJECT_TORCH == 0
|
||||||
if(index == 11)
|
if(index == 11)
|
||||||
{
|
{
|
||||||
@ -688,8 +710,9 @@ Feature2D * Settings::createKeypointDetector()
|
|||||||
if(index>=0 && index<strategies.size())
|
if(index>=0 && index<strategies.size())
|
||||||
{
|
{
|
||||||
|
|
||||||
#if FINDOBJECT_NONFREE == 0
|
|
||||||
//check for nonfree stuff
|
//check for nonfree stuff
|
||||||
|
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3)
|
||||||
|
#if FINDOBJECT_NONFREE == 0
|
||||||
if(strategies.at(index).compare("SIFT") == 0 ||
|
if(strategies.at(index).compare("SIFT") == 0 ||
|
||||||
strategies.at(index).compare("SURF") == 0)
|
strategies.at(index).compare("SURF") == 0)
|
||||||
{
|
{
|
||||||
@ -700,6 +723,16 @@ Feature2D * Settings::createKeypointDetector()
|
|||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#elif FINDOBJECT_NONFREE == 0
|
||||||
|
if(strategies.at(index).compare("SURF") == 0)
|
||||||
|
{
|
||||||
|
index = Settings::defaultFeature2D_1Detector().split(':').first().toInt();
|
||||||
|
UERROR("Find-Object is not built with OpenCV nonfree module so "
|
||||||
|
"SURF cannot be used! Using default \"%s\" instead.",
|
||||||
|
strategies.at(index).toStdString().c_str());
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FINDOBJECT_TORCH == 0
|
#if FINDOBJECT_TORCH == 0
|
||||||
//check for nonfree stuff
|
//check for nonfree stuff
|
||||||
@ -964,6 +997,7 @@ Feature2D * Settings::createKeypointDetector()
|
|||||||
#endif
|
#endif
|
||||||
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
||||||
}
|
}
|
||||||
|
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3) // <4.3.0
|
||||||
#if FINDOBJECT_NONFREE == 1
|
#if FINDOBJECT_NONFREE == 1
|
||||||
else if(strategies.at(index).compare("SIFT") == 0)
|
else if(strategies.at(index).compare("SIFT") == 0)
|
||||||
{
|
{
|
||||||
@ -1018,6 +1052,44 @@ Feature2D * Settings::createKeypointDetector()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#else // >= 4.3.0
|
||||||
|
else if(strategies.at(index).compare("SIFT") == 0)
|
||||||
|
{
|
||||||
|
feature2D = new Feature2D(cv::SIFT::create(
|
||||||
|
getFeature2D_SIFT_nfeatures(),
|
||||||
|
getFeature2D_SIFT_nOctaveLayers(),
|
||||||
|
getFeature2D_SIFT_contrastThreshold(),
|
||||||
|
getFeature2D_SIFT_edgeThreshold(),
|
||||||
|
getFeature2D_SIFT_sigma()));
|
||||||
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
||||||
|
}
|
||||||
|
#if FINDOBJECT_NONFREE == 1
|
||||||
|
else if(strategies.at(index).compare("SURF") == 0)
|
||||||
|
{
|
||||||
|
if(getFeature2D_SURF_gpu() && CVCUDA::getCudaEnabledDeviceCount())
|
||||||
|
{
|
||||||
|
feature2D = new GPUSURF(
|
||||||
|
getFeature2D_SURF_hessianThreshold(),
|
||||||
|
getFeature2D_SURF_nOctaves(),
|
||||||
|
getFeature2D_SURF_nOctaveLayers(),
|
||||||
|
getFeature2D_SURF_extended(),
|
||||||
|
getFeature2D_SURF_keypointsRatio(),
|
||||||
|
getFeature2D_SURF_upright());
|
||||||
|
UDEBUG("type=%s (GPU)", strategies.at(index).toStdString().c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
feature2D = new Feature2D(cv::xfeatures2d::SURF::create(
|
||||||
|
getFeature2D_SURF_hessianThreshold(),
|
||||||
|
getFeature2D_SURF_nOctaves(),
|
||||||
|
getFeature2D_SURF_nOctaveLayers(),
|
||||||
|
getFeature2D_SURF_extended(),
|
||||||
|
getFeature2D_SURF_upright()));
|
||||||
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#if FINDOBJECT_TORCH == 1
|
#if FINDOBJECT_TORCH == 1
|
||||||
else if(strategies.at(index).compare("SuperPointTorch") == 0)
|
else if(strategies.at(index).compare("SuperPointTorch") == 0)
|
||||||
{
|
{
|
||||||
@ -1053,8 +1125,9 @@ Feature2D * Settings::createDescriptorExtractor()
|
|||||||
if(index>=0 && index<strategies.size())
|
if(index>=0 && index<strategies.size())
|
||||||
{
|
{
|
||||||
|
|
||||||
#if FINDOBJECT_NONFREE == 0
|
|
||||||
//check for nonfree stuff
|
//check for nonfree stuff
|
||||||
|
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3)
|
||||||
|
#if FINDOBJECT_NONFREE == 0
|
||||||
if(strategies.at(index).compare("SIFT") == 0 ||
|
if(strategies.at(index).compare("SIFT") == 0 ||
|
||||||
strategies.at(index).compare("SURF") == 0)
|
strategies.at(index).compare("SURF") == 0)
|
||||||
{
|
{
|
||||||
@ -1065,6 +1138,16 @@ Feature2D * Settings::createDescriptorExtractor()
|
|||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#elif FINDOBJECT_NONFREE == 0 // >= 4.3.0
|
||||||
|
if(strategies.at(index).compare("SURF") == 0)
|
||||||
|
{
|
||||||
|
index = Settings::defaultFeature2D_2Descriptor().split(':').first().toInt();
|
||||||
|
UERROR("Find-Object is not built with OpenCV nonfree module so "
|
||||||
|
"SURF cannot be used! Using default \"%s\" instead.",
|
||||||
|
strategies.at(index).toStdString().c_str());
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FINDOBJECT_TORCH == 0
|
#if FINDOBJECT_TORCH == 0
|
||||||
//check for nonfree stuff
|
//check for nonfree stuff
|
||||||
@ -1269,6 +1352,7 @@ Feature2D * Settings::createDescriptorExtractor()
|
|||||||
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION < 3) // <4.3.0
|
||||||
#if FINDOBJECT_NONFREE == 1
|
#if FINDOBJECT_NONFREE == 1
|
||||||
else if(strategies.at(index).compare("SIFT") == 0)
|
else if(strategies.at(index).compare("SIFT") == 0)
|
||||||
{
|
{
|
||||||
@ -1323,6 +1407,45 @@ Feature2D * Settings::createDescriptorExtractor()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#else // >= 4.3.0
|
||||||
|
else if(strategies.at(index).compare("SIFT") == 0)
|
||||||
|
{
|
||||||
|
feature2D = new Feature2D(cv::SIFT::create(
|
||||||
|
getFeature2D_SIFT_nfeatures(),
|
||||||
|
getFeature2D_SIFT_nOctaveLayers(),
|
||||||
|
getFeature2D_SIFT_contrastThreshold(),
|
||||||
|
getFeature2D_SIFT_edgeThreshold(),
|
||||||
|
getFeature2D_SIFT_sigma()));
|
||||||
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
||||||
|
}
|
||||||
|
#if FINDOBJECT_NONFREE == 1
|
||||||
|
else if(strategies.at(index).compare("SURF") == 0)
|
||||||
|
{
|
||||||
|
if(getFeature2D_SURF_gpu() && CVCUDA::getCudaEnabledDeviceCount())
|
||||||
|
{
|
||||||
|
feature2D = new GPUSURF(
|
||||||
|
getFeature2D_SURF_hessianThreshold(),
|
||||||
|
getFeature2D_SURF_nOctaves(),
|
||||||
|
getFeature2D_SURF_nOctaveLayers(),
|
||||||
|
getFeature2D_SURF_extended(),
|
||||||
|
getFeature2D_SURF_keypointsRatio(),
|
||||||
|
getFeature2D_SURF_upright());
|
||||||
|
UDEBUG("type=%s (GPU)", strategies.at(index).toStdString().c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
feature2D = new Feature2D(cv::xfeatures2d::SURF::create(
|
||||||
|
getFeature2D_SURF_hessianThreshold(),
|
||||||
|
getFeature2D_SURF_nOctaves(),
|
||||||
|
getFeature2D_SURF_nOctaveLayers(),
|
||||||
|
getFeature2D_SURF_extended(),
|
||||||
|
getFeature2D_SURF_upright()));
|
||||||
|
UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if FINDOBJECT_TORCH == 1
|
#if FINDOBJECT_TORCH == 1
|
||||||
else if(strategies.at(index).compare("SuperPointTorch") == 0)
|
else if(strategies.at(index).compare("SuperPointTorch") == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -121,7 +121,11 @@ int main(int argc, char * argv[])
|
|||||||
////////////////////////////
|
////////////////////////////
|
||||||
// EXTRACT KEYPOINTS
|
// EXTRACT KEYPOINTS
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
#if CV_MAJOR_VERSION < 4 || (CV_MAJOR_VERSION == 4 and CV_MINOR_VERSION < 3)
|
||||||
cv::Ptr<cv::xfeatures2d::SIFT> sift = cv::xfeatures2d::SIFT::create();
|
cv::Ptr<cv::xfeatures2d::SIFT> sift = cv::xfeatures2d::SIFT::create();
|
||||||
|
#else
|
||||||
|
cv::Ptr<cv::SIFT> sift = cv::SIFT::create();
|
||||||
|
#endif
|
||||||
sift->detect(objectImg, objectKeypoints);
|
sift->detect(objectImg, objectKeypoints);
|
||||||
sift->detect(sceneImg, sceneKeypoints);
|
sift->detect(sceneImg, sceneKeypoints);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user