主要参考大佬博客:
- https://zhuanlan.zhihu.com/p/86718461
- https://blog.csdn.net/u010451780/article/details/108356447
1) 重要参数
- zParametersBundlingDefault.txt
- s_numLocalNonLinIterations = 2; //局部非线性优化迭代次数
- s_numLocalLinIterations = 100; //局部线性优化迭代次数,重要
- s_numGlobalNonLinIterations = 3; //全局非线性优化迭代次数
- s_numGlobalLinIterations = 150; //全局线性优化迭代次数
- s_downsampledWidth = 80; //用于Correspondence Filtering中的dense verification中,如果设置的不恰当,会导致在跟踪过程中,容易跟踪失败,导致重建的稠密模型缺失
- s_downsampledHeight = 60;
- s_sensorIdx = 8; //输入数据模式,1~7代表不同的深度相机实时扫描输入,8代表离线.sens文件
- s_RenderMode = 1; //程序运行时窗口实时展示的模式,Tab键显示菜单,输入不同数字或字母显示不同模式;
- zParametersDefault.txt
- s_maxNumKeysPerImage = 1024; //每一帧图像上检测的最多的sift特征点的个数。
- s_integrationWidth = 320; //使用的帧size,需根据自己数据的分辨率修改
- s_integrationHeight = 240;
- s_maxNumImages = 1200; //最大帧数
- s_submapSize = 10; //每个localBundle最大帧数
- s_maxNumKeysPerImage = 1024; //每帧最大特征点数
2) 程序梳理
Fredver.cpp是主程序入口,bundlingThreadFunc开启多线程分层优化特征提取匹配过滤实现位姿估计,startDepthSensing从传感器读取数据并重建。
-
main() FriedLiver.cpp:程序入口
- g_RGBDSensor = getRGBDSensor();//根据你设置的s_sensorIdx来判断你输入的数据的形式,是深度相机还是.sens文件。
- g_RGBDSensor->createFirstConnected(); //这个函数主要是读取输入的.sens文件中的数据,彩色图,深度图,pose,还有info.txt
- g_imageManager = new CUDAImageManger();
- std::thread bundlingThread(bundlingThreadFunc); //开启多线程,进行跟踪和优化
- 如果已经处理的最后一帧是localBundle的第一帧,则等待上一次solve优化完
- 如果已经处理的最后一帧是localBundle的最后一帧,则开始新的solve优化
- std::thread(bundlingOptimizationThreadFunc); //11帧为一个chunk
- bundlingOptimization();
- g_bundler->process();
- optimizeLocal()
- processGlobal()
- optimizeGlobal()
- g_bundler->process();
- 等待新的输入数据,处理输入processInput,通知DepthSensing
- startDepthSensing(g_bundler, getRGBDSensor(), g_imageManager); //调用DX进行渲染,从传感器中读取数据,重建
-
startDepthSensing() DepthSensing.cpp
- DXUTSetCallbackD3D11FrameRender(OnD3D11FrameRender)
- 等待上一次bundlingThread完成,读取数据,然后通知bundlingThread
- bool bGotDepth = g_CudaImageManager->process(); // 读取输入
- reintegrate(); //Fix old frames,更新模型,包括:deintegrate和integrate
- 等待bundling完成:sift extraction, sift matching, and key point filtering
- integrate(depthCameraData, transformation); //Reconstruction of current frame,获取当前帧,fusion进TSDF中
- VisualizeFrame; //Render with view of current frame, RayCast
- StopScanningAndExit(); //这个函数中实现将计算的位姿保存到.sens中的pose数据,并且生成.ply模型
- DXUTSetCallbackD3D11FrameRender(OnD3D11FrameRender)
-
CUDAImageManager
- init
-
-
- m_bHasBundlingFrameRdy=false
- m_currFrame = 0
-
process:输入数据预处理,m_currFrame++
-
-
ColorMap:
-
- 重采样:根据s_integrationWidth
-
DepthMap:
-
- erode:腐蚀2次
- smooth:双边滤波
- 重采样:根据s_integrationWidth
-
加入m_data
-
-
-
OnlineBundler
-
OnlineBundler()// init input data & sift camera constant params & trajectories
- m_bHasProcessedInputFrame=false
- m_bExitBundlingThread=false
- m_lastFrameProcessed = -1
-
getCurrentFrame()// BundlerInputData获取depthMap和colorMap
-
- Color to Intensity:(0.299fc.x + 0.587fc.y + 0.114f*c.z) / 255.0f
- colorFilter:双边滤波bilateral filter
-
processInput()
-
- 获取depth/color data
- localBundle检测SIFT特征点,缓存数据
- m_local->detectFeatures() //Bundle中定义的函数
- m_local->storeCachedFrame()//Bundle中定义的函数
- 如果是localBundle最后一帧,copy localBundle data to optBundle
- m_optLocal->copyFrame(m_local, curLocalFrame)
- 如果不是localBundle第一帧,localBundle进行SIFT特征点匹配和过滤,计算当前帧的transform
- m_local->matchAndFilter()//Bundle中定义的函数
- 如果是localBundle最后一帧,准备local solve,更新BundlerState,交换localBundle和optBundle
-
process()//BundleFusion Optimization
- optimizeLocal() //局部优化
- processGlobal()
- fuseToGlobal //把localBundle关键帧加入globalBundle中
- matchAndFilter
- optimizeGlobal() //全局优化
-
-
Bundler
- detectFeatures() //检测图像sift特征点
- storeCachedFrame() //缓存数据
- matchAndFilter() //匹配和过滤当前帧和之前所有帧的sift特征点,计算3D点。
- optimize() //稀疏点优化
- CUDA solve
-
CUDASolverBundling 求解器
- BuildDenseSystem
3) 效率分析
亲测bundlefusion实时处理速度可达30fps。在zParametersDefault.txt中指定time文件输出目录s_printTimingsDirectory, 在zParametersBundlingDefault.txt中指定s_enablePerFrameTimings和s_enableGlobalTimings为true。程序结束运行后或者运行过程中按"T"键,会在指定文件夹下输出四个记时文件:
- excel_local.txt:
- SIFT Dection(9.0ms),SIFT Matching(1.5ms),corr Fliter(1.2ms),Misc(0.5ms),Solve(1.9ms),Re-Integrate(24.5ms),Misc(6.6ms);
- excel_global.txt:
- SIFT Dection(2.7ms),SIFT Matching(19.3ms),corr Fliter(1.4ms),Misc(0.5ms),Solve(133.7ms);
- excel_total.txt:每一帧的总耗时,平均约30ms;
- timingLogPerFrame.txt:每一帧各模块耗时及总耗时
- 等待bundling完成:sift extraction, sift matching, and key point filtering,通知depth,等待新的输入数据,处理输入processInput,通知DepthSensing
- SIFT Dection:计算一帧 SIFT 关键点和提取关键点描述子占用 9.0ms;
- SIFT Matching:匹配一次耗时大概 1.5ms;
- corr Fliter:帧间对应关系过滤大概1.2ms;
- Misc:0.5ms;
- Solve:local bundle最后一帧执行CUDA solve大概1.9ms;
- Process Input:处理输入,约2ms
- Re-Integrate:更新模型,约24ms
- Reconstruct:重建当前帧,约1.5ms
- Visualize:可视化,约2.5~3ms
- 等待bundling完成:sift extraction, sift matching, and key point filtering,通知depth,等待新的输入数据,处理输入processInput,通知DepthSensing