制作自己的ORBSLAM2数据集,并实现三维重建

2 ORBSLAM2 测试自己拍摄的数据集
        使用手机、摄像机等设备拍摄视频,对应我们只能使用单目 (Monocular)。


2.1对相机标定
        首先我们要对相机进行标定,使用 MATLAB 里面的标定工具包。标定好之
后创建一个单目模式下的 yaml,复制 TUM1.yaml 修改标定参数即可。


注意: 因为现在手机比较智能,要注意手机录像清晰度是可调节的,对应标
定出的数不同。一定要保证标定时的清晰度一定要和录像时的一样。标定时最
好不要选择拍照的方式,因为拍照和录像手机清晰度基本上也是不一样的。可
以用录像的方式来获取标定的数据,再用下面的代码隔几十帧取一帧,来实现
标定。

2.2制作自己的数据集
        录制一段视频,将视频转换成 ORBSLAM2 数据集的格式。代码如下可以指
定保存的图像的格式和隔多少帧保存一张。

/* Author(s):
 *        哇哈哈(WHH)
 */

#include <iostream>
#include "opencv2/opencv.hpp"
#include <string>
#include <fstream> 
using namespace cv;

void TransV2I();
 
// 描述:将视频帧转成图片输出
int main()
{
	TransV2I();
	return 0;
}

void TransV2I()
{
	std::cout<<"Enter the video for trans: ";
	std::string vido;
	std::cin>>vido;

// load video
	VideoCapture cap(vido);
//get info of video
	long TotalFrameNumber = cap.get(CV_CAP_PROP_FRAME_COUNT);
	int FrameRate = cap.get(CV_CAP_PROP_FPS);
	std::cout<<"Frame rate :"<<FrameRate<<std::endl;
	std::cout<< "Total frames: " << TotalFrameNumber <<std::endl;
 
//get rate for capture
	Mat frame;
	bool toStop = true;
	long CurrentFrame = 100000;
	std::cout<<"Save one after how many frames: ";
	int Rate;
	std::cin>>Rate;

//get format for images type
	std::string fomat;
	std::cout<<"Enter image format: ";
	std::cin>>fomat;
//path to write
	std::string folderpath = "DataforORBSLAM2/rgb/";
	std::string command;
	command = "mkdir -p "+ folderpath;
	system(command.c_str());

//write txt file
	std::ofstream OutFile;
	std::string FilePath = "dataforslam/rgb.txt";
    OutFile.open(FilePath);    //打开文件
//write info of images
	OutFile<<"# color images"<<std::endl;
	OutFile<<"#total "<<TotalFrameNumber<<" images"<<std::endl;


	while (toStop){
		cap.read(frame);

		if(CurrentFrame%Rate == 0){
			std::stringstream str1, str2;
			str1<<"6269."<<CurrentFrame<<"."<<fomat;
			str2<<"6269."<<CurrentFrame;
			imwrite(folderpath+str1.str(), frame);
			OutFile <<str2.str()<<"   rgb/"+str1.str()<< std::endl;
		}
		
		if((CurrentFrame-100000)>TotalFrameNumber-1){
			toStop = false;
		}
		CurrentFrame++;
		
}
	OutFile.close();
	std::cout<<"Done!\n";
}

3 OpenMVS 使用 ORBSLAM2 的位姿进行三维重建
        参考https://blog.csdn.net/qq34325730/article/details/118360533
        这里需要对 ORBSLAM2 和 OpenMVS 更改, 下载更改后的模块替换就行。
        记得把 DensifyPointCloud.cpp 里面的一个屏蔽符去掉如下图:

4效果

       

 拍的数据集不是很行,效果一般。对建筑表面进行重建效果会比较好。

  • 8
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值