資源簡介
使用BA優化對SfM三維重建的結果進行非線性優化,環境:VS2015+OpenCV3.4+PCL1.8+Ceres Solver,包含兩張圖、多張圖BA優化代碼及images文件。
代碼片段和文件信息
#ifndef?_CRT_SECURE_NO_WARNINGS
#define?_CRT_SECURE_NO_WARNINGS
#endif
#define?GLOG_NO_ABBREVIATED_SEVERITIES
#include?
#include?
#include?
#include??
#include?
#include?
#include?
#include?
#include?
#include?
#include?“gflags/gflags.h“
#include?“glog/logging.h“
using?namespace?std;
using?namespace?cv;
using?namespace?pcl;
using?namespace?cv::xfeatures2d;
//?代價函數
struct?ReprojectCost
{
cv::Point2d?observation;
ReprojectCost(cv::Point2d&?observation)?:?observation(observation)
{
}
//?參數:內參、外參、三維點、反向投影誤差
template?
bool?operator()(const?T*?const?intrinsic?const?T*?const?extrinsic?const?T*?const?pos3d?T*?residuals)?const
{
const?T*?r?=?extrinsic;
const?T*?t?=?&extrinsic[3];
T?pos_proj[3];
ceres::AngleAxisRotatePoint(r?pos3d?pos_proj);
//?Apply?the?camera?translation
pos_proj[0]?+=?t[0];
pos_proj[1]?+=?t[1];
pos_proj[2]?+=?t[2];
const?T?x?=?pos_proj[0]?/?pos_proj[2];
const?T?y?=?pos_proj[1]?/?pos_proj[2];
const?T?fx?=?intrinsic[0];
const?T?fy?=?intrinsic[1];
const?T?cx?=?intrinsic[2];
const?T?cy?=?intrinsic[3];
//?Apply?intrinsic
const?T?u?=?fx?*?x?+?cx;
const?T?v?=?fy?*?y?+?cy;
residuals[0]?=?u?-?T(observation.x);
residuals[1]?=?v?-?T(observation.y);
return?true;
}
};
//?提取所有圖像的特征點?及?特征點處的RGB
void?extract_features(vector&?image_names?vector>&?keypoints_for_all?vector&?descriptor_for_all?vector>&?colors_for_all);
//?ratio?&?symmetry?test
void?ratioTest(vector>?&matches?vector?&goodMatches);
void?symmetryTest(const?vector&?matches1?const?vector&?matches2?vector&?symMatches);
//?匹配所有特征點
void?match_features(vector&?descriptor_for_all?vector>&?matches_for_all);
//?由匹配對提取特征點對
void?get_matched_points(vector?keypoints1vector?keypoints2vector?goodMatchesvector&?points1vector&?points2);
//?獲取匹配點的RGB
void?get_matched_colors(vector&?color1?vector&?color2?vector?matches?vector&?out_c1?vector&?out_c2);
//?剔除p1中mask值為0的元素
void?maskout_points(vector&?p1?Mat&?mask);
void?maskout_colors(vector&?p1?Mat&?mask);
//?重建前2張圖片
void?reconstruct_first2imgs(Mat?K?vector>&?key_points_for_all?vector>&?colors_for_all?vector>&?matches_for_all?vector&?structure?vector>&?correspond_struct_idx?vector&?colors?vector&?rotations?vector&?translations);
//?三維重建
//?前兩張圖片重建
void?reconstruct(Mat&?K?vector&?points1?vector&?points2?Mat&?R?Mat&?t?Mat&?mask?vector&?poi
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????23063??2019-03-15?13:43??BA_MultiView_Rec.cpp
?????文件???????13219??2019-03-15?13:42??BA_Signle2Images.cpp
?????目錄???????????0??2019-03-15?13:48??images\
?????文件?????6047052??2018-04-22?08:33??images\000.png
?????文件?????6273917??2018-04-22?08:33??images\001.png
?????文件?????6382709??2018-04-22?08:33??images\002.png
?????文件?????6363282??2018-04-22?08:33??images\003.png
?????文件?????6340215??2018-04-22?08:33??images\004.png
?????文件?????6365922??2018-04-22?08:33??images\005.png
?????文件?????6262661??2018-04-22?08:33??images\006.png
?????文件?????6347685??2018-04-22?08:33??images\007.png
?????文件?????6481233??2018-04-22?08:33??images\008.png
?????文件?????6540372??2018-04-22?08:33??images\009.png
- 上一篇:無線AP網絡測試工具
- 下一篇:erlang_win_64位安裝包
評論
共有 條評論