读入批量图像

读入两帧图像直接使用imread即可,但是读入文件夹内的图像文件夹有点复杂。

在视觉SLAM十四讲第八章使用LK光流法时,第一帧图像提取FAST特征点,之后的帧使用LK跟踪特征点,需要批量导入图像。

这里提供的方式如下:

string path_to_dataset="../TUM";
string associate_file=path_to_dataset+"/associate.txt";
ifstream fin(associate_file);
string rgb_file, depth_file,time_rgb,time_depth;

for (int index=0;index<100;index++)
{
 fin>>rgb_file>>depth_file>>time_rgb>>time_depth;
 color=cv::imread(path_to_dataset+"/"+rgb_file);
 depth=cv::imread(path_to_dataset+"/"+depth_file,-1);
}

1、其中,associate.txt对depth和rgb图像的采集时间进行配对,时间上对齐。

运行:python associate.py rgb.txt depth.txt > associate.txt

2、imread(flag); 彩色图像为8位3通道,深度图为16位单通道图像。

flags = 1:imread按三通道方式读入图像,即彩色图像

flags = 0:imread按单通道的方式读入图像,即灰白图像

flags = -1:imread按解码得到的方式读入图像

3、groundtruth.txt为标准轨迹,外部运动捕捉系统采集到的相机位姿。(time,tx,ty,tz,qx,qy,qz,qw)


在实现简单的视觉里程计里,需要读入KITTI的图像。

要求:图像为顺序排列1、2、3....

char filename[100];
for(int index=2;index<100;index++)
{
 sprintf(filename,"/home/avisingh/Datasets/KITTI_VO/00/image_2/%06d.png",index);
 Mat currImage_c=imread(filename);
 cvtColor(currImage_c,currImage,COLOR_BGR2GRAY);
}

1、sprintf()把格式化的数据写入某个字符串中

2、照片格式为000011.png,所以这里用sprintf(filename,"../%06d.png",index)形式,字长6位,不够的前面补零

     相同效果的是:

     stringstream ss;

     ss << "../"  << setw(6) << setfill('0') << index<< ".png";

    Mat img(imread(ss.str(),0));

猜你喜欢

转载自blog.csdn.net/try_again_later/article/details/83374412