diff --git a/corelib/include/rtabmap/core/Features2d.h b/corelib/include/rtabmap/core/Features2d.h index 20a7dc04..b02b04b6 100644 --- a/corelib/include/rtabmap/core/Features2d.h +++ b/corelib/include/rtabmap/core/Features2d.h @@ -25,8 +25,8 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef KEYPOINTDESCRIPTOR_H_ -#define KEYPOINTDESCRIPTOR_H_ +#ifndef FEATURES2D_H_ +#define FEATURES2D_H_ #include "rtabmap/core/RtabmapExp.h" // DLL export/import defines @@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "rtabmap/core/Parameters.h" +#if CV_MAJOR_VERSION < 3 namespace cv{ class SURF; class SIFT; @@ -45,6 +46,44 @@ namespace gpu { class FAST_GPU; } } +typedef cv::SIFT CV_SIFT; +typedef cv::SURF CV_SURF; +typedef cv::ORB CV_ORB; +typedef cv::FastFeatureDetector CV_FAST; +typedef cv::FREAK CV_FREAK; +typedef cv::GFTTDetector CV_GFTT; +typedef cv::BriefDescriptorExtractor CV_BRIEF; +typedef cv::BRISK CV_BRISK; +typedef cv::gpu::SURF_GPU CV_SURF_GPU; +typedef cv::gpu::ORB_GPU CV_ORB_GPU; +typedef cv::gpu::FAST_GPU CV_FAST_GPU; +#else +namespace cv{ +namespace xfeatures2d { +class FREAK; +class BriefDescriptorExtractor; +class SIFT; +class SURF; +} +namespace cuda { +class FastFeatureDetector; +class ORB; +class SURF_CUDA; +} +} +typedef cv::xfeatures2d::SIFT CV_SIFT; +typedef cv::xfeatures2d::SURF CV_SURF; +typedef cv::ORB CV_ORB; +typedef cv::FastFeatureDetector CV_FAST; +typedef cv::xfeatures2d::FREAK CV_FREAK; +typedef cv::GFTTDetector CV_GFTT; +typedef cv::xfeatures2d::BriefDescriptorExtractor CV_BRIEF; +typedef cv::BRISK CV_BRISK; +typedef cv::cuda::SURF_CUDA CV_SURF_GPU; +typedef cv::cuda::ORB CV_ORB_GPU; +typedef cv::cuda::FastFeatureDetector CV_FAST_GPU; +#endif + namespace rtabmap { @@ -134,8 +173,8 @@ private: float gpuKeypointsRatio_; bool gpuVersion_; - cv::SURF * _surf; - cv::gpu::SURF_GPU * _gpuSurf; + cv::Ptr _surf; + cv::Ptr _gpuSurf; }; //SIFT @@ -159,7 +198,7 @@ private: double edgeThreshold_; double sigma_; - cv::SIFT * _sift; + cv::Ptr _sift; }; //ORB @@ -190,8 +229,8 @@ private: int fastThreshold_; bool nonmaxSuppresion_; - cv::ORB * _orb; - cv::gpu::ORB_GPU * _gpuOrb; + cv::Ptr _orb; + cv::Ptr _gpuOrb; }; //FAST @@ -212,8 +251,8 @@ private: bool gpu_; double gpuKeypointsRatio_; - cv::FastFeatureDetector * _fast; - cv::gpu::FAST_GPU * _gpuFast; + cv::Ptr _fast; + cv::Ptr _gpuFast; }; //FAST_BRIEF @@ -232,7 +271,7 @@ private: private: int bytes_; - cv::BriefDescriptorExtractor * _brief; + cv::Ptr _brief; }; //FAST_FREAK @@ -254,7 +293,7 @@ private: float patternScale_; int nOctaves_; - cv::FREAK * _freak; + cv::Ptr _freak; }; //GFTT @@ -277,7 +316,7 @@ private: bool _useHarrisDetector; double _k; - cv::GFTTDetector * _gftt; + cv::Ptr _gftt; }; //GFTT_BRIEF @@ -296,7 +335,7 @@ private: private: int bytes_; - cv::BriefDescriptorExtractor * _brief; + cv::Ptr _brief; }; //GFTT_FREAK @@ -318,7 +357,7 @@ private: float patternScale_; int nOctaves_; - cv::FREAK * _freak; + cv::Ptr _freak; }; //BRISK @@ -340,10 +379,10 @@ private: int octaves_; float patternScale_; - cv::BRISK * brisk_; + cv::Ptr brisk_; }; } -#endif /* KEYPOINTDESCRIPTOR_H_ */ +#endif /* FEATURES2D_H_ */ diff --git a/corelib/include/rtabmap/core/OdometryInfo.h b/corelib/include/rtabmap/core/OdometryInfo.h index a5f27adb..798ee45a 100644 --- a/corelib/include/rtabmap/core/OdometryInfo.h +++ b/corelib/include/rtabmap/core/OdometryInfo.h @@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ODOMETRYINFO_H_ #define ODOMETRYINFO_H_ +#include + namespace rtabmap { class OdometryInfo diff --git a/corelib/include/rtabmap/core/util3d.h b/corelib/include/rtabmap/core/util3d.h index 5164b158..8f76c22a 100644 --- a/corelib/include/rtabmap/core/util3d.h +++ b/corelib/include/rtabmap/core/util3d.h @@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include namespace rtabmap diff --git a/corelib/include/rtabmap/core/util3d_features.h b/corelib/include/rtabmap/core/util3d_features.h index 6670f321..1cec93f6 100644 --- a/corelib/include/rtabmap/core/util3d_features.h +++ b/corelib/include/rtabmap/core/util3d_features.h @@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace rtabmap { @@ -86,7 +87,7 @@ std::multimap RTABMAP_EXP generateWords3DMono( Transform & cameraTransform, int pnpIterations = 100, float pnpReprojError = 8.0f, - int pnpFlags = cv::ITERATIVE, + int pnpFlags = 0, // cv::SOLVEPNP_ITERATIVE float ransacParam1 = 3.0f, float ransacParam2 = 0.99f, const std::multimap & refGuess3D = std::multimap(), @@ -96,14 +97,6 @@ std::multimap RTABMAP_EXP aggregate( const std::list & wordIds, const std::vector & keypoints); -pcl::PointCloud::Ptr RTABMAP_EXP get3DFASTKpts( - const cv::Mat & image, - const cv::Mat & imageDepth, - float constant, - int fastThreshold=50, - bool fastNonmaxSuppression=true, - float maxDepth = 5.0f); - } // namespace util3d } // namespace rtabmap diff --git a/corelib/include/rtabmap/core/util3d_mapping.h b/corelib/include/rtabmap/core/util3d_mapping.h index 6f13b51a..fceb7e7a 100644 --- a/corelib/include/rtabmap/core/util3d_mapping.h +++ b/corelib/include/rtabmap/core/util3d_mapping.h @@ -31,6 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "rtabmap/core/RtabmapExp.h" #include +#include #include #include #include diff --git a/corelib/src/Camera.cpp b/corelib/src/Camera.cpp index 43e5efaa..3e484aa2 100644 --- a/corelib/src/Camera.cpp +++ b/corelib/src/Camera.cpp @@ -287,6 +287,7 @@ cv::Mat CameraImages::captureImage() UDEBUG("width=%d, height=%d, channels=%d, elementSize=%d, total=%d", img.cols, img.rows, img.channels(), img.elemSize(), img.total()); +#if CV_MAJOR_VERSION < 3 // FIXME : it seems that some png are incorrectly loaded with opencv c++ interface, where c interface works... if(img.depth() != CV_8U) { @@ -296,6 +297,7 @@ cv::Mat CameraImages::captureImage() img = cv::Mat(i, true); cvReleaseImage(&i); } +#endif if(img.channels()>3) { diff --git a/corelib/src/Features2d.cpp b/corelib/src/Features2d.cpp index 405fbdec..55aa82ea 100644 --- a/corelib/src/Features2d.cpp +++ b/corelib/src/Features2d.cpp @@ -34,14 +34,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "rtabmap/utilite/ULogger.h" #include "rtabmap/utilite/UTimer.h" #include -#include #include +#include -#if RTABMAP_NONFREE == 1 -#if CV_MAJOR_VERSION > 2 || (CV_MAJOR_VERSION >=2 && CV_MINOR_VERSION >=4) -#include -#include +#if CV_MAJOR_VERSION < 3 +#include +#else +#include #endif + +#ifdef HAVE_OPENCV_NONFREE + #if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >=4 + #include + #include + #endif +#endif +#ifdef HAVE_OPENCV_XFEATURES2D + #include + #include + #include #endif namespace rtabmap { @@ -330,12 +341,29 @@ void Feature2D::parseParameters(const ParametersMap & parameters) } Feature2D * Feature2D::create(Feature2D::Type & type, const ParametersMap & parameters) { - if(RTABMAP_NONFREE == 0 && - (type == Feature2D::kFeatureSurf || type == Feature2D::kFeatureSift)) + if(RTABMAP_NONFREE == 0) { - UWARN("SURF/SIFT features cannot be used because OpenCV was not built with nonfree module. ORB is used instead."); - type = Feature2D::kFeatureOrb; + if(type == Feature2D::kFeatureSurf || type == Feature2D::kFeatureSift) + { +#if CV_MAJOR_VERSION < 3 + UWARN("SURF/SIFT features cannot be used because OpenCV was not built with nonfree module. ORB is used instead."); +#else + UWARN("SURF/SIFT features cannot be used because OpenCV was not built with xfeatures2d module. ORB is used instead."); +#endif + type = Feature2D::kFeatureOrb; + } +#if CV_MAJOR_VERSION == 3 + if(type == Feature2D::kFeatureFastBrief || + type == Feature2D::kFeatureFastFreak || + type == Feature2D::kFeatureGfttBrief || + type == Feature2D::kFeatureGfttFreak) + { + UWARN("BRIEF/FREAK features cannot be used because OpenCV was not built with xfeatures2d module. ORB is used instead."); + type = Feature2D::kFeatureOrb; + } +#endif } + Feature2D * feature2D = 0; switch(type) { @@ -432,25 +460,13 @@ SURF::SURF(const ParametersMap & parameters) : extended_(Parameters::defaultSURFExtended()), upright_(Parameters::defaultSURFUpright()), gpuKeypointsRatio_(Parameters::defaultSURFGpuKeypointsRatio()), - gpuVersion_(Parameters::defaultSURFGpuVersion()), - _surf(0), - _gpuSurf(0) + gpuVersion_(Parameters::defaultSURFGpuVersion()) { parseParameters(parameters); } SURF::~SURF() { -#if RTABMAP_NONFREE == 1 - if(_surf) - { - delete _surf; - } - if(_gpuSurf) - { - delete _gpuSurf; - } -#endif } void SURF::parseParameters(const ParametersMap & parameters) @@ -466,29 +482,30 @@ void SURF::parseParameters(const ParametersMap & parameters) Parameters::parse(parameters, Parameters::kSURFGpuVersion(), gpuVersion_); #if RTABMAP_NONFREE == 1 - if(_gpuSurf) +#if CV_MAJOR_VERSION < 3 + if(gpuVersion_ && cv::gpu::getCudaEnabledDeviceCount() == 0) { - delete _gpuSurf; - _gpuSurf = 0; + UWARN("GPU version of SURF not available! Using CPU version instead..."); + gpuVersion_ = false; } - if(_surf) +#else + if(gpuVersion_ && cv::cuda::getCudaEnabledDeviceCount() == 0) { - delete _surf; - _surf = 0; + UWARN("GPU version of SURF not available! Using CPU version instead..."); + gpuVersion_ = false; } - - if(gpuVersion_ && cv::gpu::getCudaEnabledDeviceCount()) +#endif + if(gpuVersion_) { - _gpuSurf = new cv::gpu::SURF_GPU(hessianThreshold_, nOctaves_, nOctaveLayers_, extended_, gpuKeypointsRatio_, upright_); + _gpuSurf = cv::Ptr(new CV_SURF_GPU(hessianThreshold_, nOctaves_, nOctaveLayers_, extended_, gpuKeypointsRatio_, upright_)); } else { - if(gpuVersion_) - { - UWARN("GPU version of SURF not available! Using CPU version instead..."); - } - - _surf = new cv::SURF(hessianThreshold_, nOctaves_, nOctaveLayers_, extended_, upright_); +#if CV_MAJOR_VERSION < 3 + _surf = cv::Ptr(new CV_SURF(hessianThreshold_, nOctaves_, nOctaveLayers_, extended_, upright_)); +#else + _surf = CV_SURF::create(hessianThreshold_, nOctaves_, nOctaveLayers_, extended_, upright_); +#endif } #else UWARN("RTAB-Map is not built with OpenCV nonfree module so SURF cannot be used!"); @@ -502,10 +519,15 @@ std::vector SURF::generateKeypointsImpl(const cv::Mat & image, con #if RTABMAP_NONFREE == 1 cv::Mat imgRoi(image, roi); - if(_gpuSurf) + if(gpuVersion_) { +#if CV_MAJOR_VERSION < 3 cv::gpu::GpuMat imgGpu(imgRoi); - (*_gpuSurf)(imgGpu, cv::gpu::GpuMat(), keypoints); + (*_gpuSurf.obj)(imgGpu, cv::gpu::GpuMat(), keypoints); +#else + cv::cuda::GpuMat imgGpu(imgRoi); + (*_gpuSurf.get())(imgGpu, cv::cuda::GpuMat(), keypoints); +#endif } else { @@ -522,11 +544,17 @@ cv::Mat SURF::generateDescriptorsImpl(const cv::Mat & image, std::vector(new CV_SIFT(nfeatures_, nOctaveLayers_, contrastThreshold_, edgeThreshold_, sigma_)); +#else + _sift = CV_SIFT::create(nfeatures_, nOctaveLayers_, contrastThreshold_, edgeThreshold_, sigma_); +#endif #else UWARN("RTAB-Map is not built with OpenCV nonfree module so SIFT cannot be used!"); #endif @@ -637,23 +654,13 @@ ORB::ORB(const ParametersMap & parameters) : patchSize_(Parameters::defaultORBPatchSize()), gpu_(Parameters::defaultORBGpu()), fastThreshold_(Parameters::defaultFASTThreshold()), - nonmaxSuppresion_(Parameters::defaultFASTNonmaxSuppression()), - _orb(0), - _gpuOrb(0) + nonmaxSuppresion_(Parameters::defaultFASTNonmaxSuppression()) { parseParameters(parameters); } ORB::~ORB() { - if(_orb) - { - delete _orb; - } - if(_gpuOrb) - { - delete _gpuOrb; - } } void ORB::parseParameters(const ParametersMap & parameters) @@ -673,29 +680,44 @@ void ORB::parseParameters(const ParametersMap & parameters) Parameters::parse(parameters, Parameters::kFASTThreshold(), fastThreshold_); Parameters::parse(parameters, Parameters::kFASTNonmaxSuppression(), nonmaxSuppresion_); - if(_gpuOrb) +#if CV_MAJOR_VERSION < 3 + if(gpu_ && cv::gpu::getCudaEnabledDeviceCount() == 0) { - delete _gpuOrb; - _gpuOrb = 0; + UWARN("GPU version of ORB not available! Using CPU version instead..."); + gpu_ = false; } - if(_orb) +#else +#ifndef HAVE_OPENCV_CUDAFEATURES2D + if(gpu_) { - delete _orb; - _orb = 0; + UWARN("GPU version of ORB not available (OpenCV cudafeatures2d module)! Using CPU version instead..."); + gpu_ = false; } - - if(gpu_ && cv::gpu::getCudaEnabledDeviceCount()) +#endif + if(gpu_) { - _gpuOrb = new cv::gpu::ORB_GPU(nFeatures_, scaleFactor_, nLevels_, edgeThreshold_, firstLevel_, WTA_K_, scoreType_, patchSize_); + UWARN("GPU version of ORB available but not implemented yet! Using CPU version instead..."); + } + gpu_ = false; +#endif + if(gpu_) + { +#if CV_MAJOR_VERSION < 3 + _gpuOrb = cv::Ptr(new CV_ORB_GPU(nFeatures_, scaleFactor_, nLevels_, edgeThreshold_, firstLevel_, WTA_K_, scoreType_, patchSize_)); _gpuOrb->setFastParams(fastThreshold_, nonmaxSuppresion_); +#else +#ifdef HAVE_OPENCV_CUDAFEATURES2D + UFATAL("not implemented"); +#endif +#endif } else { - if(gpu_) - { - UWARN("GPU version of ORB not available! Using CPU version instead..."); - } - _orb = new cv::ORB(nFeatures_, scaleFactor_, nLevels_, edgeThreshold_, firstLevel_, WTA_K_, scoreType_, patchSize_); +#if CV_MAJOR_VERSION < 3 + _orb = cv::Ptr(new CV_ORB(nFeatures_, scaleFactor_, nLevels_, edgeThreshold_, firstLevel_, WTA_K_, scoreType_, patchSize_)); +#else + _orb = CV_ORB::create(nFeatures_, scaleFactor_, nLevels_, edgeThreshold_, firstLevel_, WTA_K_, scoreType_, patchSize_); +#endif } } @@ -704,10 +726,17 @@ std::vector ORB::generateKeypointsImpl(const cv::Mat & image, cons UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U); std::vector keypoints; cv::Mat imgRoi(image, roi); - if(_gpuOrb) + + if(gpu_) { +#if CV_MAJOR_VERSION < 3 cv::gpu::GpuMat imgGpu(imgRoi); - (*_gpuOrb)(imgGpu, cv::gpu::GpuMat(), keypoints); + (*_gpuOrb.obj)(imgGpu, cv::gpu::GpuMat(), keypoints); +#else +#ifdef HAVE_OPENCV_CUDAFEATURES2D + UFATAL("not implemented"); +#endif +#endif } else { @@ -726,11 +755,19 @@ cv::Mat ORB::generateDescriptorsImpl(const cv::Mat & image, std::vector(new CV_FAST(threshold_, nonmaxSuppression_)); +#else + _fast = CV_FAST::create(threshold_, nonmaxSuppression_); +#endif } } @@ -815,10 +862,16 @@ std::vector FAST::generateKeypointsImpl(const cv::Mat & image, con UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U); std::vector keypoints; cv::Mat imgRoi(image, roi); - if(_gpuFast) + if(gpu_) { +#if CV_MAJOR_VERSION < 3 cv::gpu::GpuMat imgGpu(imgRoi); - (*_gpuFast)(imgGpu, cv::gpu::GpuMat(), keypoints); + (*_gpuFast.obj)(imgGpu, cv::gpu::GpuMat(), keypoints); +#else +#ifdef HAVE_OPENCV_CUDAFEATURES2D + UFATAL("not implemented"); +#endif +#endif } else { @@ -832,18 +885,13 @@ std::vector FAST::generateKeypointsImpl(const cv::Mat & image, con ////////////////////////// FAST_BRIEF::FAST_BRIEF(const ParametersMap & parameters) : FAST(parameters), - bytes_(Parameters::defaultBRIEFBytes()), - _brief(0) + bytes_(Parameters::defaultBRIEFBytes()) { parseParameters(parameters); } FAST_BRIEF::~FAST_BRIEF() { - if(_brief) - { - delete _brief; - } } void FAST_BRIEF::parseParameters(const ParametersMap & parameters) @@ -851,19 +899,30 @@ void FAST_BRIEF::parseParameters(const ParametersMap & parameters) FAST::parseParameters(parameters); Parameters::parse(parameters, Parameters::kBRIEFBytes(), bytes_); - if(_brief) - { - delete _brief; - _brief = 0; - } - _brief = new cv::BriefDescriptorExtractor(bytes_); +#if CV_MAJOR_VERSION < 3 + _brief = cv::Ptr(new CV_BRIEF(bytes_)); +#else +#ifdef HAVE_OPENCV_XFEATURES2D + _brief = CV_BRIEF::create(bytes_); +#else + UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so Brief cannot be used!"); +#endif +#endif } cv::Mat FAST_BRIEF::generateDescriptorsImpl(const cv::Mat & image, std::vector & keypoints) const { UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U); cv::Mat descriptors; +#if CV_MAJOR_VERSION < 3 _brief->compute(image, keypoints, descriptors); +#else +#ifdef HAVE_OPENCV_XFEATURES2D + _brief->compute(image, keypoints, descriptors); +#else + UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so Brief cannot be used!"); +#endif +#endif return descriptors; } @@ -875,18 +934,13 @@ FAST_FREAK::FAST_FREAK(const ParametersMap & parameters) : orientationNormalized_(Parameters::defaultFREAKOrientationNormalized()), scaleNormalized_(Parameters::defaultFREAKScaleNormalized()), patternScale_(Parameters::defaultFREAKPatternScale()), - nOctaves_(Parameters::defaultFREAKNOctaves()), - _freak(0) + nOctaves_(Parameters::defaultFREAKNOctaves()) { parseParameters(parameters); } FAST_FREAK::~FAST_FREAK() { - if(_freak) - { - delete _freak; - } } void FAST_FREAK::parseParameters(const ParametersMap & parameters) @@ -898,20 +952,30 @@ void FAST_FREAK::parseParameters(const ParametersMap & parameters) Parameters::parse(parameters, Parameters::kFREAKPatternScale(), patternScale_); Parameters::parse(parameters, Parameters::kFREAKNOctaves(), nOctaves_); - if(_freak) - { - delete _freak; - _freak = 0; - } - - _freak = new cv::FREAK(orientationNormalized_, scaleNormalized_, patternScale_, nOctaves_); +#if CV_MAJOR_VERSION < 3 + _freak = cv::Ptr(new CV_FREAK(orientationNormalized_, scaleNormalized_, patternScale_, nOctaves_)); +#else +#ifdef HAVE_OPENCV_XFEATURES2D + _freak = CV_FREAK::create(orientationNormalized_, scaleNormalized_, patternScale_, nOctaves_); +#else + UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so Freak cannot be used!"); +#endif +#endif } cv::Mat FAST_FREAK::generateDescriptorsImpl(const cv::Mat & image, std::vector & keypoints) const { UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U); cv::Mat descriptors; +#if CV_MAJOR_VERSION < 3 _freak->compute(image, keypoints, descriptors); +#else +#ifdef HAVE_OPENCV_XFEATURES2D + _freak->compute(image, keypoints, descriptors); +#else + UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so Freak cannot be used!"); +#endif +#endif return descriptors; } @@ -924,18 +988,13 @@ GFTT::GFTT(const ParametersMap & parameters) : _minDistance(Parameters::defaultGFTTMinDistance()), _blockSize(Parameters::defaultGFTTBlockSize()), _useHarrisDetector(Parameters::defaultGFTTUseHarrisDetector()), - _k(Parameters::defaultGFTTK()), - _gftt(0) + _k(Parameters::defaultGFTTK()) { parseParameters(parameters); } GFTT::~GFTT() { - if(_gftt) - { - delete _gftt; - } } void GFTT::parseParameters(const ParametersMap & parameters) @@ -949,12 +1008,11 @@ void GFTT::parseParameters(const ParametersMap & parameters) Parameters::parse(parameters, Parameters::kGFTTUseHarrisDetector(), _useHarrisDetector); Parameters::parse(parameters, Parameters::kGFTTK(), _k); - if(_gftt) - { - delete _gftt; - _gftt = 0; - } - _gftt = new cv::GFTTDetector(_maxCorners, _qualityLevel, _minDistance, _blockSize, _useHarrisDetector ,_k); +#if CV_MAJOR_VERSION < 3 + _gftt = cv::Ptr(new CV_GFTT(_maxCorners, _qualityLevel, _minDistance, _blockSize, _useHarrisDetector ,_k)); +#else + _gftt = CV_GFTT::create(_maxCorners, _qualityLevel, _minDistance, _blockSize, _useHarrisDetector ,_k); +#endif } std::vector GFTT::generateKeypointsImpl(const cv::Mat & image, const cv::Rect & roi) const @@ -971,18 +1029,13 @@ std::vector GFTT::generateKeypointsImpl(const cv::Mat & image, con ////////////////////////// GFTT_BRIEF::GFTT_BRIEF(const ParametersMap & parameters) : GFTT(parameters), - bytes_(Parameters::defaultBRIEFBytes()), - _brief(0) + bytes_(Parameters::defaultBRIEFBytes()) { parseParameters(parameters); } GFTT_BRIEF::~GFTT_BRIEF() { - if(_brief) - { - delete _brief; - } } void GFTT_BRIEF::parseParameters(const ParametersMap & parameters) @@ -990,19 +1043,30 @@ void GFTT_BRIEF::parseParameters(const ParametersMap & parameters) GFTT::parseParameters(parameters); Parameters::parse(parameters, Parameters::kBRIEFBytes(), bytes_); - if(_brief) - { - delete _brief; - _brief = 0; - } - _brief = new cv::BriefDescriptorExtractor(bytes_); +#if CV_MAJOR_VERSION < 3 + _brief = cv::Ptr(new CV_BRIEF(bytes_)); +#else +#ifdef HAVE_OPENCV_XFEATURES2D + _brief = CV_BRIEF::create(bytes_); +#else + UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so Brief cannot be used!"); +#endif +#endif } cv::Mat GFTT_BRIEF::generateDescriptorsImpl(const cv::Mat & image, std::vector & keypoints) const { UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U); cv::Mat descriptors; +#if CV_MAJOR_VERSION < 3 _brief->compute(image, keypoints, descriptors); +#else +#ifdef HAVE_OPENCV_XFEATURES2D + _brief->compute(image, keypoints, descriptors); +#else + UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so Brief cannot be used!"); +#endif +#endif return descriptors; } @@ -1014,18 +1078,13 @@ GFTT_FREAK::GFTT_FREAK(const ParametersMap & parameters) : orientationNormalized_(Parameters::defaultFREAKOrientationNormalized()), scaleNormalized_(Parameters::defaultFREAKScaleNormalized()), patternScale_(Parameters::defaultFREAKPatternScale()), - nOctaves_(Parameters::defaultFREAKNOctaves()), - _freak(0) + nOctaves_(Parameters::defaultFREAKNOctaves()) { parseParameters(parameters); } GFTT_FREAK::~GFTT_FREAK() { - if(_freak) - { - delete _freak; - } } void GFTT_FREAK::parseParameters(const ParametersMap & parameters) @@ -1037,20 +1096,30 @@ void GFTT_FREAK::parseParameters(const ParametersMap & parameters) Parameters::parse(parameters, Parameters::kFREAKPatternScale(), patternScale_); Parameters::parse(parameters, Parameters::kFREAKNOctaves(), nOctaves_); - if(_freak) - { - delete _freak; - _freak = 0; - } - - _freak = new cv::FREAK(orientationNormalized_, scaleNormalized_, patternScale_, nOctaves_); +#if CV_MAJOR_VERSION < 3 + _freak = cv::Ptr(new CV_FREAK(orientationNormalized_, scaleNormalized_, patternScale_, nOctaves_)); +#else +#ifdef HAVE_OPENCV_XFEATURES2D + _freak = CV_FREAK::create(orientationNormalized_, scaleNormalized_, patternScale_, nOctaves_); +#else + UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so Freak cannot be used!"); +#endif +#endif } cv::Mat GFTT_FREAK::generateDescriptorsImpl(const cv::Mat & image, std::vector & keypoints) const { UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U); cv::Mat descriptors; +#if CV_MAJOR_VERSION < 3 _freak->compute(image, keypoints, descriptors); +#else +#ifdef HAVE_OPENCV_XFEATURES2D + _freak->compute(image, keypoints, descriptors); +#else + UWARN("RTAB-Map is not built with OpenCV xfeatures2d module so Freak cannot be used!"); +#endif +#endif return descriptors; } @@ -1060,18 +1129,13 @@ cv::Mat GFTT_FREAK::generateDescriptorsImpl(const cv::Mat & image, std::vector(new CV_BRISK(thresh_, octaves_, patternScale_)); +#else + brisk_ = CV_BRISK::create(thresh_, octaves_, patternScale_); +#endif } std::vector BRISK::generateKeypointsImpl(const cv::Mat & image, const cv::Rect & roi) const diff --git a/corelib/src/Memory.cpp b/corelib/src/Memory.cpp index 609d8659..6b032d58 100644 --- a/corelib/src/Memory.cpp +++ b/corelib/src/Memory.cpp @@ -1933,7 +1933,7 @@ Transform Memory::computeVisualTransform( cameraTransform, 100, 4.0f, - cv::ITERATIVE, + 0, // cv::SOLVEPNP_ITERATIVE 1.0f, 0.99f, oldS.getWords3(), diff --git a/corelib/src/VWDictionary.cpp b/corelib/src/VWDictionary.cpp index e043c0dc..a8242105 100644 --- a/corelib/src/VWDictionary.cpp +++ b/corelib/src/VWDictionary.cpp @@ -34,7 +34,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "rtabmap/utilite/UtiLite.h" +#include +#if CV_MAJOR_VERSION < 3 #include +#else +#include +#ifdef HAVE_OPENCV_CUDAFEATURES2D +#include +#endif +#endif #include #include @@ -220,11 +228,26 @@ void VWDictionary::setNNStrategy(NNStrategy strategy) { if(strategy!=kNNUndef) { +#if CV_MAJOR_VERSION < 3 if(strategy == kNNBruteForceGPU && !cv::gpu::getCudaEnabledDeviceCount()) { UERROR("Nearest neighobr strategy \"kNNBruteForceGPU\" chosen but no CUDA devices found! Doing \"kNNBruteForce\" instead."); strategy = kNNBruteForce; } +#else + if(strategy == kNNBruteForceGPU && !cv::cuda::getCudaEnabledDeviceCount()) + { + UERROR("Nearest neighobr strategy \"kNNBruteForceGPU\" chosen but no CUDA devices found! Doing \"kNNBruteForce\" instead."); + strategy = kNNBruteForce; + } +#endif +#ifndef HAVE_OPENCV_CUDAFEATURES2D + if(strategy == kNNBruteForceGPU) + { + UERROR("Nearest neighobr strategy \"kNNBruteForceGPU\" chosen but OpenCV cudafeatures2d module is not found! Doing \"kNNBruteForce\" instead."); + strategy = kNNBruteForce; + } +#endif if(RTABMAP_NONFREE == 0 && strategy == kNNFlannKdTree) { @@ -466,6 +489,7 @@ std::list VWDictionary::addNewWords(const cv::Mat & descriptors, else if(_strategy == kNNBruteForceGPU) { bruteForce = true; +#if CV_MAJOR_VERSION < 3 cv::gpu::GpuMat newDescriptorsGpu(descriptors); cv::gpu::GpuMat lastDescriptorsGpu(_dataTree); if(type==CV_8U) @@ -478,6 +502,22 @@ std::list VWDictionary::addNewWords(const cv::Mat & descriptors, cv::gpu::BruteForceMatcher_GPU > gpuMatcher; gpuMatcher.knnMatch(newDescriptorsGpu, lastDescriptorsGpu, matches, k); } +#else +#ifdef HAVE_OPENCV_CUDAFEATURES2D + cv::cuda::GpuMat newDescriptorsGpu(descriptors); + cv::cuda::GpuMat lastDescriptorsGpu(_dataTree); + if(type==CV_8U) + { + cv::cuda::BruteForceMatcher_GPU gpuMatcher; + gpuMatcher.knnMatch(newDescriptorsGpu, lastDescriptorsGpu, matches, k); + } + else + { + cv::cuda::BruteForceMatcher_GPU > gpuMatcher; + gpuMatcher.knnMatch(newDescriptorsGpu, lastDescriptorsGpu, matches, k); + } +#endif +#endif } else { @@ -681,6 +721,7 @@ std::vector VWDictionary::findNN(const std::list & vws) const else if(_strategy == kNNBruteForceGPU) { bruteForce = true; +#if CV_MAJOR_VERSION < 3 cv::gpu::GpuMat newDescriptorsGpu(query); cv::gpu::GpuMat lastDescriptorsGpu(_dataTree); if(type==CV_8U) @@ -693,6 +734,23 @@ std::vector VWDictionary::findNN(const std::list & vws) const cv::gpu::BruteForceMatcher_GPU > gpuMatcher; gpuMatcher.knnMatch(newDescriptorsGpu, lastDescriptorsGpu, matches, k); } +#else +#ifdef HAVE_OPENCV_CUDAFEATURES2D + cv::cuda::GpuMat newDescriptorsGpu(query); + cv::cuda::GpuMat lastDescriptorsGpu(_dataTree); + cv::Ptr gpuMatcher; + if(type==CV_8U) + { + gpuMatcher = cv::cuda::DescriptorMatcher::createBFMatcher(cv::NORM_HAMMING); + gpuMatcher->knnMatch(newDescriptorsGpu, lastDescriptorsGpu, matches, k); + } + else + { + gpuMatcher = cv::cuda::DescriptorMatcher::createBFMatcher(cv::NORM_L2); + gpuMatcher.knnMatch(newDescriptorsGpu, lastDescriptorsGpu, matches, k); + } +#endif +#endif } else { diff --git a/corelib/src/VisualWord.h b/corelib/src/VisualWord.h index c2284e4e..8889a4ab 100644 --- a/corelib/src/VisualWord.h +++ b/corelib/src/VisualWord.h @@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "rtabmap/core/RtabmapExp.h" // DLL export/import defines #include +#include namespace rtabmap { diff --git a/corelib/src/util2d.cpp b/corelib/src/util2d.cpp index 46bbf2ba..856ec7a9 100644 --- a/corelib/src/util2d.cpp +++ b/corelib/src/util2d.cpp @@ -58,7 +58,8 @@ cv::Mat disparityFromStereoImages( { leftMono = leftImage; } - + cv::Mat disparity; +#if CV_MAJOR_VERSION < 3 cv::StereoBM stereo(cv::StereoBM::BASIC_PRESET); stereo.state->SADWindowSize = 15; stereo.state->minDisparity = 0; @@ -69,8 +70,20 @@ cv::Mat disparityFromStereoImages( stereo.state->textureThreshold = 10; stereo.state->speckleWindowSize = 100; stereo.state->speckleRange = 4; - cv::Mat disparity; stereo(leftMono, rightImage, disparity, CV_16SC1); +#else + cv::Ptr stereo = cv::StereoBM::create(); + stereo->setBlockSize(15); + stereo->setMinDisparity(0); + stereo->setNumDisparities(64); + stereo->setPreFilterSize(9); + stereo->setPreFilterCap(31); + stereo->setUniquenessRatio(15); + stereo->setTextureThreshold(10); + stereo->setSpeckleWindowSize(100); + stereo->setSpeckleRange(4); + stereo->compute(leftMono, rightImage, disparity); +#endif return disparity; } diff --git a/corelib/src/util3d_features.cpp b/corelib/src/util3d_features.cpp index 5352a7cf..b35554ef 100644 --- a/corelib/src/util3d_features.cpp +++ b/corelib/src/util3d_features.cpp @@ -477,32 +477,6 @@ std::multimap aggregate( return words; } -pcl::PointCloud::Ptr get3DFASTKpts( - const cv::Mat & image, - const cv::Mat & imageDepth, - float constant, - int fastThreshold, - bool fastNonmaxSuppression, - float maxDepth) -{ - // Extract words - cv::FastFeatureDetector detector(fastThreshold, fastNonmaxSuppression); - std::vector kpts; - detector.detect(image, kpts); - - pcl::PointCloud::Ptr points(new pcl::PointCloud); - for(unsigned int i=0; ipush_back(pt); - } - } - UDEBUG("points %d -> %d", (int)kpts.size(), (int)points->size()); - return points; -} - } } diff --git a/guilib/include/rtabmap/gui/CloudViewer.h b/guilib/include/rtabmap/gui/CloudViewer.h index 133f84a5..7922e088 100644 --- a/guilib/include/rtabmap/gui/CloudViewer.h +++ b/guilib/include/rtabmap/gui/CloudViewer.h @@ -42,6 +42,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include #include diff --git a/guilib/src/CalibrationDialog.cpp b/guilib/src/CalibrationDialog.cpp index 5a722b09..cb21cea4 100644 --- a/guilib/src/CalibrationDialog.cpp +++ b/guilib/src/CalibrationDialog.cpp @@ -736,12 +736,27 @@ void CalibrationDialog::calibrate() objectPoints.resize(stereoImagePoints_[0].size(), objectPoints[0]); // calibrate extrinsic - double rms = cv::stereoCalibrate(objectPoints, stereoImagePoints_[0], stereoImagePoints_[1], - models_[0].K(), models_[0].D(), - models_[1].K(), models_[1].D(), - imageSize, R, T, E, F, - cv::TermCriteria(cv::TermCriteria::COUNT+cv::TermCriteria::EPS, 100, 1e-5), - cv::CALIB_FIX_INTRINSIC); +#if CV_MAJOR_VERSION < 3 + double rms = cv::stereoCalibrate( + objectPoints, + stereoImagePoints_[0], + stereoImagePoints_[1], + models_[0].K(), models_[0].D(), + models_[1].K(), models_[1].D(), + imageSize, R, T, E, F, + cv::TermCriteria(cv::TermCriteria::COUNT+cv::TermCriteria::EPS, 100, 1e-5), + cv::CALIB_FIX_INTRINSIC); +#else + double rms = cv::stereoCalibrate( + objectPoints, + stereoImagePoints_[0], + stereoImagePoints_[1], + models_[0].K(), models_[0].D(), + models_[1].K(), models_[1].D(), + imageSize, R, T, E, F, + cv::CALIB_FIX_INTRINSIC, + cv::TermCriteria(cv::TermCriteria::COUNT+cv::TermCriteria::EPS, 100, 1e-5)); +#endif UINFO("stereo calibration... done with RMS error=%f", rms); double err = 0; diff --git a/guilib/src/PreferencesDialog.cpp b/guilib/src/PreferencesDialog.cpp index d14b1f00..2a25d68e 100644 --- a/guilib/src/PreferencesDialog.cpp +++ b/guilib/src/PreferencesDialog.cpp @@ -70,7 +70,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "utilite/UPlot.h" -#include +#include +#if CV_MAJOR_VERSION < 3 + #include +#else + #include +#endif using namespace rtabmap; @@ -91,7 +96,16 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) : _ui = new Ui_preferencesDialog(); _ui->setupUi(this); - if(cv::gpu::getCudaEnabledDeviceCount() == 0) + bool haveCuda = false; +#if CV_MAJOR_VERSION < 3 + haveCuda = cv::gpu::getCudaEnabledDeviceCount() != 0; +#else + haveCuda = cv::cuda::getCudaEnabledDeviceCount() != 0; +#ifndef HAVE_OPENCV_CUDAFEATURES2D + haveCuda = false; +#endif +#endif + if(!haveCuda) { _ui->surf_checkBox_gpuVersion->setChecked(false); _ui->surf_checkBox_gpuVersion->setEnabled(false); @@ -133,6 +147,27 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) : _ui->comboBox_dictionary_strategy->setItemData(1, 0, Qt::UserRole - 1); _ui->reextract_nn->setItemData(1, 0, Qt::UserRole - 1); _ui->odom_bin_nn->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->reextract_type->setItemData(0, 0, Qt::UserRole - 1); + _ui->reextract_type->setItemData(1, 0, Qt::UserRole - 1); + _ui->reextract_type->setItemData(3, 0, Qt::UserRole - 1); + _ui->reextract_type->setItemData(4, 0, Qt::UserRole - 1); + _ui->reextract_type->setItemData(5, 0, Qt::UserRole - 1); + _ui->reextract_type->setItemData(6, 0, Qt::UserRole - 1); + _ui->odom_type->setItemData(0, 0, Qt::UserRole - 1); + _ui->odom_type->setItemData(1, 0, Qt::UserRole - 1); + _ui->odom_type->setItemData(3, 0, Qt::UserRole - 1); + _ui->odom_type->setItemData(4, 0, Qt::UserRole - 1); + _ui->odom_type->setItemData(5, 0, Qt::UserRole - 1); + _ui->odom_type->setItemData(6, 0, Qt::UserRole - 1); +#endif } if(!graph::G2OOptimizer::available()) { diff --git a/tools/ImagesJoiner/main.cpp b/tools/ImagesJoiner/main.cpp index 7a7ee600..68e6aa76 100644 --- a/tools/ImagesJoiner/main.cpp +++ b/tools/ImagesJoiner/main.cpp @@ -104,7 +104,7 @@ int main(int argc, char * argv[]) { CvSize sizeA = cvGetSize(imageA); CvSize sizeB = cvGetSize(imageB); - CvSize targetSize = {0}; + CvSize targetSize = cvSize(0,0); targetSize.width = sizeA.width + sizeB.width; targetSize.height = sizeA.height > sizeB.height ? sizeA.height : sizeB.height; IplImage* targetImage = cvCreateImage(targetSize, imageA->depth, imageA->nChannels); diff --git a/tools/OdometryViewer/main.cpp b/tools/OdometryViewer/main.cpp index 4c4fa8b1..5996c758 100644 --- a/tools/OdometryViewer/main.cpp +++ b/tools/OdometryViewer/main.cpp @@ -671,7 +671,7 @@ int main (int argc, char * argv[]) if(mono) { - parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kOdomPnPFlags(), uNumber2Str(cv::ITERATIVE))); + parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kOdomPnPFlags(), uNumber2Str(0))); //CV_ITERATIVE parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kOdomPnPReprojError(), "4.0")); parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kOdomIterations(), "100")); odom = new rtabmap::OdometryMono(parameters);