39 #include <opencv2/imgproc/imgproc_c.h> 40 #include <opencv2/core/version.hpp> 41 #include <opencv2/opencv_modules.hpp> 43 #if CV_MAJOR_VERSION < 3 45 #ifdef HAVE_OPENCV_GPU 46 #include <opencv2/gpu/gpu.hpp> 49 #include <opencv2/core/cuda.hpp> 52 #ifdef HAVE_OPENCV_NONFREE 53 #if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >=4 54 #include <opencv2/nonfree/gpu.hpp> 55 #include <opencv2/nonfree/features2d.hpp> 58 #ifdef HAVE_OPENCV_XFEATURES2D 59 #include <opencv2/xfeatures2d.hpp> 60 #include <opencv2/xfeatures2d/nonfree.hpp> 61 #include <opencv2/xfeatures2d/cuda.hpp> 67 std::vector<cv::KeyPoint> & keypoints,
68 const cv::Mat & depth,
77 std::vector<cv::KeyPoint> & keypoints,
78 cv::Mat & descriptors,
79 const cv::Mat & depth,
84 UASSERT(maxDepth <= 0.0f || maxDepth > minDepth);
85 if(!depth.empty() && (descriptors.empty() || descriptors.rows == (int)keypoints.size()))
87 std::vector<cv::KeyPoint> output(keypoints.size());
88 std::vector<int> indexes(keypoints.size(), 0);
90 bool isInMM = depth.type() == CV_16UC1;
91 for(
unsigned int i=0; i<keypoints.size(); ++i)
93 int u = int(keypoints[i].pt.x+0.5f);
94 int v = int(keypoints[i].pt.y+0.5f);
95 if(u >=0 && u<depth.cols && v >=0 && v<depth.rows)
97 float d = isInMM?(float)depth.at<
uint16_t>(v,u)*0.001f:depth.at<
float>(v,u);
98 if(
uIsFinite(d) && d>minDepth && (maxDepth <= 0.0f || d < maxDepth))
100 output[oi++] = keypoints[i];
108 if(!descriptors.empty() && (int)keypoints.size() != descriptors.rows)
110 if(keypoints.size() == 0)
112 descriptors = cv::Mat();
116 cv::Mat newDescriptors((
int)keypoints.size(), descriptors.cols, descriptors.type());
118 for(
unsigned int i=0; i<indexes.size(); ++i)
122 if(descriptors.type() == CV_32FC1)
124 memcpy(newDescriptors.ptr<
float>(di++), descriptors.ptr<
float>(i), descriptors.cols*
sizeof(
float));
128 memcpy(newDescriptors.ptr<
char>(di++), descriptors.ptr<
char>(i), descriptors.cols*
sizeof(
char));
132 descriptors = newDescriptors;
139 std::vector<cv::KeyPoint> & keypoints,
140 const cv::Mat & disparity,
148 std::vector<cv::KeyPoint> & keypoints,
149 cv::Mat & descriptors,
150 const cv::Mat & disparity,
153 if(!disparity.empty() && minDisparity > 0.0f && (descriptors.empty() || descriptors.rows == (int)keypoints.size()))
155 std::vector<cv::KeyPoint> output(keypoints.size());
156 std::vector<int> indexes(keypoints.size(), 0);
158 for(
unsigned int i=0; i<keypoints.size(); ++i)
160 int u = int(keypoints[i].pt.x+0.5f);
161 int v = int(keypoints[i].pt.y+0.5f);
162 if(u >=0 && u<disparity.cols && v >=0 && v<disparity.rows)
164 float d = disparity.type() == CV_16SC1?float(disparity.at<
short>(v,u))/16.0f:disparity.at<
float>(v,u);
165 if(d!=0.0
f &&
uIsFinite(d) && d >= minDisparity)
167 output[oi++] = keypoints[i];
175 if(!descriptors.empty() && (int)keypoints.size() != descriptors.rows)
177 if(keypoints.size() == 0)
179 descriptors = cv::Mat();
183 cv::Mat newDescriptors((
int)keypoints.size(), descriptors.cols, descriptors.type());
185 for(
unsigned int i=0; i<indexes.size(); ++i)
189 if(descriptors.type() == CV_32FC1)
191 memcpy(newDescriptors.ptr<
float>(di++), descriptors.ptr<
float>(i), descriptors.cols*
sizeof(
float));
195 memcpy(newDescriptors.ptr<
char>(di++), descriptors.ptr<
char>(i), descriptors.cols*
sizeof(
char));
199 descriptors = newDescriptors;
213 std::vector<cv::Point3f> keypoints3D;
214 limitKeypoints(keypoints, keypoints3D, descriptors, maxKeypoints);
217 void Feature2D::limitKeypoints(std::vector<cv::KeyPoint> & keypoints, std::vector<cv::Point3f> & keypoints3D, cv::Mat & descriptors,
int maxKeypoints)
219 UASSERT_MSG((
int)keypoints.size() == descriptors.rows || descriptors.rows == 0,
uFormat(
"keypoints=%d descriptors=%d", (
int)keypoints.size(), descriptors.rows).c_str());
220 UASSERT_MSG(keypoints.size() == keypoints3D.size() || keypoints3D.size() == 0,
uFormat(
"keypoints=%d keypoints3D=%d", (
int)keypoints.size(), (int)keypoints3D.size()).c_str());
221 if(maxKeypoints > 0 && (
int)keypoints.size() > maxKeypoints)
224 ULOGGER_DEBUG(
"too much words (%d), removing words with the hessian threshold", keypoints.size());
228 std::multimap<float, int> hessianMap;
229 for(
unsigned int i = 0; i <keypoints.size(); ++i)
232 hessianMap.insert(std::pair<float, int>(fabs(keypoints[i].response), i));
236 int removed = (int)hessianMap.size()-maxKeypoints;
237 std::multimap<float, int>::reverse_iterator iter = hessianMap.rbegin();
238 std::vector<cv::KeyPoint> kptsTmp(maxKeypoints);
239 std::vector<cv::Point3f> kpts3DTmp(maxKeypoints);
240 cv::Mat descriptorsTmp;
243 descriptorsTmp = cv::Mat(maxKeypoints, descriptors.cols, descriptors.type());
245 for(
unsigned int k=0; k < kptsTmp.size() && iter!=hessianMap.rend(); ++k, ++iter)
247 kptsTmp[k] = keypoints[iter->second];
248 if(keypoints3D.size())
250 kpts3DTmp[k] = keypoints3D[iter->second];
254 if(descriptors.type() == CV_32FC1)
256 memcpy(descriptorsTmp.ptr<
float>(k), descriptors.ptr<
float>(iter->second), descriptors.cols*
sizeof(
float));
260 memcpy(descriptorsTmp.ptr<
char>(k), descriptors.ptr<
char>(iter->second), descriptors.cols*
sizeof(
char));
264 ULOGGER_DEBUG(
"%d keypoints removed, (kept %d), minimum response=%f", removed, (
int)kptsTmp.size(), kptsTmp.size()?kptsTmp.back().response:0.0f);
267 keypoints3D = kpts3DTmp;
270 descriptors = descriptorsTmp;
277 if(maxKeypoints > 0 && (
int)keypoints.size() > maxKeypoints)
280 ULOGGER_DEBUG(
"too much words (%d), removing words with the hessian threshold", keypoints.size());
284 std::multimap<float, int> hessianMap;
285 for(
unsigned int i = 0; i <keypoints.size(); ++i)
288 hessianMap.insert(std::pair<float, int>(fabs(keypoints[i].response), i));
292 int removed = (int)hessianMap.size()-maxKeypoints;
293 std::multimap<float, int>::reverse_iterator iter = hessianMap.rbegin();
294 inliers.resize(keypoints.size(),
false);
295 float minimumHessian = 0.0f;
296 for(
int k=0; k < maxKeypoints && iter!=hessianMap.rend(); ++k, ++iter)
298 inliers[iter->second] =
true;
299 minimumHessian = iter->first;
301 ULOGGER_DEBUG(
"%d keypoints removed, (kept %d), minimum response=%f", removed, maxKeypoints, minimumHessian);
306 inliers.resize(keypoints.size(),
true);
361 ParametersMap::const_iterator iter;
362 if((iter=parameters.find(Parameters::kKpRoiRatios())) != parameters.end())
364 std::list<std::string> strValues =
uSplit(iter->second,
' ');
365 if(strValues.size() != 4)
367 ULOGGER_ERROR(
"The number of values must be 4 (roi=\"%s\")", iter->second.c_str());
371 std::vector<float> tmpValues(4);
373 for(std::list<std::string>::iterator jter = strValues.begin(); jter!=strValues.end(); ++jter)
379 if(tmpValues[0] >= 0 && tmpValues[0] < 1 && tmpValues[0] < 1.0
f-tmpValues[1] &&
380 tmpValues[1] >= 0 && tmpValues[1] < 1 && tmpValues[1] < 1.0
f-tmpValues[0] &&
381 tmpValues[2] >= 0 && tmpValues[2] < 1 && tmpValues[2] < 1.0
f-tmpValues[3] &&
382 tmpValues[3] >= 0 && tmpValues[3] < 1 && tmpValues[3] < 1.0
f-tmpValues[2])
388 ULOGGER_ERROR(
"The roi ratios are not valid (roi=\"%s\")", iter->second.c_str());
395 if((iter=parameters.find(Parameters::kStereoOpticalFlow())) != parameters.end())
407 int type = Parameters::defaultKpDetectorStrategy();
413 #ifndef RTABMAP_NONFREE 416 #if CV_MAJOR_VERSION < 3 417 UWARN(
"SURF and SIFT features cannot be used because OpenCV was not built with nonfree module. ORB is used instead.");
419 UWARN(
"SURF and SIFT features cannot be used because OpenCV was not built with xfeatures2d module. ORB is used instead.");
423 #if CV_MAJOR_VERSION == 3 429 UWARN(
"BRIEF and FREAK features cannot be used because OpenCV was not built with xfeatures2d module. ORB is used instead.");
435 #if CV_MAJOR_VERSION < 3 438 #ifdef RTABMAP_NONFREE 439 UWARN(
"KAZE detector/descriptor can be used only with OpenCV3. SURF is used instead.");
442 UWARN(
"KAZE detector/descriptor can be used only with OpenCV3. ORB is used instead.");
452 feature2D =
new SURF(parameters);
455 feature2D =
new SIFT(parameters);
458 feature2D =
new ORB(parameters);
473 feature2D =
new GFTT_ORB(parameters);
476 feature2D =
new BRISK(parameters);
479 feature2D =
new KAZE(parameters);
481 #ifdef RTABMAP_NONFREE 483 feature2D =
new SURF(parameters);
488 feature2D =
new ORB(parameters);
500 UASSERT(image.type() == CV_8UC1);
505 if(maskIn.type()==CV_16UC1 || maskIn.type() == CV_32FC1)
507 mask = cv::Mat::zeros(maskIn.rows, maskIn.cols, CV_8UC1);
508 for(
int i=0; i<(int)mask.total(); ++i)
511 if(maskIn.type()==CV_16UC1)
513 if(((
unsigned short*)maskIn.data)[i] > 0 &&
516 value = float(((
unsigned short*)maskIn.data)[i])*0.001f;
521 value = ((
float*)maskIn.data)[i];
527 ((
unsigned char*)mask.data)[i] = 255;
531 else if(maskIn.type()==CV_8UC1)
538 UERROR(
"Wrong mask type (%d)! Should be 8UC1, 16UC1 or 32FC1.", maskIn.type());
542 UASSERT(mask.empty() || (mask.cols == image.cols && mask.rows == image.rows));
544 std::vector<cv::KeyPoint> keypoints;
547 if(!(globalRoi.width && globalRoi.height))
549 globalRoi = cv::Rect(0,0,image.cols, image.rows);
553 int rowSize = globalRoi.height /
gridRows_;
554 int colSize = globalRoi.width /
gridCols_;
559 cv::Rect roi(globalRoi.x + j*colSize, globalRoi.y + i*rowSize, colSize, rowSize);
560 std::vector<cv::KeyPoint> sub_keypoints;
566 for(std::vector<cv::KeyPoint>::iterator iter=sub_keypoints.begin(); iter!=sub_keypoints.end(); ++iter)
572 keypoints.insert( keypoints.end(), sub_keypoints.begin(), sub_keypoints.end() );
575 UDEBUG(
"Keypoints extraction time = %f s, keypoints extracted = %d (mask empty=%d)", timer.
ticks(), keypoints.size(), mask.empty()?1:0);
579 std::vector<cv::Point2f> corners;
580 cv::KeyPoint::convert(keypoints, corners);
581 cv::cornerSubPix( image, corners,
586 for(
unsigned int i=0;i<corners.size(); ++i)
588 keypoints[i].pt = corners[i];
597 const cv::Mat & image,
598 std::vector<cv::KeyPoint> & keypoints)
const 604 UASSERT(image.type() == CV_8UC1);
606 UASSERT_MSG(descriptors.rows == (
int)keypoints.size(),
uFormat(
"descriptors=%d, keypoints=%d", descriptors.rows, (
int)keypoints.size()).c_str());
607 UDEBUG(
"Descriptors extracted = %d, remaining kpts=%d", descriptors.rows, (
int)keypoints.size());
614 const std::vector<cv::KeyPoint> & keypoints)
const 616 std::vector<cv::Point3f> keypoints3D;
626 cv::cvtColor(data.
imageRaw(), imageMono, cv::COLOR_BGR2GRAY);
633 std::vector<cv::Point2f> leftCorners;
634 cv::KeyPoint::convert(keypoints, leftCorners);
635 std::vector<unsigned char> status;
637 std::vector<cv::Point2f> rightCorners;
670 hessianThreshold_(
Parameters::defaultSURFHessianThreshold()),
672 nOctaveLayers_(
Parameters::defaultSURFOctaveLayers()),
675 gpuKeypointsRatio_(
Parameters::defaultSURFGpuKeypointsRatio()),
676 gpuVersion_(
Parameters::defaultSURFGpuVersion())
697 #ifdef RTABMAP_NONFREE 698 #if CV_MAJOR_VERSION < 3 699 if(
gpuVersion_ && cv::gpu::getCudaEnabledDeviceCount() == 0)
701 UWARN(
"GPU version of SURF not available! Using CPU version instead...");
705 if(
gpuVersion_ && cv::cuda::getCudaEnabledDeviceCount() == 0)
707 UWARN(
"GPU version of SURF not available! Using CPU version instead...");
717 #if CV_MAJOR_VERSION < 3 724 UWARN(
"RTAB-Map is not built with OpenCV nonfree module so SURF cannot be used!");
730 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
731 std::vector<cv::KeyPoint> keypoints;
733 #ifdef RTABMAP_NONFREE 734 cv::Mat imgRoi(image, roi);
738 maskRoi = cv::Mat(mask, roi);
742 #if CV_MAJOR_VERSION < 3 743 cv::gpu::GpuMat imgGpu(imgRoi);
744 cv::gpu::GpuMat maskGpu(maskRoi);
745 (*
_gpuSurf.obj)(imgGpu, maskGpu, keypoints);
747 cv::cuda::GpuMat imgGpu(imgRoi);
748 cv::cuda::GpuMat maskGpu(maskRoi);
749 (*
_gpuSurf.get())(imgGpu, maskGpu, keypoints);
754 _surf->detect(imgRoi, keypoints, maskRoi);
757 UWARN(
"RTAB-Map is not built with OpenCV nonfree module so SURF cannot be used!");
764 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
766 #ifdef RTABMAP_NONFREE 769 #if CV_MAJOR_VERSION < 3 770 cv::gpu::GpuMat imgGpu(image);
771 cv::gpu::GpuMat descriptorsGPU;
772 (*
_gpuSurf.obj)(imgGpu, cv::gpu::GpuMat(), keypoints, descriptorsGPU,
true);
774 cv::cuda::GpuMat imgGpu(image);
775 cv::cuda::GpuMat descriptorsGPU;
776 (*
_gpuSurf.get())(imgGpu, cv::cuda::GpuMat(), keypoints, descriptorsGPU,
true);
780 if (descriptorsGPU.empty())
781 descriptors = cv::Mat();
784 UASSERT(descriptorsGPU.type() == CV_32F);
785 descriptors = cv::Mat(descriptorsGPU.size(), CV_32F);
786 descriptorsGPU.download(descriptors);
791 _surf->compute(image, keypoints, descriptors);
794 UWARN(
"RTAB-Map is not built with OpenCV nonfree module so SURF cannot be used!");
805 contrastThreshold_(
Parameters::defaultSIFTContrastThreshold()),
806 edgeThreshold_(
Parameters::defaultSIFTEdgeThreshold()),
825 #ifdef RTABMAP_NONFREE 826 #if CV_MAJOR_VERSION < 3 832 UWARN(
"RTAB-Map is not built with OpenCV nonfree module so SIFT cannot be used!");
838 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
839 std::vector<cv::KeyPoint> keypoints;
840 #ifdef RTABMAP_NONFREE 841 cv::Mat imgRoi(image, roi);
845 maskRoi = cv::Mat(mask, roi);
847 _sift->detect(imgRoi, keypoints, maskRoi);
849 UWARN(
"RTAB-Map is not built with OpenCV nonfree module so SIFT cannot be used!");
856 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
858 #ifdef RTABMAP_NONFREE 859 _sift->compute(image, keypoints, descriptors);
861 UWARN(
"RTAB-Map is not built with OpenCV nonfree module so SIFT cannot be used!");
870 scaleFactor_(
Parameters::defaultORBScaleFactor()),
873 firstLevel_(
Parameters::defaultORBFirstLevel()),
875 scoreType_(
Parameters::defaultORBScoreType()),
876 patchSize_(
Parameters::defaultORBPatchSize()),
878 fastThreshold_(
Parameters::defaultFASTThreshold()),
879 nonmaxSuppresion_(
Parameters::defaultFASTNonmaxSuppression())
904 #if CV_MAJOR_VERSION < 3 905 #ifdef HAVE_OPENCV_GPU 906 if(
gpu_ && cv::gpu::getCudaEnabledDeviceCount() == 0)
908 UWARN(
"GPU version of ORB not available! Using CPU version instead...");
914 UWARN(
"GPU version of ORB not available (OpenCV not built with gpu/cuda module)! Using CPU version instead...");
919 #ifndef HAVE_OPENCV_CUDAFEATURES2D 922 UWARN(
"GPU version of ORB not available (OpenCV cudafeatures2d module)! Using CPU version instead...");
926 if(
gpu_ && cv::cuda::getCudaEnabledDeviceCount() == 0)
928 UWARN(
"GPU version of ORB not available (no GPU found)! Using CPU version instead...");
934 #if CV_MAJOR_VERSION < 3 935 #ifdef HAVE_OPENCV_GPU 939 UFATAL(
"not supposed to be here");
942 #ifdef HAVE_OPENCV_CUDAFEATURES2D 949 #if CV_MAJOR_VERSION < 3 959 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
960 std::vector<cv::KeyPoint> keypoints;
961 cv::Mat imgRoi(image, roi);
965 maskRoi = cv::Mat(mask, roi);
970 #if CV_MAJOR_VERSION < 3 971 #ifdef HAVE_OPENCV_GPU 972 cv::gpu::GpuMat imgGpu(imgRoi);
973 cv::gpu::GpuMat maskGpu(maskRoi);
974 (*
_gpuOrb.obj)(imgGpu, maskGpu, keypoints);
976 UERROR(
"Cannot use ORBGPU because OpenCV is not built with gpu module.");
979 #ifdef HAVE_OPENCV_CUDAFEATURES2D 980 cv::cuda::GpuMat d_image(imgRoi);
981 cv::cuda::GpuMat d_mask(maskRoi);
983 _gpuOrb->detectAndCompute(d_image, d_mask, keypoints, cv::cuda::GpuMat(),
false);
984 }
catch (cv::Exception&
e) {
985 const char* err_msg = e.what();
986 UWARN(
"OpenCV exception caught: %s", err_msg);
993 _orb->detect(imgRoi, keypoints, maskRoi);
1001 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1002 cv::Mat descriptors;
1010 #if CV_MAJOR_VERSION < 3 1011 #ifdef HAVE_OPENCV_GPU 1012 cv::gpu::GpuMat imgGpu(image);
1013 cv::gpu::GpuMat descriptorsGPU;
1014 (*
_gpuOrb.obj)(imgGpu, cv::gpu::GpuMat(), keypoints, descriptorsGPU);
1016 if (descriptorsGPU.empty())
1017 descriptors = cv::Mat();
1020 UASSERT(descriptorsGPU.type() == CV_32F);
1021 descriptors = cv::Mat(descriptorsGPU.size(), CV_32F);
1022 descriptorsGPU.download(descriptors);
1025 UERROR(
"GPU version of ORB not available (OpenCV not built with gpu/cuda module)! Using CPU version instead...");
1028 #ifdef HAVE_OPENCV_CUDAFEATURES2D 1029 cv::cuda::GpuMat d_image(image);
1030 cv::cuda::GpuMat d_descriptors;
1032 _gpuOrb->detectAndCompute(d_image, cv::cuda::GpuMat(), keypoints, d_descriptors,
true);
1033 }
catch (cv::Exception&
e) {
1034 const char* err_msg = e.what();
1035 UWARN(
"OpenCV exception caught: %s", err_msg);
1038 if (d_descriptors.empty())
1039 descriptors = cv::Mat();
1042 UASSERT(d_descriptors.type() == CV_32F || d_descriptors.type() == CV_8U);
1043 d_descriptors.download(descriptors);
1050 _orb->compute(image, keypoints, descriptors);
1060 threshold_(
Parameters::defaultFASTThreshold()),
1061 nonmaxSuppression_(
Parameters::defaultFASTNonmaxSuppression()),
1063 gpuKeypointsRatio_(
Parameters::defaultFASTGpuKeypointsRatio()),
1064 minThreshold_(
Parameters::defaultFASTMinThreshold()),
1065 maxThreshold_(
Parameters::defaultFASTMaxThreshold()),
1093 #if CV_MAJOR_VERSION < 3 1094 #ifdef HAVE_OPENCV_GPU 1095 if(
gpu_ && cv::gpu::getCudaEnabledDeviceCount() == 0)
1097 UWARN(
"GPU version of FAST not available! Using CPU version instead...");
1103 UWARN(
"GPU version of FAST not available (OpenCV not built with gpu/cuda module)! Using CPU version instead...");
1108 #ifdef HAVE_OPENCV_CUDAFEATURES2D 1109 if(
gpu_ && cv::cuda::getCudaEnabledDeviceCount() == 0)
1111 UWARN(
"GPU version of FAST not available! Using CPU version instead...");
1117 UWARN(
"GPU version of FAST not available (OpenCV cudafeatures2d module)! Using CPU version instead...");
1124 #if CV_MAJOR_VERSION < 3 1125 #ifdef HAVE_OPENCV_GPU 1128 UFATAL(
"not supposed to be here!");
1131 #ifdef HAVE_OPENCV_CUDAFEATURES2D 1132 UFATAL(
"not implemented");
1138 #if CV_MAJOR_VERSION < 3 1149 UWARN(
"Parameter \"%s\" is set (value=%d) but not \"%s\"! Grid adaptor will not be added.",
1150 Parameters::kFASTGridRows().c_str(),
gridRows_, Parameters::kFASTGridCols().c_str());
1154 UWARN(
"Parameter \"%s\" is set (value=%d) but not \"%s\"! Grid adaptor will not be added.",
1155 Parameters::kFASTGridCols().c_str(),
gridCols_, Parameters::kFASTGridRows().c_str());
1167 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1168 std::vector<cv::KeyPoint> keypoints;
1169 cv::Mat imgRoi(image, roi);
1173 maskRoi = cv::Mat(mask, roi);
1177 #if CV_MAJOR_VERSION < 3 1178 #ifdef HAVE_OPENCV_GPU 1179 cv::gpu::GpuMat imgGpu(imgRoi);
1180 cv::gpu::GpuMat maskGpu(maskRoi);
1181 (*
_gpuFast.obj)(imgGpu, maskGpu, keypoints);
1183 UERROR(
"Cannot use FAST GPU because OpenCV is not built with gpu module.");
1186 #ifdef HAVE_OPENCV_CUDAFEATURES2D 1187 UFATAL(
"not implemented");
1193 _fast->detect(imgRoi, keypoints, maskRoi);
1217 #if CV_MAJOR_VERSION < 3 1220 #ifdef HAVE_OPENCV_XFEATURES2D 1223 UWARN(
"RTAB-Map is not built with OpenCV xfeatures2d module so Brief cannot be used!");
1230 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1231 cv::Mat descriptors;
1232 #if CV_MAJOR_VERSION < 3 1233 _brief->compute(image, keypoints, descriptors);
1235 #ifdef HAVE_OPENCV_XFEATURES2D 1236 _brief->compute(image, keypoints, descriptors);
1238 UWARN(
"RTAB-Map is not built with OpenCV xfeatures2d module so Brief cannot be used!");
1249 orientationNormalized_(
Parameters::defaultFREAKOrientationNormalized()),
1250 scaleNormalized_(
Parameters::defaultFREAKScaleNormalized()),
1251 patternScale_(
Parameters::defaultFREAKPatternScale()),
1252 nOctaves_(
Parameters::defaultFREAKNOctaves())
1270 #if CV_MAJOR_VERSION < 3 1273 #ifdef HAVE_OPENCV_XFEATURES2D 1276 UWARN(
"RTAB-Map is not built with OpenCV xfeatures2d module so Freak cannot be used!");
1283 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1284 cv::Mat descriptors;
1285 #if CV_MAJOR_VERSION < 3 1286 _freak->compute(image, keypoints, descriptors);
1288 #ifdef HAVE_OPENCV_XFEATURES2D 1289 _freak->compute(image, keypoints, descriptors);
1291 UWARN(
"RTAB-Map is not built with OpenCV xfeatures2d module so Freak cannot be used!");
1301 _qualityLevel(
Parameters::defaultGFTTQualityLevel()),
1302 _minDistance(
Parameters::defaultGFTTMinDistance()),
1303 _blockSize(
Parameters::defaultGFTTBlockSize()),
1304 _useHarrisDetector(
Parameters::defaultGFTTUseHarrisDetector()),
1324 #if CV_MAJOR_VERSION < 3 1333 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1334 std::vector<cv::KeyPoint> keypoints;
1335 cv::Mat imgRoi(image, roi);
1339 maskRoi = cv::Mat(mask, roi);
1341 _gftt->detect(imgRoi, keypoints, maskRoi);
1364 #if CV_MAJOR_VERSION < 3 1367 #ifdef HAVE_OPENCV_XFEATURES2D 1370 UWARN(
"RTAB-Map is not built with OpenCV xfeatures2d module so Brief cannot be used!");
1377 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1378 cv::Mat descriptors;
1379 #if CV_MAJOR_VERSION < 3 1380 _brief->compute(image, keypoints, descriptors);
1382 #ifdef HAVE_OPENCV_XFEATURES2D 1383 _brief->compute(image, keypoints, descriptors);
1385 UWARN(
"RTAB-Map is not built with OpenCV xfeatures2d module so Brief cannot be used!");
1396 orientationNormalized_(
Parameters::defaultFREAKOrientationNormalized()),
1397 scaleNormalized_(
Parameters::defaultFREAKScaleNormalized()),
1398 patternScale_(
Parameters::defaultFREAKPatternScale()),
1399 nOctaves_(
Parameters::defaultFREAKNOctaves())
1417 #if CV_MAJOR_VERSION < 3 1420 #ifdef HAVE_OPENCV_XFEATURES2D 1423 UWARN(
"RTAB-Map is not built with OpenCV xfeatures2d module so Freak cannot be used!");
1430 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1431 cv::Mat descriptors;
1432 #if CV_MAJOR_VERSION < 3 1433 _freak->compute(image, keypoints, descriptors);
1435 #ifdef HAVE_OPENCV_XFEATURES2D 1436 _freak->compute(image, keypoints, descriptors);
1438 UWARN(
"RTAB-Map is not built with OpenCV xfeatures2d module so Freak cannot be used!");
1466 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1476 patternScale_(
Parameters::defaultBRISKPatternScale())
1493 #if CV_MAJOR_VERSION < 3 1502 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1503 std::vector<cv::KeyPoint> keypoints;
1504 cv::Mat imgRoi(image, roi);
1508 maskRoi = cv::Mat(mask, roi);
1510 brisk_->detect(imgRoi, keypoints, maskRoi);
1516 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1517 cv::Mat descriptors;
1518 brisk_->compute(image, keypoints, descriptors);
1526 extended_(
Parameters::defaultKAZEExtended()),
1528 threshold_(
Parameters::defaultKAZEThreshold()),
1529 nOctaves_(
Parameters::defaultKAZENOctaves()),
1530 nOctaveLayers_(
Parameters::defaultKAZENOctaveLayers()),
1531 diffusivity_(
Parameters::defaultKAZEDiffusivity())
1551 #if CV_MAJOR_VERSION > 2 1554 UWARN(
"RTAB-Map is not built with OpenCV3 so Kaze feature cannot be used!");
1560 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1561 std::vector<cv::KeyPoint> keypoints;
1562 #if CV_MAJOR_VERSION > 2 1563 cv::Mat imgRoi(image, roi);
1567 maskRoi = cv::Mat(mask, roi);
1569 kaze_->detect(imgRoi, keypoints, maskRoi);
1571 UWARN(
"RTAB-Map is not built with OpenCV3 so Kaze feature cannot be used!");
1578 UASSERT(!image.empty() && image.channels() == 1 && image.depth() == CV_8U);
1579 cv::Mat descriptors;
1580 #if CV_MAJOR_VERSION > 2 1581 kaze_->compute(image, keypoints, descriptors);
1583 UWARN(
"RTAB-Map is not built with OpenCV3 so Kaze feature cannot be used!");
virtual std::vector< cv::KeyPoint > generateKeypointsImpl(const cv::Mat &image, const cv::Rect &roi, const cv::Mat &mask=cv::Mat()) const
GLM_FUNC_DECL genIType mask(genIType const &count)
static bool parse(const ParametersMap ¶meters, const std::string &key, bool &value)
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const =0
virtual void parseParameters(const ParametersMap ¶meters)
static void limitKeypoints(std::vector< cv::KeyPoint > &keypoints, int maxKeypoints)
virtual std::vector< cv::KeyPoint > generateKeypointsImpl(const cv::Mat &image, const cv::Rect &roi, const cv::Mat &mask=cv::Mat()) const
std::vector< cv::Point3f > generateKeypoints3D(const SensorData &data, const std::vector< cv::KeyPoint > &keypoints) const
double gpuKeypointsRatio_
FAST_BRIEF(const ParametersMap ¶meters=ParametersMap())
virtual void parseParameters(const ParametersMap ¶meters)
cv::Mat generateDescriptors(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
virtual void parseParameters(const ParametersMap ¶meters)
cv::Ptr< CV_FREAK > _freak
GFTT_FREAK(const ParametersMap ¶meters=ParametersMap())
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
virtual void parseParameters(const ParametersMap ¶meters)
virtual void parseParameters(const ParametersMap ¶meters)
cv::Ptr< CV_FREAK > _freak
std::vector< cv::KeyPoint > generateKeypoints(const cv::Mat &image, const cv::Mat &mask=cv::Mat()) const
cv::BriefDescriptorExtractor CV_BRIEF
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
GLM_FUNC_DECL genType e()
float UTILITE_EXP uStr2Float(const std::string &str)
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
virtual std::vector< cv::KeyPoint > generateKeypointsImpl(const cv::Mat &image, const cv::Rect &roi, const cv::Mat &mask=cv::Mat()) const
std::map< std::string, std::string > ParametersMap
double contrastThreshold_
virtual std::vector< cv::KeyPoint > generateKeypointsImpl(const cv::Mat &image, const cv::Rect &roi, const cv::Mat &mask=cv::Mat()) const
std::vector< float > _roiRatios
Basic mathematics functions.
cv::Ptr< CV_BRISK > brisk_
cv::Ptr< CV_ORB_GPU > _gpuOrb
Some conversion functions.
cv::FastFeatureDetector CV_FAST
const cv::Mat & imageRaw() const
virtual std::vector< cv::KeyPoint > generateKeypointsImpl(const cv::Mat &image, const cv::Rect &roi, const cv::Mat &mask=cv::Mat()) const
Feature2D(const ParametersMap ¶meters=ParametersMap())
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
int getMaxFeatures() const
std::list< std::string > uSplit(const std::string &str, char separator= ' ')
bool uIsFinite(const T &value)
cv::Ptr< CV_FAST_GPU > _gpuFast
#define UASSERT(condition)
virtual void parseParameters(const ParametersMap ¶meters)
Wrappers of STL for convenient functions.
static void filterKeypointsByDisparity(std::vector< cv::KeyPoint > &keypoints, const cv::Mat &disparity, float minDisparity)
virtual std::vector< cv::Point2f > computeCorrespondences(const cv::Mat &leftImage, const cv::Mat &rightImage, const std::vector< cv::Point2f > &leftCorners, std::vector< unsigned char > &status) const
bool isValidForProjection() const
BRISK(const ParametersMap ¶meters=ParametersMap())
static Feature2D * create(const ParametersMap ¶meters=ParametersMap())
#define ULOGGER_DEBUG(...)
virtual void parseParameters(const ParametersMap ¶meters)
#define UASSERT_MSG(condition, msg_str)
bool orientationNormalized_
cv::Rect RTABMAP_EXP computeRoi(const cv::Mat &image, const std::string &roiRatios)
FAST(const ParametersMap ¶meters=ParametersMap())
virtual void parseParameters(const ParametersMap ¶meters)
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
virtual void parseParameters(const ParametersMap ¶meters)
static void filterKeypointsByDepth(std::vector< cv::KeyPoint > &keypoints, const cv::Mat &depth, float minDepth, float maxDepth)
KAZE(const ParametersMap ¶meters=ParametersMap())
const cv::Mat & depthOrRightRaw() const
cv::gpu::SURF_GPU CV_SURF_GPU
virtual std::vector< cv::KeyPoint > generateKeypointsImpl(const cv::Mat &image, const cv::Rect &roi, const cv::Mat &mask=cv::Mat()) const
static cv::Rect computeRoi(const cv::Mat &image, const std::string &roiRatios)
virtual std::vector< cv::KeyPoint > generateKeypointsImpl(const cv::Mat &image, const cv::Rect &roi, const cv::Mat &mask=cv::Mat()) const =0
SIFT(const ParametersMap ¶meters=ParametersMap())
static Stereo * create(const ParametersMap ¶meters=ParametersMap())
cv::Ptr< CV_BRIEF > _brief
const std::vector< CameraModel > & cameraModels() const
FAST_FREAK(const ParametersMap ¶meters=ParametersMap())
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
virtual void parseParameters(const ParametersMap ¶meters)
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
ORB(const ParametersMap ¶meters=ParametersMap())
cv::Ptr< CV_BRIEF > _brief
virtual void parseParameters(const ParametersMap ¶meters)
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
virtual void parseParameters(const ParametersMap ¶meters)
GFTT(const ParametersMap ¶meters=ParametersMap())
ULogger class and convenient macros.
const StereoCameraModel & stereoCameraModel() const
SURF(const ParametersMap ¶meters=ParametersMap())
virtual void parseParameters(const ParametersMap ¶meters)
virtual cv::Mat generateDescriptorsImpl(const cv::Mat &image, std::vector< cv::KeyPoint > &keypoints) const
GFTT_BRIEF(const ParametersMap ¶meters=ParametersMap())
virtual std::vector< cv::KeyPoint > generateKeypointsImpl(const cv::Mat &image, const cv::Rect &roi, const cv::Mat &mask=cv::Mat()) const
cv::gpu::ORB_GPU CV_ORB_GPU
GFTT_ORB(const ParametersMap ¶meters=ParametersMap())
bool orientationNormalized_
cv::gpu::FAST_GPU CV_FAST_GPU
#define ULOGGER_ERROR(...)
std::vector< cv::Point3f > RTABMAP_EXP generateKeypoints3DDepth(const std::vector< cv::KeyPoint > &keypoints, const cv::Mat &depth, const CameraModel &cameraModel, float minDepth=0, float maxDepth=0)
cv::Ptr< cv::FeatureDetector > _fast
std::string UTILITE_EXP uFormat(const char *fmt,...)
ParametersMap parameters_
void uInsert(std::map< K, V > &map, const std::pair< K, V > &pair)
virtual void parseParameters(const ParametersMap ¶meters)
std::vector< cv::Point3f > RTABMAP_EXP generateKeypoints3DStereo(const std::vector< cv::Point2f > &leftCorners, const std::vector< cv::Point2f > &rightCorners, const StereoCameraModel &model, const std::vector< unsigned char > &mask=std::vector< unsigned char >(), float minDepth=0, float maxDepth=0)
cv::Ptr< CV_SURF_GPU > _gpuSurf