以图像为基础的三维重建过程SFM基本如下图所示:
以SfM-Toy-Library代码为例,如下:
ErrorCode SfM::runSfM()
{
if (mImages.size() <= 0) {
cerr << "No images to work on." << endl;
return ErrorCode::ERROR;
}
//initialize intrinsics
mIntrinsics.K = (Mat_<float>(3,3) << 2500, 0, mImages[0].cols / 2,
0, 2500, mImages[0].rows / 2,
0, 0, 1);
mIntrinsics.Kinv = mIntrinsics.K.inv();
mIntrinsics.distortion = Mat_<float>::zeros(1, 4);
mCameraPoses.resize(mImages.size());
//First - extract features from all images
extractFeatures();
//Create a matching matrix between all images' features
createFeatureMatchMatrix();
//Find the best two views for an initial triangulation on the 3D map
findBaselineTriangulation();
//Lastly - add more camera views to the map
addMoreViewsToReconstruction();
if (mConsoleDebugLevel <= LOG_INFO) {
cout << "----------------------- Done -----------------------" << endl;
}
return OKAY;
}
Intrinsics mIntrinsics; //有3个矩阵,分别是内参 内参的转置 畸变
Intrinsics的定义为
struct Intrinsics {
cv::Mat K; //内参
cv::Mat Kinv; //内参的转置
cv::Mat distortion; //畸变
};
流程解析:
1、初始化相机参数矩阵,包括内参矩阵和相机变形参数;
2、提取所有图像的特征点;
3、为所有的图像特征点创建匹配矩阵;
4、在三维地图上寻找初始三角化的最佳两个视图;
5、加入更多图像到地图中来重建三维。
后续将会逐个解析每个过程。