OpenCV的特征提取和匹配

点、线的特征提取和匹配都有两个函数:分步求,和一起求:

1. 点:

分两步:detect(), compute()

//-- 初始化
Mat descriptors_1, descriptors_2;
// used in OpenCV3
Ptr detector = ORB::create();
Ptr descriptor = ORB::create();
Ptr matcher = DescriptorMatcher::create("BruteForce-Hamming");

//-- 第一步:检测 Oriented FAST 角点位置
detector->detect(img_1, keypoints_1);
detector->detect(img_2, keypoints_2);

//-- 第二步:根据角点位置计算 BRIEF 描述子
descriptor->compute(img_1, keypoints_1, descriptors_1);
descriptor->compute(img_2, keypoints_2, descriptors_2);

一步:detectAndCompute()

cv::Mat d_srcL, d_srcR;

// 1. definitions
cv::Ptr detector = cv::ORB::create();

cv::Ptr matcher = cv::DescriptorMatcher::create(cv::NORM_L2);

// 2. detect and compute, match
detector -> detectAndCompute(d_srcL, cv::Mat(), keyPoints_1, d_descriptorsL);
detector -> detectAndCompute(d_srcR, cv::Mat(), keyPoints_2, d_descriptorsR);

2. 线:

两步:

Ptr lsd = LSDDetector::createLSDDetector();

/* detect lines */
std::vector klsd1, klsd2;
Mat lsd_descr1, lsd_descr2;
lsd->detect( imageMat1, klsd1, 2, 2, mask1 );
lsd->detect( imageMat2, klsd2, 2, 2, mask2 );

/* compute descriptors for lines from first octave */
bd->compute( imageMat1, klsd1, lsd_descr1 );
bd->compute( imageMat2, klsd2, lsd_descr2 );

一步:

Ptr bd = BinaryDescriptor::createBinaryDescriptor();

// 【1】 提取 line
/** @brief 从金字塔的所有层提取出LSD线,计算LBD描述子。同 lsd->detect + bd->compute
 * useProvidedKeyLines==false: 先提取LSD,再计算描述子
*/
(*bd)(imageMat1, cv::Mat(), keylines1, descr1, false, false);
(*bd)(imageMat2, cv::Mat(), keylines2, descr2, false, false);

你可能感兴趣的:(SLAM入门,opencv)