一起做RGB-D SLAM (3)


第三講 特征提取與配准


 2016.11 更新

  • 把原文的SIFT替換成了ORB,這樣你可以在沒有nonfree模塊下使用本程序了。
  • OpenCV可以使用 apt-get install libopencv-dev ,一樣能成功。
  • 因為換成了ORB,所以調整了good match的閾值,並且匹配時需要使用 Brute Force match。
  • 請以現在的github上源碼為准。

 

  師兄:同學們大家好,又到我們每周一次的“一起做RGB-D SLAM”時間啦!大家還記得上周我們講了什么東西嗎?

  小蘿卜:等一下師兄!我們的博客什么時候變成每周一更了?

  師兄:這個,這不是因為終於到暑假了,我可以專門搞學術了嘛。

  小蘿卜:胡說!前兩天我還看到你在超市開挖掘機來着!

  師兄:這事你就別提了啊……

  小蘿卜:我還有照片為證呢!

 

 

 

 

 

 

 

 

 

 

  師兄:你能不能別提這個事了啊……我們趕緊開始講課吧。

  小蘿卜:師兄,那可是兒童專區啊,您可是個博士,自重啊!


 上講回顧

  在上一講中,我們介紹了如何把2D圖像坐標轉換為3D空間坐標。然后,利用推導的數學公式,實現了把圖像轉化為點雲的程序。在上一講的末尾,我們給出了一道作業題,希望讀者去把這兩件事做成一個函數庫,以供將來調用。不知道大家回去之后做了沒有呢?

  小蘿卜:讀者這么勤奮肯定已經做好了啦!

  師兄:嗯,所以呢,這一講里面我們就要用到上面兩個函數了。在講解本講的內容之前,先介紹一下我們是如何封裝上節課代碼的。在 代碼根目錄/include 下,我們新建了一個 slamBase.h 文件,存放上一講以及以后講到的各種函數:

  include/slamBase.h:

 1 /*************************************************************************
 2     > File Name: rgbd-slam-tutorial-gx/part III/code/include/slamBase.h
 3     > Author: xiang gao
 4     > Mail: gaoxiang12@mails.tsinghua.edu.cn
 5     > Created Time: 2015年07月18日 星期六 15時14分22秒
 6     > 說明:rgbd-slam教程所用到的基本函數(C風格)
 7  ************************************************************************/
 8 # pragma once
 9 
10 // 各種頭文件 
11 // C++標准庫
12 #include <fstream>
13 #include <vector>
14 using namespace std;
15 
16 // OpenCV
17 #include <opencv2/core/core.hpp>
18 #include <opencv2/highgui/highgui.hpp>
19 
20 //PCL
21 #include <pcl/io/pcd_io.h>
22 #include <pcl/point_types.h>
23 
24 // 類型定義
25 typedef pcl::PointXYZRGBA PointT;
26 typedef pcl::PointCloud<PointT> PointCloud;
27 
28 // 相機內參結構
29 struct CAMERA_INTRINSIC_PARAMETERS 
30 { 
31     double cx, cy, fx, fy, scale;
32 };
33 
34 // 函數接口
35 // image2PonitCloud 將rgb圖轉換為點雲
36 PointCloud::Ptr image2PointCloud( cv::Mat& rgb, cv::Mat& depth, CAMERA_INTRINSIC_PARAMETERS& camera );
37 
38 // point2dTo3d 將單個點從圖像坐標轉換為空間坐標
39 // input: 3維點Point3f (u,v,d)
40 cv::Point3f point2dTo3d( cv::Point3f& point, CAMERA_INTRINSIC_PARAMETERS& camera );

  可以看到,我們把相機參數封裝成了一個結構體,另外還聲明了 image2PointCloud 和 point2dTo3d 兩個函數。然后,在 src/ 目錄下新建 slamBase.cpp 文件:

  src/slamBase.cpp

 1 /*************************************************************************
 2     > File Name: src/slamBase.cpp
 3     > Author: xiang gao
 4     > Mail: gaoxiang12@mails.tsinghua.edu.cn
 5     > Implementation of slamBase.h
 6     > Created Time: 2015年07月18日 星期六 15時31分49秒
 7  ************************************************************************/
 8 
 9 #include "slamBase.h"
10 
11 PointCloud::Ptr image2PointCloud( cv::Mat& rgb, cv::Mat& depth, CAMERA_INTRINSIC_PARAMETERS& camera )
12 {
13     PointCloud::Ptr cloud ( new PointCloud );
14 
15     for (int m = 0; m < depth.rows; m++)
16         for (int n=0; n < depth.cols; n++)
17         {
18             // 獲取深度圖中(m,n)處的值
19             ushort d = depth.ptr<ushort>(m)[n];
20             // d 可能沒有值,若如此,跳過此點
21             if (d == 0)
22                 continue;
23             // d 存在值,則向點雲增加一個點
24             PointT p;
25 
26             // 計算這個點的空間坐標
27             p.z = double(d) / camera.scale;
28             p.x = (n - camera.cx) * p.z / camera.fx;
29             p.y = (m - camera.cy) * p.z / camera.fy;
30             
31             // 從rgb圖像中獲取它的顏色
32             // rgb是三通道的BGR格式圖,所以按下面的順序獲取顏色
33             p.b = rgb.ptr<uchar>(m)[n*3];
34             p.g = rgb.ptr<uchar>(m)[n*3+1];
35             p.r = rgb.ptr<uchar>(m)[n*3+2];
36 
37             // 把p加入到點雲中
38             cloud->points.push_back( p );
39         }
40     // 設置並保存點雲
41     cloud->height = 1;
42     cloud->width = cloud->points.size();
43     cloud->is_dense = false;
44 
45     return cloud;
46 }
47 
48 cv::Point3f point2dTo3d( cv::Point3f& point, CAMERA_INTRINSIC_PARAMETERS& camera )
49 {
50     cv::Point3f p; // 3D 點
51     p.z = double( point.z ) / camera.scale;
52     p.x = ( point.x - camera.cx) * p.z / camera.fx;
53     p.y = ( point.y - camera.cy) * p.z / camera.fy;
54     return p;
55 }

  最后,在 src/CMakeLists.txt 中加入以下幾行,將 slamBase.cpp 編譯成一個庫,供將來調用:

ADD_LIBRARY( slambase slamBase.cpp )
TARGET_LINK_LIBRARIES( slambase
    ${OpenCV_LIBS} 
    ${PCL_LIBRARIES} )

  這兩句話是說,把slamBase.cpp編譯成 slamBase 庫,並把該庫里調到的OpenCV和PCL的部分,和相應的庫鏈接起來。是不是感覺代碼更有條理了呢?今后,我們會在每一講里介紹新的內容,並把實現的代碼封裝里這個slamBase庫中。


圖像配准 數學部分

  SLAM是由“定位”(Localization)和“建圖”(Mapping)兩部分構成的。現在來看定位問題。要求解機器人的運動,首先要解決這樣一個問題:給定了兩個圖像,如何知道圖像的運動關系呢?

  這個問題可以用基於特征的方法(feature-based)或直接的方法(direct method)來解。雖說直接法已經有了一定的發展,但目前主流的方法還是基於特征點的方式。在后者的方法中,首先你需要知道圖像里的“特征”,以及這些特征的一一對應關系。

  假設我們有兩個幀:$F_1$和$F_2$. 並且,我們獲得了兩組一一對應的特征點:$$P=\{p_1, p_2, \ldots, p_N \} \in F_1 $$ $$Q=\{ q_1, q_2, \ldots, q_N \} \in F_2 $$. 其中$p$和$q$都是$R^3$中的點。

  我們的目的是求出一個旋轉矩陣$R$和位移矢量$t$,使得:$$ \forall i, p_i = R q_i + t $$.

  然而實際當中由於誤差的存在,等號基本是不可能的。所以我們通過最小化一個誤差來求解$R,t$:

  $$\min\limits_{R,t} \sum\limits_{i=1}^{N} \| p_i - (R q_i + t) \|_2 $$

  這個問題可以用經典的ICP算法求解。其核心是奇異值分解(SVD)。我們將調用OpenCV中的函數求解此問題,所以在此就不細講ICP的具體步驟了。有興趣的讀者可以參閱1987年PAMI上的一篇文章,也是最原始的ICP方法:Least-squares fitting of two 3-D point sets。

  那么從這個數學問題上來講,我們的關鍵就是要獲取一組一一對應的空間點,這可以通過圖像的特征匹配來完成。  

提示:由於OpenCV中沒有提供ICP,我們在實現中使用PnP進行求解。


圖像配准 編程實現

  本節中,我們要匹配兩對圖像,並且計算它們的位移關系。它們分別是rgb1,png, rgb2.png, depth1.png, depth2.png. 人眼可以直觀地看到第二個圖是向左轉動了一些。

 

 

 

 

 

 

 

 

 

 

   照例,我們先給出完整的程序代碼。讀者可以先把代碼瀏覽一遍,我們再加以詳細的解釋。因為本節的代碼比較長,我把它折疊起來,否則排版就太長了。

  1 /*************************************************************************
  2     > File Name: detectFeatures.cpp
  3     > Author: xiang gao
  4     > Mail: gaoxiang12@mails.tsinghua.edu.cn
  5     > 特征提取與匹配
  6     > Created Time: 2015年07月18日 星期六 16時00分21秒
  7  ************************************************************************/
  8 
  9 #include<iostream>
 10 #include "slamBase.h"
 11 using namespace std;
 12 
 13 // OpenCV 特征檢測模塊
 14 #include <opencv2/features2d/features2d.hpp>
 15 #include <opencv2/nonfree/nonfree.hpp>
 16 #include <opencv2/calib3d/calib3d.hpp>
 17 
 18 int main( int argc, char** argv )
 19 {
 20     // 聲明並從data文件夾里讀取兩個rgb與深度圖
 21     cv::Mat rgb1 = cv::imread( "./data/rgb1.png");
 22     cv::Mat rgb2 = cv::imread( "./data/rgb2.png");
 23     cv::Mat depth1 = cv::imread( "./data/depth1.png", -1);
 24     cv::Mat depth2 = cv::imread( "./data/depth2.png", -1);
 25 
 26     // 聲明特征提取器與描述子提取器
 27     cv::Ptr<cv::FeatureDetector> _detector;
 28     cv::Ptr<cv::DescriptorExtractor> _descriptor;
 29 
 30     // 構建提取器,默認兩者都為sift
 31     // 構建sift, surf之前要初始化nonfree模塊
 32     cv::initModule_nonfree();
 33     _detector = cv::FeatureDetector::create( "GridSIFT" );
 34     _descriptor = cv::DescriptorExtractor::create( "SIFT" );
 35 
 36     vector< cv::KeyPoint > kp1, kp2; //關鍵點
 37     _detector->detect( rgb1, kp1 );  //提取關鍵點
 38     _detector->detect( rgb2, kp2 );
 39 
 40     cout<<"Key points of two images: "<<kp1.size()<<", "<<kp2.size()<<endl;
 41     
 42     // 可視化, 顯示關鍵點
 43     cv::Mat imgShow;
 44     cv::drawKeypoints( rgb1, kp1, imgShow, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS );
 45     cv::imshow( "keypoints", imgShow );
 46     cv::imwrite( "./data/keypoints.png", imgShow );
 47     cv::waitKey(0); //暫停等待一個按鍵
 48    
 49     // 計算描述子
 50     cv::Mat desp1, desp2;
 51     _descriptor->compute( rgb1, kp1, desp1 );
 52     _descriptor->compute( rgb2, kp2, desp2 );
 53 
 54     // 匹配描述子
 55     vector< cv::DMatch > matches; 
 56     cv::FlannBasedMatcher matcher;
 57     matcher.match( desp1, desp2, matches );
 58     cout<<"Find total "<<matches.size()<<" matches."<<endl;
 59 
 60     // 可視化:顯示匹配的特征
 61     cv::Mat imgMatches;
 62     cv::drawMatches( rgb1, kp1, rgb2, kp2, matches, imgMatches );
 63     cv::imshow( "matches", imgMatches );
 64     cv::imwrite( "./data/matches.png", imgMatches );
 65     cv::waitKey( 0 );
 66 
 67     // 篩選匹配,把距離太大的去掉
 68     // 這里使用的准則是去掉大於四倍最小距離的匹配
 69     vector< cv::DMatch > goodMatches;
 70     double minDis = 9999;
 71     for ( size_t i=0; i<matches.size(); i++ )
 72     {
 73         if ( matches[i].distance < minDis )
 74             minDis = matches[i].distance;
 75     }
 76 
 77     for ( size_t i=0; i<matches.size(); i++ )
 78     {
 79         if (matches[i].distance < 4*minDis)
 80             goodMatches.push_back( matches[i] );
 81     }
 82 
 83     // 顯示 good matches
 84     cout<<"good matches="<<goodMatches.size()<<endl;
 85     cv::drawMatches( rgb1, kp1, rgb2, kp2, goodMatches, imgMatches );
 86     cv::imshow( "good matches", imgMatches );
 87     cv::imwrite( "./data/good_matches.png", imgMatches );
 88     cv::waitKey(0);
 89 
 90     // 計算圖像間的運動關系
 91     // 關鍵函數:cv::solvePnPRansac()
 92     // 為調用此函數准備必要的參數
 93     
 94     // 第一個幀的三維點
 95     vector<cv::Point3f> pts_obj;
 96     // 第二個幀的圖像點
 97     vector< cv::Point2f > pts_img;
 98 
 99     // 相機內參
100     CAMERA_INTRINSIC_PARAMETERS C;
101     C.cx = 325.5;
102     C.cy = 253.5;
103     C.fx = 518.0;
104     C.fy = 519.0;
105     C.scale = 1000.0;
106 
107     for (size_t i=0; i<goodMatches.size(); i++)
108     {
109         // query 是第一個, train 是第二個
110         cv::Point2f p = kp1[goodMatches[i].queryIdx].pt;
111         // 獲取d是要小心!x是向右的,y是向下的,所以y才是行,x是列!
112         ushort d = depth1.ptr<ushort>( int(p.y) )[ int(p.x) ];
113         if (d == 0)
114             continue;
115         pts_img.push_back( cv::Point2f( kp2[goodMatches[i].trainIdx].pt ) );
116 
117         // 將(u,v,d)轉成(x,y,z)
118         cv::Point3f pt ( p.x, p.y, d );
119         cv::Point3f pd = point2dTo3d( pt, C );
120         pts_obj.push_back( pd );
121     }
122 
123     double camera_matrix_data[3][3] = {
124         {C.fx, 0, C.cx},
125         {0, C.fy, C.cy},
126         {0, 0, 1}
127     };
128 
129     // 構建相機矩陣
130     cv::Mat cameraMatrix( 3, 3, CV_64F, camera_matrix_data );
131     cv::Mat rvec, tvec, inliers;
132     // 求解pnp
133     cv::solvePnPRansac( pts_obj, pts_img, cameraMatrix, cv::Mat(), rvec, tvec, false, 100, 1.0, 100, inliers );
134 
135     cout<<"inliers: "<<inliers.rows<<endl;
136     cout<<"R="<<rvec<<endl;
137     cout<<"t="<<tvec<<endl;
138 
139     // 畫出inliers匹配 
140     vector< cv::DMatch > matchesShow;
141     for (size_t i=0; i<inliers.rows; i++)
142     {
143         matchesShow.push_back( goodMatches[inliers.ptr<int>(i)[0]] );    
144     }
145     cv::drawMatches( rgb1, kp1, rgb2, kp2, matchesShow, imgMatches );
146     cv::imshow( "inlier matches", imgMatches );
147     cv::imwrite( "./data/inliers.png", imgMatches );
148     cv::waitKey( 0 );
149 
150     return 0;
151 }
detectFeatures.cpp

   代碼的解釋:


   第一部分: 18行至52行,特征的檢測與描述子的計算。

  要在一個圖像里提取特征,第一步是計算“關鍵點”,然后,針對這些關鍵點周圍的像素,計算其“描述子”。在OpenCV中,分別由cv::FeatureDetector和cv::DescriptorExtractor來計算。

1 cv::Ptr<cv::FeatureDetector> _detector = cv::FeatureDetector::create( "SIFT" );
2 cv::Ptr<cv::DescriptorExtractor> _descriptor = cv:: DescriptorExtractor::create( "SIFT" );

  然后,使用 _detector->detect()函數提取關鍵點。值得一提的是,_detector和_descriptor的類型可以由字符串指定。如果你想構建FAST, SURF等特征,只需改后面的字符串即可。

  關鍵點是一種cv::KeyPoint的類型。你可以看它的API: http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html?highlight=keypoint#KeyPoint 由於比較長我這里就不貼了。可以看到,KeyPoint結構中帶有 Point2f pt 這個成員變量,指這個關鍵點的像素坐標。此外,有的關鍵點還有半徑、角度等參數,畫在圖里就會像一個個的圓一樣。

 

  

 

 

 

 

 

 

 

 

 

 

有了一組KeyPoint之后,就可以調用:

1 _descriptor->compute( image, keypoint, descriptor )

  在 keypoint 上計算描述子。描述子是一個cv::Mat的矩陣結構,它的每一行代表一個對應於Keypoint的特征向量。當兩個keypoint的描述子越相似,說明這兩個關鍵點也就越相似。我們正是通過這種相似性來檢測圖像之間的運動的。


 

  第二部分:特征匹配(53行至88行)

  接下來,我們對上述的描述子進行匹配。在OpenCV中,你需要選擇一個匹配算法,例如粗暴式(bruteforce),近似最近鄰(Fast Library for Approximate Nearest Neighbour, FLANN)等等。這里我們構建一個FLANN的匹配算法:

1 vector< cv::DMatch > matches;
2 cv::FlannBasedMatcher matcher;
3 matcher.match( desp1, desp2, matches );

  匹配完成后,算法會返回一些 DMatch 結構。該結構含有以下幾個成員:

  1. queryIdx 源特征描述子的索引(也就是第一張圖像)。
  2. trainIdx 目標特征描述子的索引(第二個圖像)
  3. distance 匹配距離,越大表示匹配越差。

  有了匹配后,可以用drawMatch函數畫出匹配的結果:

 

 

 

 

 

 

 

 

 

  小蘿卜:這真是“亂花漸欲迷人眼,淺草才能沒馬蹄”啊!

  師兄:你不是機器人么,怎么開始變得文藝起來了?

  不管如何說,僅靠描述子的匹配似乎是太多了些,把許多不相似的東西也匹配起來了。(由於這兩個圖像只有水平旋轉,所以水平的匹配線才是對的,其他的都是誤匹配)。因此,需要篩選一下這些匹配,例如,把distance太大的給去掉(源文件69到88行)。

  篩選的准則是:去掉大於最小距離四倍的匹配。

  小蘿卜:為什么是四倍呢?

  師兄:這只是個經驗數值啦,就像你平時都買一斤半的棗糕呀,為什么不買兩斤呢?

  小蘿卜:我喜歡吃棗糕!等這節講完我們去吃棗糕吧!

  師兄:呃……總、總之,選出來的goodmatch大概是這樣的:

 

 

 

 

 

 

 

 

 

 

 

  篩選之后,匹配就少了許多了,圖像看起來也比較干凈。


  第三部分 求解PnP

  求解PnP的核心是調用OpenCV里的SolvePnPRansac函數。該函數的接口如下(來自OpenCV在線API):

C++:  void  solvePnPRansac (InputArray  objectPoints, InputArray  imagePoints, InputArray  cameraMatrix, InputArray  distCoeffs, OutputArray  rvec, OutputArray  tvec, bool  useExtrinsicGuess=false, int  iterationsCount=100, float  reprojectionError=8.0, int  minInliersCount=100, OutputArray  inliers=noArray(), int  flags=ITERATIVE  )
Python:   cv2. solvePnPRansac (objectPoints, imagePoints, cameraMatrix, distCoeffs [, rvec[, tvec[, useExtrinsicGuess[, iterationsCount[, reprojectionError[, minInliersCount[, inliers[, flags]]]]]]]]) → rvec, tvec, inliers
Parameters:
  • objectPoints – Array of object points in the object coordinate space, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel, where N is the number of points.  vector<Point3f> can be also passed here.
  • imagePoints – Array of corresponding image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, where N is the number of points.  vector<Point2f> can be also passed here.
  • cameraMatrix – Input camera matrix  A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1} .
  • distCoeffs – Input vector of distortion coefficients  (k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]]) of 4, 5, or 8 elements. If the vector is NULL/empty, the zero distortion coefficients are assumed.
  • rvec – Output rotation vector (see  Rodrigues() ) that, together with  tvec , brings points from the model coordinate system to the camera coordinate system.
  • tvec – Output translation vector.
  • useExtrinsicGuess – If true (1), the function uses the provided  rvec and  tvec values as initial approximations of the rotation and translation vectors, respectively, and further optimizes them.
  • iterationsCount – Number of iterations.
  • reprojectionError – Inlier threshold value used by the RANSAC procedure. The parameter value is the maximum allowed distance between the observed and computed point projections to consider it an inlier.
  • minInliersCount – Number of inliers. If the algorithm at some stage finds more inliers than minInliersCount , it finishes.
  • inliers – Output vector that contains indices of inliers in objectPoints and imagePoints .
  • flags – Method for solving a PnP problem (see  solvePnP() ).

  可以看到,這個函數需要輸入一組匹配好的三維點: objectPoints 和一組二維圖像點: imagePoints. 返回的結果是旋轉向量 rvec 和平移向量tvec。其他的都是算法中的參數。因此,我們需要想辦法構建這兩組輸入點,它們實際上就是從goodmatches里抽取來的。

  由於我們已經提取了KeyPoint,知道了它們的像素坐標。那么,利用上一節提供的庫函數,就可以直接轉到三維點啦。代碼如下:(因為很重要就又貼了一遍)

 1 // 計算圖像間的運動關系
 2     // 關鍵函數:cv::solvePnPRansac()
 3     // 為調用此函數准備必要的參數
 4     
 5     // 第一個幀的三維點
 6     vector<cv::Point3f> pts_obj;
 7     // 第二個幀的圖像點
 8     vector< cv::Point2f > pts_img;
 9 
10     // 相機內參
11     CAMERA_INTRINSIC_PARAMETERS C;
12     C.cx = 325.5;
13     C.cy = 253.5;
14     C.fx = 518.0;
15     C.fy = 519.0;
16     C.scale = 1000.0;
17 
18     for (size_t i=0; i<goodMatches.size(); i++)
19     {
20         // query 是第一個, train 是第二個
21         cv::Point2f p = kp1[goodMatches[i].queryIdx].pt;
22         // 獲取d是要小心!x是向右的,y是向下的,所以y才是行,x是列!
23         ushort d = depth1.ptr<ushort>( int(p.y) )[ int(p.x) ];
24         if (d == 0)
25             continue;
26         pts_img.push_back( cv::Point2f( kp2[goodMatches[i].trainIdx].pt ) );
27 
28         // 將(u,v,d)轉成(x,y,z)
29         cv::Point3f pt ( p.x, p.y, d );
30         cv::Point3f pd = point2dTo3d( pt, C );
31         pts_obj.push_back( pd );
32     }
33 
34     double camera_matrix_data[3][3] = {
35         {C.fx, 0, C.cx},
36         {0, C.fy, C.cy},
37         {0, 0, 1}
38     };
39 
40     // 構建相機矩陣
41     cv::Mat cameraMatrix( 3, 3, CV_64F, camera_matrix_data );
42     cv::Mat rvec, tvec, inliers;
43     // 求解pnp
44     cv::solvePnPRansac( pts_obj, pts_img, cameraMatrix, cv::Mat(), rvec, tvec, false, 100, 1.0, 100, inliers );

  求解完成后,rvec和tvec就含有了位移和旋轉的信息,至此,我們已經成功地計算出兩個圖像的運動啦!

  

 

 

 

 

 

 

 

 

 

 

 

 

 

  小蘿卜:對了,那個Ransac和inlier是什么呢?

  師兄:盡管經過了篩選,我們提供的匹配里還是存在誤匹配的情況。根據誤匹配計算運動是不靠譜的。這時該怎么辦呢?OpenCV會利用一種“隨機采樣一致性”(Random Sample Consensus)的思路(見https://en.wikipedia.org/wiki/RANSAC)。意思即為,在現有的匹配中隨機取一部分,估計其運動。因為正確的匹配結果肯定是相似的,而誤匹配的結果肯定滿天亂飛。只要把收斂的結果取出來即可。

  小蘿卜:這個就叫做“幸福的家庭都是相似的,不幸的家庭各有各的不幸”吧。

  師兄:你這樣理解也可以。ransac適用於數據噪聲比較大的場合。這對圖像的inlier大概是這樣的:

  小蘿卜:似乎仍有一些誤差的樣子呢。

  師兄:是的,不過可以通過調節我們之前的篩選過程以及之后的ransac參數,得到更好的結果。


本節回顧

  本節中,我們介紹了如何提取、匹配圖像的特征,並通過這些匹配,使用ransac方法估計圖像的運動。下一節,我們將介紹如何使用剛得到的平移、旋轉向量來拼接點雲。至此,我們就完成了一個只有兩幀的迷你SLAM程序。

  課后作業:

  1. 請把計算圖像運動信息封裝成一個函數,放進slamBase庫中。
  2. 由於我們的程序變復雜了,出現了一些內部的參數,如特征點類型,篩選准則,ransac參數等等。如果我們把這些參數值定義在源代碼里,那么每修改一次,就要重新編譯一遍程序。這非常麻煩。所以,我們希望把參數定義在外部文件中,在程序剛開始時讀取此文件。這樣一來,只要更改此文件即可完成參數的調節,不必重新編譯程序了。因此,請你完成一個讀取參數的類,放進slamBase中。

  小蘿卜:這一講比前兩節難好多啊,師兄。

  師兄:是啊,然而我也不得不講這些東西,不然講不清楚呢。

  小蘿卜:嗯,那我回去好好復習啦。大家也要加油!

未完待續

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM