From c7ed37ff72972e48fbb253d7410e8d9740effc13 Mon Sep 17 00:00:00 2001 From: Raghavender Sahdev Date: Sat, 2 Sep 2017 01:58:09 -0400 Subject: [PATCH] fixed opencv version issue for AKAZE,LATCH,LSD,BLD features and updated authors file --- AUTHORS | 4 + doc/man-pages/CMakeLists.txt | 1 + libs/vision/src/CFeatureExtraction_AKAZE.cpp | 78 +++++------------- libs/vision/src/CFeatureExtraction_LATCH.cpp | 54 ++++++------- .../vision/src/CFeatureExtraction_LSD_BLD.cpp | 80 +++++++------------ 5 files changed, 82 insertions(+), 135 deletions(-) diff --git a/AUTHORS b/AUTHORS index 77efebc772..095b37095f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -154,5 +154,9 @@ the GitHub contributors page (https://github.com/MRPT/mrpt/graphs/contributors). * Alisa Chukaeva (LisGein), Moscow Technological University (2017) - The application robot-map-gui. +* Raghavender Sahdev, York University, Canada (GSoC 2017) https://github.com/raghavendersahdev + - The application benchmarking-image-features + - added files in the mrpt/libs/vision (detectors: AKAZE, LSD line detectors; descriptors: LATCH, BLD) + Several bug reports have been provided from MRPT users world-wide. We kindly thank all of them for this valuable feedback, and they are usually mentioned in changelogs. diff --git a/doc/man-pages/CMakeLists.txt b/doc/man-pages/CMakeLists.txt index 21a0dc90c9..4209e94305 100644 --- a/doc/man-pages/CMakeLists.txt +++ b/doc/man-pages/CMakeLists.txt @@ -79,6 +79,7 @@ IF (PROG_GZIP AND PROG_POD2MAN) CREATE_MANPAGE_PROJECT(DifOdometry-Datasets) CREATE_MANPAGE_PROJECT(DifOdometry-Camera) + CREATE_MANPAGE_PROJECT(robot-map-gui) CREATE_MANPAGE_PROJECT(benchmarking-image-features) ENDIF (PROG_GZIP AND PROG_POD2MAN) diff --git a/libs/vision/src/CFeatureExtraction_AKAZE.cpp b/libs/vision/src/CFeatureExtraction_AKAZE.cpp index 9e45ee3a3d..2159201dbc 100644 --- a/libs/vision/src/CFeatureExtraction_AKAZE.cpp +++ b/libs/vision/src/CFeatureExtraction_AKAZE.cpp @@ -1,41 +1,36 @@ -// -// Created by raghavender on 28/06/17. -// +/* +------------------------------------------------------------------------+ + | Mobile Robot Programming Toolkit (MRPT) | + | http://www.mrpt.org/ | + | | + | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file | + | See: http://www.mrpt.org/Authors - All rights reserved. | + | Released under BSD License. See details in http://www.mrpt.org/License | + +------------------------------------------------------------------------+ */ -#include -#include -#include +/*--------------------------------------------------------------- + APPLICATION: CFeatureExtraction + FILE: CFeatureExtraction_AKAZE.cpp + AUTHOR: Raghavender Sahdev + ---------------------------------------------------------------*/ -#include -#include -#include -#include "opencv2/core.hpp" -#include -#include -#include -#include "opencv2/features2d.hpp" -#include "opencv2/xfeatures2d.hpp" -#include -#include -#include "vision-precomp.h" // Precompiled headers +// Universal include for all versions of OpenCV +#include +#include "vision-precomp.h" // Precompiled headers #include #include // important import #include -#include - using namespace mrpt::vision; using namespace mrpt::utils; - using namespace mrpt::math; using namespace mrpt; - using namespace std; -using namespace cv; + + void CFeatureExtraction::extractFeaturesAKAZE( const mrpt::utils::CImage & inImg, @@ -48,28 +43,19 @@ void CFeatureExtraction::extractFeaturesAKAZE( MRPT_UNUSED_PARAM(ROI); MRPT_START #if MRPT_HAS_OPENCV -# if MRPT_OPENCV_VERSION_NUM < 0x210 - THROW_EXCEPTION("This function requires OpenCV > 2.1.0") +# if MRPT_OPENCV_VERSION_NUM < 0x300 + THROW_EXCEPTION("This function requires OpenCV > 3.0.0") # else using namespace cv; - vector cv_feats; // The opencv keypoint output vector - // Make sure we operate on a gray-scale version of the image: const CImage inImg_gray( inImg, FAST_REF_OR_CONVERT_TO_GRAY ); - -#if MRPT_OPENCV_VERSION_NUM >= 0x211 - -// cv::Mat *mask ; -// if( _mask ) -// mask = static_cast(_mask); +#if MRPT_OPENCV_VERSION_NUM >= 0x300 const Mat theImg = cvarrToMat( inImg_gray.getAs() ); - - Ptr akaze = AKAZE::create(options.AKAZEOptions.descriptor_type , options.AKAZEOptions.descriptor_size , options.AKAZEOptions.descriptor_channels , options.AKAZEOptions.threshold , options.AKAZEOptions.nOctaves , options.AKAZEOptions.nOctaveLayers , options.AKAZEOptions.diffusivity); @@ -80,13 +66,6 @@ void CFeatureExtraction::extractFeaturesAKAZE( const size_t N = cv_feats.size(); #endif - - // Now: - // 1) Sort them by "response": It's ~100 times faster to sort a list of - // indices "sorted_indices" than sorting directly the actual list of features "cv_feats" - //std::vector sorted_indices(N); - //for (size_t i=0;i >(cv_feats) ); // sort the AKAZE features by line length for(int i=0; i nDesiredFeatures) ? nDesiredFeatures : N; const int offset = (int)this->options.patchSize/2 + 1; @@ -126,7 +95,7 @@ void CFeatureExtraction::extractFeaturesAKAZE( while( cont != nMax && i!=N ) { - // Take the next feature fromt the ordered list of good features: + // Take the next feature from the ordered list of good features: const KeyPoint &kp = cv_feats[i]; i++; @@ -164,11 +133,8 @@ void CFeatureExtraction::extractFeaturesAKAZE( ++cont; //cout << ft->x << " " << ft->y << endl; } - //feats.resize( cont ); // JL: really needed??? # endif #endif MRPT_END - - } diff --git a/libs/vision/src/CFeatureExtraction_LATCH.cpp b/libs/vision/src/CFeatureExtraction_LATCH.cpp index 0783e30bd7..42139f22a1 100644 --- a/libs/vision/src/CFeatureExtraction_LATCH.cpp +++ b/libs/vision/src/CFeatureExtraction_LATCH.cpp @@ -1,51 +1,45 @@ -// -// Created by raghavender on 28/06/17. -// - - - - -#include -#include - +/* +------------------------------------------------------------------------+ + | Mobile Robot Programming Toolkit (MRPT) | + | http://www.mrpt.org/ | + | | + | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file | + | See: http://www.mrpt.org/Authors - All rights reserved. | + | Released under BSD License. See details in http://www.mrpt.org/License | + +------------------------------------------------------------------------+ */ + +/*--------------------------------------------------------------- + APPLICATION: CFeatureExtraction + FILE: CFeatureExtraction_LATCH.cpp + AUTHOR: Raghavender Sahdev + ---------------------------------------------------------------*/ #include "vision-precomp.h" // Precompiled headers - #include #include // important import #include -#include // Universal include for all versions of OpenCV #include #ifdef HAVE_OPENCV_NONFREE //MRPT_HAS_OPENCV_NONFREE # include #endif -#ifdef HAVE_OPENCV_FEATURES2D -# include -# include -#endif + #ifdef HAVE_OPENCV_XFEATURES2D # include #endif - - - +#ifdef HAVE_OPENCV_FEATURES2D +# include using namespace cv::line_descriptor; +#endif using namespace mrpt::vision; using namespace mrpt::utils; - using namespace mrpt::math; using namespace mrpt; - using namespace std; -#if MRPT_HAS_OPENCV -# if MRPT_OPENCV_VERSION_NUM>=0x211 -using namespace cv; -# endif -#endif + + /************************************************************************************************ * internal_computeLATCHDescriptors @@ -54,14 +48,15 @@ void CFeatureExtraction::internal_computeLATCHDescriptors( const mrpt::utils::CImage &in_img, CFeatureList &in_features) const { + //function is tested with opencv 3.1 MRPT_START #if MRPT_HAS_OPENCV -# if MRPT_OPENCV_VERSION_NUM < 0x210 - THROW_EXCEPTION("This function requires OpenCV > 2.1.0") +# if MRPT_OPENCV_VERSION_NUM < 0x300 + THROW_EXCEPTION("This function requires OpenCV > 3.0.0") # else + using namespace cv; - //cout << "I am in LATCH descriptor" << endl; if (in_features.empty()) return; const size_t n_feats = in_features.size(); @@ -84,7 +79,6 @@ void CFeatureExtraction::internal_computeLATCHDescriptors( Ptr latch = xfeatures2d::LATCH::create(options.LATCHOptions.bytes, options.LATCHOptions.rotationInvariance, options.LATCHOptions.half_ssd_size); - latch->compute(cvImg, cv_feats, cv_descs); // ----------------------------------------------------------------- diff --git a/libs/vision/src/CFeatureExtraction_LSD_BLD.cpp b/libs/vision/src/CFeatureExtraction_LSD_BLD.cpp index b6fe227369..1a77c80919 100644 --- a/libs/vision/src/CFeatureExtraction_LSD_BLD.cpp +++ b/libs/vision/src/CFeatureExtraction_LSD_BLD.cpp @@ -1,34 +1,34 @@ -// -// Created by raghavender on 28/06/17. -// - -#include -#include - +/* +------------------------------------------------------------------------+ + | Mobile Robot Programming Toolkit (MRPT) | + | http://www.mrpt.org/ | + | | + | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file | + | See: http://www.mrpt.org/Authors - All rights reserved. | + | Released under BSD License. See details in http://www.mrpt.org/License | + +------------------------------------------------------------------------+ */ + +/*--------------------------------------------------------------- + APPLICATION: CFeatureExtraction + FILE: CFeatureExtraction_LSD_BLD.cpp + AUTHOR: Raghavender Sahdev + ---------------------------------------------------------------*/ #include "vision-precomp.h" // Precompiled headers - #include #include // important import #include #include -#ifdef HAVE_OPENCV_FEATURES2D -# include -#endif #ifdef HAVE_OPENCV_XFEATURES2D # include # include using namespace cv::line_descriptor; #endif - using namespace mrpt::vision; using namespace mrpt::utils; - using namespace mrpt::math; using namespace mrpt; - using namespace std; @@ -36,12 +36,13 @@ void CFeatureExtraction::extractFeaturesLSD(const mrpt::utils::CImage &inImg, C unsigned int init_ID, unsigned int nDesiredFeatures, const TImageROI &ROI) const { + //function is tested with opencv 3.1 MRPT_UNUSED_PARAM(ROI); MRPT_START #if MRPT_HAS_OPENCV -# if MRPT_OPENCV_VERSION_NUM < 0x210 - THROW_EXCEPTION("This function requires OpenCV > 2.1.0") +# if MRPT_OPENCV_VERSION_NUM < 0x300 + THROW_EXCEPTION("This function requires OpenCV > 3.0.0") # else using namespace cv; @@ -49,41 +50,28 @@ void CFeatureExtraction::extractFeaturesLSD(const mrpt::utils::CImage &inImg, C vector cv_feats; // The opencv keypoint output vector vector cv_line; +#if MRPT_OPENCV_VERSION_NUM >= 0x300 + // Make sure we operate on a gray-scale version of the image: const CImage inImg_gray( inImg, FAST_REF_OR_CONVERT_TO_GRAY ); - -#if MRPT_OPENCV_VERSION_NUM >= 0x211 - - const Mat theImg = cvarrToMat( inImg_gray.getAs() ); /* create a random binary mask */ cv::Mat mask = Mat::ones( theImg.size(), CV_8UC1 ); - Ptr bd = LSDDetector::createLSDDetector(); - /* create a structure to store extracted lines */ - - /* extract lines */ cv::Mat output = theImg.clone(); bd->detect( theImg, cv_line, options.LSDOptions.scale, options.LSDOptions.nOctaves, mask ); - // *All* the features have been extracted. const size_t N = cv_line.size(); - + #endif - // Now: - // 1) Sort them by "response": It's ~100 times faster to sort a list of - // indices "sorted_indices" than sorting directly the actual list of features "cv_feats" - //std::vector sorted_indices(N); - //for (size_t i=0;i >(cv_line) ); - + // 1) Sort them by "response": // sort the LSD features by line length for(int i=0; i nDesiredFeatures) ? nDesiredFeatures : N; const int offset = (int)this->options.patchSize/2 + 1; const size_t size_2 = options.patchSize/2; @@ -179,13 +164,10 @@ void CFeatureExtraction::extractFeaturesLSD(const mrpt::utils::CImage &inImg, C ++cont; //cout << ft->x << " " << ft->y << endl; } - //feats.resize( cont ); // JL: really needed??? # endif #endif MRPT_END - - } @@ -196,7 +178,13 @@ void CFeatureExtraction::internal_computeBLDLineDescriptors( const mrpt::utils::CImage &in_img, CFeatureList &in_features) const { -//#if HAVE_OPENCV_WITH_SURF + //function is tested with opencv 3.1 + +#if MRPT_HAS_OPENCV +# if MRPT_OPENCV_VERSION_NUM < 0x300 + THROW_EXCEPTION("This function requires OpenCV > 3.0.0") +# else + using namespace cv; if (in_features.empty()) return; @@ -223,15 +211,9 @@ void CFeatureExtraction::internal_computeBLDLineDescriptors( bd2->detect( img, keylines, mask ); /* compute descriptors */ - bd2->compute( img, keylines, cv_descs); - - keylines.resize(in_features.size()); - - -//gb redesign end // ----------------------------------------------------------------- // MRPT Wrapping // ----------------------------------------------------------------- @@ -247,9 +229,9 @@ void CFeatureExtraction::internal_computeBLDLineDescriptors( ft->descriptors.BLD[m] = cv_descs.at(i,m); // Get the SURF descriptor } // end for -//#else - // THROW_EXCEPTION("Method not available: MRPT compiled without OpenCV, or against a version of OpenCV without SURF") -//#endif //MRPT_HAS_OPENCV +#endif // end of opencv3 version check + +#endif //MRPT_HAS_OPENCV } // end internal_computeBLDDescriptors