Skip to content

Commit

Permalink
Merge pull request #795 from s-trinh/fix_SIFT_no_more_patented
Browse files Browse the repository at this point in the history
Fix build with OpenCV >= 3.4.11 and >= 4.4.0
  • Loading branch information
fspindle committed Aug 21, 2020
2 parents d0345e3 + ad84fd8 commit dfa7e4b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 14 deletions.
33 changes: 27 additions & 6 deletions modules/vision/src/key-point/vpKeyPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2292,13 +2292,22 @@ void vpKeyPoint::initDetector(const std::string &detectorName)
}

if (detectorNameTmp == "SIFT") {
#ifdef VISP_HAVE_OPENCV_XFEATURES2D
#if defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
// SIFT is no more patented since 09/03/2020
cv::Ptr<cv::FeatureDetector> siftDetector;
if (m_maxFeatures > 0) {
#if (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
siftDetector = cv::SIFT::create(m_maxFeatures);
#else
siftDetector = cv::xfeatures2d::SIFT::create(m_maxFeatures);
}
else {
#endif
} else {
#if (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
siftDetector = cv::SIFT::create();
#else
siftDetector = cv::xfeatures2d::SIFT::create();
#endif
}
if (!usePyramid) {
m_detectors[detectorNameTmp] = siftDetector;
Expand Down Expand Up @@ -2481,8 +2490,14 @@ void vpKeyPoint::initExtractor(const std::string &extractorName)
m_extractors[extractorName] = cv::DescriptorExtractor::create(extractorName);
#else
if (extractorName == "SIFT") {
#ifdef VISP_HAVE_OPENCV_XFEATURES2D
#if defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
// SIFT is no more patented since 09/03/2020
#if (VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
m_extractors[extractorName] = cv::SIFT::create();
#else
m_extractors[extractorName] = cv::xfeatures2d::SIFT::create();
#endif
#else
std::stringstream ss_msg;
ss_msg << "Fail to initialize the extractor: SIFT. OpenCV version " << std::hex << VISP_HAVE_OPENCV_VERSION
Expand Down Expand Up @@ -2646,8 +2661,11 @@ void vpKeyPoint::initFeatureNames()
#if (VISP_HAVE_OPENCV_VERSION < 0x030000) || (defined(VISP_HAVE_OPENCV_XFEATURES2D))
m_mapOfDetectorNames[DETECTOR_STAR] = "STAR";
#endif
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
m_mapOfDetectorNames[DETECTOR_SIFT] = "SIFT";
#endif
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
m_mapOfDetectorNames[DETECTOR_SURF] = "SURF";
#endif
#if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
Expand All @@ -2667,8 +2685,11 @@ void vpKeyPoint::initFeatureNames()
m_mapOfDescriptorNames[DESCRIPTOR_FREAK] = "FREAK";
m_mapOfDescriptorNames[DESCRIPTOR_BRIEF] = "BRIEF";
#endif
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
m_mapOfDescriptorNames[DESCRIPTOR_SIFT] = "SIFT";
#endif
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
m_mapOfDescriptorNames[DESCRIPTOR_SURF] = "SURF";
#endif
#if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
Expand Down
5 changes: 4 additions & 1 deletion modules/vision/test/key-point/testKeyPoint-5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis
detectorNames.push_back("AKAZE");
#endif

#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
detectorNames.push_back("PyramidSIFT");
detectorNames.push_back("SIFT");
#endif
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
detectorNames.push_back("PyramidSURF");
detectorNames.push_back("SURF");
#endif
Expand Down
5 changes: 4 additions & 1 deletion modules/vision/test/key-point/testKeyPoint-6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@ void run_test(const std::string &env_ipath, bool opt_click_allowed, bool opt_dis
vpKeyPoint keyPoints;

std::vector<std::string> descriptorNames;
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
descriptorNames.push_back("SIFT");
#endif
#if defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)
descriptorNames.push_back("SURF");
#endif
descriptorNames.push_back("ORB");
Expand Down
3 changes: 2 additions & 1 deletion modules/vision/test/key-point/testKeyPoint-7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ void run_test(const std::string &env_ipath, const std::string &opath, vpImage<T

// Test with floating point descriptor
#if defined(VISP_HAVE_OPENCV_NONFREE) || \
((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(VISP_HAVE_OPENCV_XFEATURES2D))
((VISP_HAVE_OPENCV_VERSION >= 0x030000) && defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400))
{
std::string keypointName = "SIFT";
keyPoints.setDetector(keypointName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ int main()
{
//! [Define]
#if (VISP_HAVE_OPENCV_VERSION >= 0x020101) && \
(defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D))
(defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400))
//! [Define]
vpImage<unsigned char> I;

Expand Down Expand Up @@ -56,9 +57,15 @@ int main()
vpColor::white, 2);
//! [Display]

vpChrono chrono;
chrono.start();
//! [Matching]
unsigned int nbMatch = keypoint.matchPoint(I);
//! [Matching]
chrono.stop();
std::ostringstream oss;
oss << "Computation time: " << chrono.getDurationMs() << " ms";
vpDisplay::displayText(Idisp, vpImagePoint(20, 20), oss.str(), vpColor::red);

std::cout << "Matches=" << nbMatch << std::endl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ int main(int argc, char **argv)
//! [MBT code]

//! [Keypoint selection]
#if (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D))
#if (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
std::string detectorName = "SIFT";
std::string extractorName = "SIFT";
std::string matcherName = "BruteForce";
Expand Down
3 changes: 2 additions & 1 deletion tutorial/detection/object/tutorial-detection-object-mbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ int main(int argc, char **argv)
//! [MBT code]

//! [Keypoint selection]
#if (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D))
#if (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
std::string detectorName = "SIFT";
std::string extractorName = "SIFT";
std::string matcherName = "BruteForce";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ int main(int argc, char *argv[])
tracker.setProjectionErrorComputation(true);
tracker.setProjectionErrorDisplay(display_projection_error);

#if (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D))
#if (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
std::string detectorName = "SIFT";
std::string extractorName = "SIFT";
std::string matcherName = "BruteForce";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ int main(int argc, char **argv)
tracker.setProjectionErrorDisplay(opt_display_projection_error);
//! [Set projection error computation]

#if (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D))
#if (defined(VISP_HAVE_OPENCV_NONFREE) || defined(VISP_HAVE_OPENCV_XFEATURES2D)) || \
(VISP_HAVE_OPENCV_VERSION >= 0x030411 && CV_MAJOR_VERSION < 4) || (VISP_HAVE_OPENCV_VERSION >= 0x040400)
std::string detectorName = "SIFT";
std::string extractorName = "SIFT";
std::string matcherName = "BruteForce";
Expand Down

0 comments on commit dfa7e4b

Please sign in to comment.