資源簡介
基于SfM實現(xiàn)視覺稀疏三維點云重建,完整的工程文件,內(nèi)含所需圖片,可直接運行。環(huán)境:Win10+VS2015+OpenCV3.4+PLC1.8。
代碼片段和文件信息
/*
使用兩張圖片進行三維重建
流程:
1.求相機內(nèi)外參數(shù)
a):2D-2D:可通過提取特征點、計算基本(或本質(zhì))矩陣、分解基本(或本質(zhì))矩陣得到R、t(K已知)
b):也可通過相機標(biāo)定的方式,直接獲得R、t、K
2.三維重建
a):可通過三角法進行重建
b):也可通過RGB-D相機獲得深度z,再求得xy進行重建
注意事項:
1.任意兩張圖片之間的K略有不同,不影響重建效果但要盡量選擇相鄰的圖片,否則匹配的特征點較少
2.可由本質(zhì)矩陣E通過SVD分解可得到4個解,只有選擇正確的R、T才能完成重建否則歸一化的坐標(biāo)之后無法正常顯示;
使用recoverPose則能直接得到正確的R、t
3.在使用triangulatePoints三維重建時,有兩種歸一化方式
4.由于E本身具有尺度等價性,它分解得到的t具有一個尺度,即在分解過程中,對t乘以任意非零常數(shù),分解都是成立的。因此常把t進行歸一化,讓其長度等于1。
對t長度的歸一化,導(dǎo)致重建的尺度不確定性。因此如何1:1三維重建?
*/
#ifndef?_CRT_SECURE_NO_WARNINGS
#define?_CRT_SECURE_NO_WARNINGS
#endif
#include?
#include?
#include??
#include?
#include?
#include?
#include?
using?namespace?std;
using?namespace?cv;
using?namespace?pcl;
using?namespace?cv::xfeatures2d;
//?ratio?&?symmetry?test
void?ratioTest(vector>?&matches?vector?&goodMatches);
void?symmetryTest(const?vector&?matches1?const?vector&?matches2?vector&?symMatches);
//?從匹配對中提取特征點
void?fillPoints(vector?goodMatches?vector?keypoints1?vector?keypoints2?vector&?points1?vector&?points2);
//?三維重建
void?reconstruct(Mat&?K?Mat&?fundamentalMatrix?vector&?points1?vector&?points2?vector&?points3D);
//?獲取關(guān)鍵點RGB
void?getPointColor(vector?points1?Mat?baseImageLeft?vector&?colors);
int?main(int?argc?char*?argv[])
{
//?PCL可視化
PointCloud::Ptr?cloud(new?PointCloud);
boost::shared_ptr?viewer(new?visualization::PCLVisualizer(“3D?viewer“));?//?實例化PCLVisualizer對象,窗口命名為3D?viewer
Mat?K; //?內(nèi)參數(shù)矩陣
Matx34d?P?P1;??//?兩圖片的相機坐標(biāo)
//?1.讀入圖片
Mat?baseImageLeft?=?imread(“.\\images\\003.png“?-1);
Mat?baseImageRight?=?imread(“.\\images\\004.png“?-1);
if?(baseImageLeft.empty()?||?baseImageRight.empty())
{
cout?<“ERROR!?NO?IMAGE?LOADED!“?< return?-1;
}
cout?<“processing...“?< //?2.SIFT提取特征點
Ptr?detector?=?xfeatures2d::SIFT::create(0?3?0.04?10);
vector?keypoints_1?keypoints_2;?//?關(guān)鍵點
Mat?descriptors_1?descriptors_2; ???//?描述符
detector->detectAndCompute(baseImageLeft?noArray()?keypoints_1?descriptors_1);
detector->detectAndCompute(baseImageRight?noArray()?keypoints_2?descriptors_2);
//?3.Flann匹配特征點
vector>?matches1?matches2;
vector?goodMatches1?goodMatches2?goodMatches?outMatches;
FlannbasedMatcher?matcher;
//?1個descriptors_1[i]對應(yīng)1個matches[i],1個matches[i]對應(yīng)2個DMatch(2?nearest)
matcher.knnMatch(descriptors_1?descriptors_2?matches1?2);//?find?2?nearest?neighbours?match.size()?=?query.rowsize()
matcher.knnMatch(descriptors_2?descriptors_1?matches2?2);
//?4.使用Ratio?Test和Symmetry?Test消除誤匹配點,提高重建精度
ratioTest(
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-03-08?22:59??.vs\
?????目錄???????????0??2019-03-08?22:59??.vs\SfM\
?????目錄???????????0??2019-03-08?22:59??.vs\SfM\v14\
?????文件???????60416??2019-03-08?21:30??.vs\SfM\v14\.suo
?????文件????????1291??2019-03-03?14:51??SfM.sln
?????文件??????????36??2019-03-08?21:28??SfM.VC.VC.opendb
?????目錄???????????0??2019-03-08?23:00??SfM\
?????文件???????10310??2019-03-08?22:14??SfM\3DReconstruction_Signle2Images.cpp
?????目錄???????????0??2019-03-08?22:59??SfM\images\
?????文件?????6047052??2018-04-22?08:33??SfM\images\000.png
?????文件?????6273917??2018-04-22?08:33??SfM\images\001.png
?????文件?????6382709??2018-04-22?08:33??SfM\images\002.png
?????文件?????6363282??2018-04-22?08:33??SfM\images\003.png
?????文件?????6340215??2018-04-22?08:33??SfM\images\004.png
?????文件?????6365922??2018-04-22?08:33??SfM\images\005.png
?????文件?????6262661??2018-04-22?08:33??SfM\images\006.png
?????文件?????6347685??2018-04-22?08:33??SfM\images\007.png
?????文件?????6481233??2018-04-22?08:33??SfM\images\008.png
?????文件?????6540372??2018-04-22?08:33??SfM\images\009.png
?????文件????????7461??2019-03-08?22:14??SfM\SfM.vcxproj
?????文件?????????971??2019-03-08?22:14??SfM\SfM.vcxproj.filters
- 上一篇:小米解鎖,BL,刷機,軟件ROM
- 下一篇:黑客防線2013年第1到12期全集合
評論
共有 條評論